2 #include FT_SYSTEM_STREAM_H
6 /* the ISO/ANSI standard stream object */
7 typedef struct FT_StdStreamRec_
13 } FT_StdStreamRec, *FT_StdStream;
17 /* read bytes from a standard stream */
19 ft_std_stream_read( FT_StdStream stream,
25 read_bytes = fread( buffer, 1, size, stream->file );
29 return (FT_ULong) read_bytes;
33 /* seek the standard stream to a new position */
35 ft_std_stream_seek( FT_StdStream stream,
38 return ( fseek( stream->file, pos, SEEK_SET ) < 0 )
44 /* close a standard stream */
46 ft_std_stream_done( FT_StdStream stream )
48 fclose( stream->file );
50 stream->pathname = NULL;
54 /* open a standard stream from a given pathname */
56 ft_std_stream_init( FT_StdStream stream,
57 const char* pathname )
59 FT_ASSERT( pathname != NULL );
61 stream->file = fopen( pathname, "rb" );
62 if ( stream->file == NULL )
64 FT_ERROR(( "iso.stream.init: could not open '%s'\n", pathname ));
65 FT_XTHROW( FT_Err_Stream_Open );
68 /* compute total size in bytes */
69 fseek( file, 0, SEEK_END );
70 FT_STREAM__SIZE(stream) = ftell( file );
71 fseek( file, 0, SEEK_SET );
73 stream->pathname = pathname;
76 FT_TRACE1(( "iso.stream.init: opened '%s' (%ld bytes) succesfully\n",
77 pathname, FT_STREAM__SIZE(stream) ));
82 ft_std_stream_class_init( FT_ClassRec* _clazz )
84 FT_StreamClassRec* clazz = FT_STREAM_CLASS(_clazz);
86 clazz->stream_read = (FT_Stream_ReadFunc) ft_std_stream_read;
87 clazz->stream_seek = (FT_Stream_SeekFunc) ft_std_stream_seek;
91 static const FT_TypeRec ft_std_stream_type;
96 sizeof( FT_ClassRec ),
100 sizeof( FT_StdStreamRec ),
108 FT_EXPORT_DEF( FT_Stream )
109 ft_std_stream_new( FT_Memory memory,
110 const char* pathname )
114 clazz = ft_class_from_type( memory, &ft_std_stream_type );
116 return (FT_Stream) ft_object_new( clazz, pathname );
120 FT_EXPORT_DEF( void )
121 ft_std_stream_create( FT_Memory memory,
122 const char* pathname,
127 clazz = ft_class_from_type( memory, &ft_std_stream_type );
129 ft_object_create( clazz, pathname, FT_OBJECT_P(astream) );