freetype-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Devel] fall-back for mmap


From: Masatake YAMATO
Subject: [Devel] fall-back for mmap
Date: Fri, 23 Jan 2004 05:04:33 +0900 (JST)

This patch improves a bit to access a font file on linux's hfs.
mmap does not work in case "fork=double" option is given to mount 
command like:

   # mount -t hfs -o fork=double /dev/cdrom /mnt/cdrom

So call ft_alloc and read if mmap is failed.

In hfs's TODO file included in linux kernel, it is described that
to implement mmap is one of the Fantasy features:

      Fantasy features:
      1.        Access Desktop file/database for comment and icon.
=>    2.        Implement mmap() for AppleDouble header files and CAP info 
files.
      3.        Implement AppleShare client support.

Regards,
Masatake YAMATO

2004-01-23  Masatake YAMATO  <address@hidden>

        * builds/unix/ftsystem.c (ft_close_stream_by_munmap): renamed from
        ft_close_stream.
        (ft_close_stream_by_free): New function.
        (FT_Stream_Open): If mmap is failed, use ft_alloc and read
        to load a font file. 

        This fall-back may be useful on Linux's hfs implementation. 
        mmap on the hfs does not work in case "fork=double" option is given 
        to mount command. 

        Quoted from linux-2.4/fs/hfs/TODO:

                Fantasy features:
                ...
                2.      Implement mmap() for AppleDouble header files
                        and CAP info files.
        

Index: builds/unix/ftsystem.c
===================================================================
RCS file: /cvsroot/freetype2/builds/unix/ftsystem.c,v
retrieving revision 1.24
diff -u -r1.24 ftsystem.c
--- ftsystem.c  2002/03/29 07:43:03     1.24
+++ ftsystem.c  2004/01/22 19:53:29
@@ -182,16 +182,16 @@
   /*************************************************************************/
   /*                                                                       */
   /* <Function>                                                            */
-  /*    ft_close_stream                                                    */
+  /*    ft_close_stream_by_munmap                                          */
   /*                                                                       */
   /* <Description>                                                         */
-  /*    The function to close a stream.                                    */
+  /*    The function to close a stream which is opened by mmap             */
   /*                                                                       */
   /* <Input>                                                               */
   /*    stream :: A pointer to the stream object.                          */
   /*                                                                       */
   FT_CALLBACK_DEF( void )
-  ft_close_stream( FT_Stream  stream )
+  ft_close_stream_by_munmap( FT_Stream  stream )
   {
     munmap( (MUNMAP_ARG_CAST)stream->descriptor.pointer, stream->size );
 
@@ -200,7 +200,27 @@
     stream->base               = 0;
   }
 
+  /*************************************************************************/
+  /*                                                                       */
+  /* <Function>                                                            */
+  /*    ft_close_stream_by_free                                            */
+  /*                                                                       */
+  /* <Description>                                                         */
+  /*    The function to close a stream which is created by ft_alloc.       */
+  /*                                                                       */
+  /* <Input>                                                               */
+  /*    stream :: A pointer to the stream object.                          */
+  /*                                                                       */
+  FT_CALLBACK_DEF( void )
+  ft_close_stream_by_free ( FT_Stream stream )
+  {
+    ft_free ( NULL, stream->descriptor.pointer );
 
+    stream->descriptor.pointer = NULL;
+    stream->size               = 0;
+    stream->base               = 0;
+  }
+
   /* documentation is in ftobjs.h */
 
   FT_EXPORT_DEF( FT_Error )
@@ -252,11 +272,28 @@
                                           file,
                                           0 );
 
-    if ( (long)stream->base == -1 )
+    if ( (long)stream->base != -1 )
+      stream->close = ft_close_stream_by_munmap;
+    else
     {
       FT_ERROR(( "FT_Stream_Open:" ));
       FT_ERROR(( " could not `mmap' file `%s'\n", filepathname ));
-      goto Fail_Map;
+      stream->base = ft_alloc ( NULL, stream->size );
+      if ( ! stream->base  )
+      {
+       FT_ERROR(( "FT_Stream_Open:" ));
+       FT_ERROR(( " could not `alloc' memory\n" ));
+       goto Fail_Map;
+      }
+
+      if ( stream->size != read ( file, stream->base, stream->size ) )
+      {
+       FT_ERROR(( "FT_Stream_Open:" ));
+       FT_ERROR(( " could not `read' file `%s'\n", filepathname ));
+       goto Fail_Read;
+      }
+
+      stream->close = ft_close_stream_by_free;
     }
 
     close( file );
@@ -264,7 +301,6 @@
     stream->descriptor.pointer = stream->base;
     stream->pathname.pointer   = (char*)filepathname;
 
-    stream->close = ft_close_stream;
     stream->read  = 0;
 
     FT_TRACE1(( "FT_Stream_Open:" ));
@@ -272,6 +308,9 @@
                 filepathname, stream->size ));
 
     return FT_Err_Ok;
+
+  Fail_Read:
+    ft_free ( NULL, stream->base );
 
   Fail_Map:
     close( file );



reply via email to

[Prev in Thread] Current Thread [Next in Thread]