diff -X /home/cedric/work/enlightenment/exclude.cvs -Nrau libtimidity-0.1.0/src/stream.c libtimidity-0.1.0-patch/src/stream.c
--- libtimidity-0.1.0/src/stream.c	2004-11-21 23:02:53.000000000 +0100
+++ libtimidity-0.1.0-patch/src/stream.c	2009-02-10 18:37:13.000000000 +0100
@@ -2,8 +2,15 @@
 #  include <config.h>
 #endif
 
-#include "string.h"
+#include <sys/mman.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
 
+#include "string.h"
 #include "timidity.h"
 #include "timidity_internal.h"
 #include "common.h"
@@ -42,7 +49,9 @@
   sint8 *base;
   sint8 *current;
   sint8 *end;
-  int autofree;
+   int autofree;
+   int fd;
+   int size;
 } MemContext;
 
 size_t
@@ -66,10 +75,20 @@
 int
 mem_istream_close (void *ctx)
 {
-  if (((MemContext *) ctx)->autofree)
-    free (((MemContext *) ctx)->base);
-  free (ctx);
-  return 0;
+   MemContext *mem;
+
+   mem = (MemContext*) ctx;
+
+   if (mem->autofree)
+     free (mem->base);
+   if (mem->fd != -1)
+     {
+	munmap(mem->base, mem->size);
+	close(mem->fd);
+     }
+
+   free (ctx);
+   return 0;
 }
 
 MidIStream *
@@ -101,13 +120,35 @@
 MidIStream *
 mid_istream_open_file (const char *file)
 {
-  FILE *fp;
-
-  fp = fopen (file, "rb");
-  if (fp == NULL)
-    return NULL;
-
-  return mid_istream_open_fp (fp, 1);
+   struct stat buf;
+   MidIStream *stream;
+   MemContext *ctx;
+   void *map = MAP_FAILED;
+   int fd;
+
+   fd = open(file, O_RDONLY);
+   if (fd < 0) return NULL;
+
+   if (fstat(fd, &buf) != 0)
+     goto on_error;
+
+   map = mmap(NULL, buf.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
+   if (map == MAP_FAILED)
+     goto on_error;
+
+   stream = mid_istream_open_mem(map, buf.st_size, 0);
+   if (!stream) goto on_error;
+
+   ctx = (MemContext*) stream->ctx;
+   ctx->fd = fd;
+   ctx->size = buf.st_size;
+
+   return stream;
+
+ on_error:
+   if (map != MAP_FAILED) munmap(map, buf.st_size);
+   close(fd);
+   return NULL;
 }
 
 MidIStream *
@@ -130,6 +171,7 @@
   ctx->current = mem;
   ctx->end = ((sint8 *) mem) + size;
   ctx->autofree = autofree;
+  ctx->fd = -1;
 
   stream->ctx = ctx;
   stream->read = mem_istream_read;
