ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

ftsystem.c
Go to the documentation of this file.
00001 /***************************************************************************/
00002 /*                                                                         */
00003 /*  ftsystem.c                                                             */
00004 /*                                                                         */
00005 /*    ANSI-specific FreeType low-level system interface (body).            */
00006 /*                                                                         */
00007 /*  Copyright 1996-2001, 2002, 2006, 2008, 2009, 2010 by                   */
00008 /*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
00009 /*                                                                         */
00010 /*  This file is part of the FreeType project, and may only be used,       */
00011 /*  modified, and distributed under the terms of the FreeType project      */
00012 /*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */
00013 /*  this file you indicate that you have read the license and              */
00014 /*  understand and accept it fully.                                        */
00015 /*                                                                         */
00016 /***************************************************************************/
00017 
00018   /*************************************************************************/
00019   /*                                                                       */
00020   /* This file contains the default interface used by FreeType to access   */
00021   /* low-level, i.e. memory management, i/o access as well as thread       */
00022   /* synchronisation.  It can be replaced by user-specific routines if     */
00023   /* necessary.                                                            */
00024   /*                                                                       */
00025   /*************************************************************************/
00026 
00027 
00028 #include <ft2build.h>
00029 #include FT_CONFIG_CONFIG_H
00030 #include FT_INTERNAL_DEBUG_H
00031 #include FT_INTERNAL_STREAM_H
00032 #include FT_SYSTEM_H
00033 #include FT_ERRORS_H
00034 #include FT_TYPES_H
00035 
00036 
00037   /*************************************************************************/
00038   /*                                                                       */
00039   /*                       MEMORY MANAGEMENT INTERFACE                     */
00040   /*                                                                       */
00041   /*************************************************************************/
00042 
00043   /*************************************************************************/
00044   /*                                                                       */
00045   /* It is not necessary to do any error checking for the                  */
00046   /* allocation-related functions.  This will be done by the higher level  */
00047   /* routines like ft_mem_alloc() or ft_mem_realloc().                     */
00048   /*                                                                       */
00049   /*************************************************************************/
00050 
00051 
00052   /*************************************************************************/
00053   /*                                                                       */
00054   /* <Function>                                                            */
00055   /*    ft_alloc                                                           */
00056   /*                                                                       */
00057   /* <Description>                                                         */
00058   /*    The memory allocation function.                                    */
00059   /*                                                                       */
00060   /* <Input>                                                               */
00061   /*    memory :: A pointer to the memory object.                          */
00062   /*                                                                       */
00063   /*    size   :: The requested size in bytes.                             */
00064   /*                                                                       */
00065   /* <Return>                                                              */
00066   /*    The address of newly allocated block.                              */
00067   /*                                                                       */
00068   FT_CALLBACK_DEF( void* )
00069   ft_alloc( FT_Memory  memory,
00070             long       size )
00071   {
00072     FT_UNUSED( memory );
00073 
00074     return ft_smalloc( size );
00075   }
00076 
00077 
00078   /*************************************************************************/
00079   /*                                                                       */
00080   /* <Function>                                                            */
00081   /*    ft_realloc                                                         */
00082   /*                                                                       */
00083   /* <Description>                                                         */
00084   /*    The memory reallocation function.                                  */
00085   /*                                                                       */
00086   /* <Input>                                                               */
00087   /*    memory   :: A pointer to the memory object.                        */
00088   /*                                                                       */
00089   /*    cur_size :: The current size of the allocated memory block.        */
00090   /*                                                                       */
00091   /*    new_size :: The newly requested size in bytes.                     */
00092   /*                                                                       */
00093   /*    block    :: The current address of the block in memory.            */
00094   /*                                                                       */
00095   /* <Return>                                                              */
00096   /*    The address of the reallocated memory block.                       */
00097   /*                                                                       */
00098   FT_CALLBACK_DEF( void* )
00099   ft_realloc( FT_Memory  memory,
00100               long       cur_size,
00101               long       new_size,
00102               void*      block )
00103   {
00104     FT_UNUSED( memory );
00105     FT_UNUSED( cur_size );
00106 
00107     return ft_srealloc( block, new_size );
00108   }
00109 
00110 
00111   /*************************************************************************/
00112   /*                                                                       */
00113   /* <Function>                                                            */
00114   /*    ft_free                                                            */
00115   /*                                                                       */
00116   /* <Description>                                                         */
00117   /*    The memory release function.                                       */
00118   /*                                                                       */
00119   /* <Input>                                                               */
00120   /*    memory  :: A pointer to the memory object.                         */
00121   /*                                                                       */
00122   /*    block   :: The address of block in memory to be freed.             */
00123   /*                                                                       */
00124   FT_CALLBACK_DEF( void )
00125   ft_free( FT_Memory  memory,
00126            void*      block )
00127   {
00128     FT_UNUSED( memory );
00129 
00130     ft_sfree( block );
00131   }
00132 
00133 
00134   /*************************************************************************/
00135   /*                                                                       */
00136   /*                     RESOURCE MANAGEMENT INTERFACE                     */
00137   /*                                                                       */
00138   /*************************************************************************/
00139 
00140 
00141   /*************************************************************************/
00142   /*                                                                       */
00143   /* The macro FT_COMPONENT is used in trace mode.  It is an implicit      */
00144   /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log  */
00145   /* messages during execution.                                            */
00146   /*                                                                       */
00147 #undef  FT_COMPONENT
00148 #define FT_COMPONENT  trace_io
00149 
00150   /* We use the macro STREAM_FILE for convenience to extract the       */
00151   /* system-specific stream handle from a given FreeType stream object */
00152 #define STREAM_FILE( stream )  ( (FT_FILE*)stream->descriptor.pointer )
00153 
00154 
00155   /*************************************************************************/
00156   /*                                                                       */
00157   /* <Function>                                                            */
00158   /*    ft_ansi_stream_close                                               */
00159   /*                                                                       */
00160   /* <Description>                                                         */
00161   /*    The function to close a stream.                                    */
00162   /*                                                                       */
00163   /* <Input>                                                               */
00164   /*    stream :: A pointer to the stream object.                          */
00165   /*                                                                       */
00166   FT_CALLBACK_DEF( void )
00167   ft_ansi_stream_close( FT_Stream  stream )
00168   {
00169     ft_fclose( STREAM_FILE( stream ) );
00170 
00171     stream->descriptor.pointer = NULL;
00172     stream->size               = 0;
00173     stream->base               = 0;
00174   }
00175 
00176 
00177   /*************************************************************************/
00178   /*                                                                       */
00179   /* <Function>                                                            */
00180   /*    ft_ansi_stream_io                                                  */
00181   /*                                                                       */
00182   /* <Description>                                                         */
00183   /*    The function to open a stream.                                     */
00184   /*                                                                       */
00185   /* <Input>                                                               */
00186   /*    stream :: A pointer to the stream object.                          */
00187   /*                                                                       */
00188   /*    offset :: The position in the data stream to start reading.        */
00189   /*                                                                       */
00190   /*    buffer :: The address of buffer to store the read data.            */
00191   /*                                                                       */
00192   /*    count  :: The number of bytes to read from the stream.             */
00193   /*                                                                       */
00194   /* <Return>                                                              */
00195   /*    The number of bytes actually read.  If `count' is zero (this is,   */
00196   /*    the function is used for seeking), a non-zero return value         */
00197   /*    indicates an error.                                                */
00198   /*                                                                       */
00199   FT_CALLBACK_DEF( unsigned long )
00200   ft_ansi_stream_io( FT_Stream       stream,
00201                      unsigned long   offset,
00202                      unsigned char*  buffer,
00203                      unsigned long   count )
00204   {
00205     FT_FILE*  file;
00206 
00207 
00208     if ( !count && offset > stream->size )
00209       return 1;
00210 
00211     file = STREAM_FILE( stream );
00212 
00213     if ( stream->pos != offset )
00214       ft_fseek( file, offset, SEEK_SET );
00215 
00216     return (unsigned long)ft_fread( buffer, 1, count, file );
00217   }
00218 
00219 
00220   /* documentation is in ftstream.h */
00221 
00222   FT_BASE_DEF( FT_Error )
00223   FT_Stream_Open( FT_Stream    stream,
00224                   const char*  filepathname )
00225   {
00226     FT_FILE*  file;
00227 
00228 
00229     if ( !stream )
00230       return FT_Err_Invalid_Stream_Handle;
00231 
00232     stream->descriptor.pointer = NULL;
00233     stream->pathname.pointer   = (char*)filepathname;
00234     stream->base               = 0;
00235     stream->pos                = 0;
00236     stream->read               = NULL;
00237     stream->close              = NULL;
00238 
00239     file = ft_fopen( filepathname, "rb" );
00240     if ( !file )
00241     {
00242       FT_ERROR(( "FT_Stream_Open:"
00243                  " could not open `%s'\n", filepathname ));
00244 
00245       return FT_Err_Cannot_Open_Resource;
00246     }
00247 
00248     ft_fseek( file, 0, SEEK_END );
00249     stream->size = ft_ftell( file );
00250     if ( !stream->size )
00251     {
00252       FT_ERROR(( "FT_Stream_Open:" ));
00253       FT_ERROR(( " opened `%s' but zero-sized\n", filepathname ));
00254       ft_fclose( file );
00255       return FT_Err_Cannot_Open_Stream;
00256     }
00257     ft_fseek( file, 0, SEEK_SET );
00258 
00259     stream->descriptor.pointer = file;
00260     stream->read  = ft_ansi_stream_io;
00261     stream->close = ft_ansi_stream_close;
00262 
00263     FT_TRACE1(( "FT_Stream_Open:" ));
00264     FT_TRACE1(( " opened `%s' (%d bytes) successfully\n",
00265                 filepathname, stream->size ));
00266 
00267     return FT_Err_Ok;
00268   }
00269 
00270 
00271 #ifdef FT_DEBUG_MEMORY
00272 
00273   extern FT_Int
00274   ft_mem_debug_init( FT_Memory  memory );
00275 
00276   extern void
00277   ft_mem_debug_done( FT_Memory  memory );
00278 
00279 #endif
00280 
00281 
00282   /* documentation is in ftobjs.h */
00283 
00284   FT_BASE_DEF( FT_Memory )
00285   FT_New_Memory( void )
00286   {
00287     FT_Memory  memory;
00288 
00289 
00290     memory = (FT_Memory)ft_smalloc( sizeof ( *memory ) );
00291     if ( memory )
00292     {
00293       memory->user    = 0;
00294       memory->alloc   = ft_alloc;
00295       memory->realloc = ft_realloc;
00296       memory->free    = ft_free;
00297 #ifdef FT_DEBUG_MEMORY
00298       ft_mem_debug_init( memory );
00299 #endif
00300     }
00301 
00302     return memory;
00303   }
00304 
00305 
00306   /* documentation is in ftobjs.h */
00307 
00308   FT_BASE_DEF( void )
00309   FT_Done_Memory( FT_Memory  memory )
00310   {
00311 #ifdef FT_DEBUG_MEMORY
00312     ft_mem_debug_done( memory );
00313 #endif
00314     ft_sfree( memory );
00315   }
00316 
00317 
00318 /* END */

Generated on Sat May 26 2012 04:32:38 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.