imported brians code
[nestedvm.git] / upstream / patches / ft-nostdio.patch
1 --- src/base/ftsystem.c.origf   Mon Dec 29 05:45:54 2003
2 +++ src/base/ftsystem.c Mon Dec 29 05:46:08 2003
3 @@ -32,7 +32,8 @@
4  #include FT_ERRORS_H
5  #include FT_TYPES_H
6  
7 -#include <stdio.h>
8 +#include <fcntl.h>
9 +#include <unistd.h>
10  #include <stdlib.h>
11  
12  
13 @@ -151,7 +152,7 @@
14  
15    /* We use the macro STREAM_FILE for convenience to extract the       */
16    /* system-specific stream handle from a given FreeType stream object */
17 -#define STREAM_FILE( stream )  ( (FILE*)stream->descriptor.pointer )
18 +#define STREAM_FD( stream )  ( (int)stream->descriptor.value )
19  
20  
21    /*************************************************************************/
22 @@ -168,7 +169,7 @@
23    FT_CALLBACK_DEF( void )
24    ft_ansi_stream_close( FT_Stream  stream )
25    {
26 -    fclose( STREAM_FILE( stream ) );
27 +    close(STREAM_FD(stream));
28  
29      stream->descriptor.pointer = NULL;
30      stream->size               = 0;
31 @@ -202,14 +203,14 @@
32                       unsigned char*  buffer,
33                       unsigned long   count )
34    {
35 -    FILE*  file;
36 +    int fd;
37  
38  
39 -    file = STREAM_FILE( stream );
40 +    fd = STREAM_FD( stream );
41  
42 -    fseek( file, offset, SEEK_SET );
43 +    if(lseek( fd, offset, SEEK_SET ) < 0) return 0;
44  
45 -    return (unsigned long)fread( buffer, 1, count, file );
46 +    return (unsigned long) read(fd,buffer,count);
47    }
48  
49  
50 @@ -219,14 +220,14 @@
51    FT_Stream_Open( FT_Stream    stream,
52                    const char*  filepathname )
53    {
54 -    FILE*  file;
55 +    int fd,n;
56  
57  
58      if ( !stream )
59        return FT_Err_Invalid_Stream_Handle;
60  
61 -    file = fopen( filepathname, "rb" );
62 -    if ( !file )
63 +    fd = open( filepathname, O_RDONLY);
64 +    if (fd < 0)
65      {
66        FT_ERROR(( "FT_Stream_Open:" ));
67        FT_ERROR(( " could not open `%s'\n", filepathname ));
68 @@ -234,11 +235,11 @@
69        return FT_Err_Cannot_Open_Resource;
70      }
71  
72 -    fseek( file, 0, SEEK_END );
73 -    stream->size = ftell( file );
74 -    fseek( file, 0, SEEK_SET );
75 +    n = lseek( fd, 0, SEEK_END );
76 +    stream-> size = n < 0 ? 0 : n;
77 +    lseek( fd, 0, SEEK_SET );
78  
79 -    stream->descriptor.pointer = file;
80 +    stream->descriptor.value   = fd;
81      stream->pathname.pointer   = (char*)filepathname;
82      stream->pos                = 0;
83