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

ftrfork.c
Go to the documentation of this file.
00001 /***************************************************************************/
00002 /*                                                                         */
00003 /*  ftrfork.c                                                              */
00004 /*                                                                         */
00005 /*    Embedded resource forks accessor (body).                             */
00006 /*                                                                         */
00007 /*  Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010 by                  */
00008 /*  Masatake YAMATO and Redhat K.K.                                        */
00009 /*                                                                         */
00010 /*  FT_Raccess_Get_HeaderInfo() and raccess_guess_darwin_hfsplus() are     */
00011 /*  derived from ftobjs.c.                                                 */
00012 /*                                                                         */
00013 /*  This file is part of the FreeType project, and may only be used,       */
00014 /*  modified, and distributed under the terms of the FreeType project      */
00015 /*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */
00016 /*  this file you indicate that you have read the license and              */
00017 /*  understand and accept it fully.                                        */
00018 /*                                                                         */
00019 /***************************************************************************/
00020 
00021 /***************************************************************************/
00022 /* Development of the code in this file is support of                      */
00023 /* Information-technology Promotion Agency, Japan.                         */
00024 /***************************************************************************/
00025 
00026 
00027 #include <ft2build.h>
00028 #include FT_INTERNAL_DEBUG_H
00029 #include FT_INTERNAL_STREAM_H
00030 #include FT_INTERNAL_RFORK_H
00031 
00032 
00033 #undef  FT_COMPONENT
00034 #define FT_COMPONENT  trace_raccess
00035 
00036 
00037   /*************************************************************************/
00038   /*************************************************************************/
00039   /*************************************************************************/
00040   /****                                                                 ****/
00041   /****                                                                 ****/
00042   /****               Resource fork directory access                    ****/
00043   /****                                                                 ****/
00044   /****                                                                 ****/
00045   /*************************************************************************/
00046   /*************************************************************************/
00047   /*************************************************************************/
00048 
00049   FT_BASE_DEF( FT_Error )
00050   FT_Raccess_Get_HeaderInfo( FT_Library  library,
00051                              FT_Stream   stream,
00052                              FT_Long     rfork_offset,
00053                              FT_Long    *map_offset,
00054                              FT_Long    *rdata_pos )
00055   {
00056     FT_Error       error;
00057     unsigned char  head[16], head2[16];
00058     FT_Long        map_pos, rdata_len;
00059     int            allzeros, allmatch, i;
00060     FT_Long        type_list;
00061 
00062     FT_UNUSED( library );
00063 
00064 
00065     error = FT_Stream_Seek( stream, rfork_offset );
00066     if ( error )
00067       return error;
00068 
00069     error = FT_Stream_Read( stream, (FT_Byte *)head, 16 );
00070     if ( error )
00071       return error;
00072 
00073     *rdata_pos = rfork_offset + ( ( head[0] << 24 ) |
00074                                   ( head[1] << 16 ) |
00075                                   ( head[2] <<  8 ) |
00076                                     head[3]         );
00077     map_pos    = rfork_offset + ( ( head[4] << 24 ) |
00078                                   ( head[5] << 16 ) |
00079                                   ( head[6] <<  8 ) |
00080                                     head[7]         );
00081     rdata_len = ( head[ 8] << 24 ) |
00082                 ( head[ 9] << 16 ) |
00083                 ( head[10] <<  8 ) |
00084                   head[11];
00085 
00086     /* map_len = head[12] .. head[15] */
00087 
00088     if ( *rdata_pos + rdata_len != map_pos || map_pos == rfork_offset )
00089       return FT_Err_Unknown_File_Format;
00090 
00091     error = FT_Stream_Seek( stream, map_pos );
00092     if ( error )
00093       return error;
00094 
00095     head2[15] = (FT_Byte)( head[15] + 1 );       /* make it be different */
00096 
00097     error = FT_Stream_Read( stream, (FT_Byte*)head2, 16 );
00098     if ( error )
00099       return error;
00100 
00101     allzeros = 1;
00102     allmatch = 1;
00103     for ( i = 0; i < 16; ++i )
00104     {
00105       if ( head2[i] != 0 )
00106         allzeros = 0;
00107       if ( head2[i] != head[i] )
00108         allmatch = 0;
00109     }
00110     if ( !allzeros && !allmatch )
00111       return FT_Err_Unknown_File_Format;
00112 
00113     /* If we have reached this point then it is probably a mac resource */
00114     /* file.  Now, does it contain any interesting resources?           */
00115     /* Skip handle to next resource map, the file resource number, and  */
00116     /* attributes.                                                      */
00117     (void)FT_STREAM_SKIP( 4        /* skip handle to next resource map */
00118                           + 2      /* skip file resource number */
00119                           + 2 );   /* skip attributes */
00120 
00121     if ( FT_READ_USHORT( type_list ) )
00122       return error;
00123     if ( type_list == -1 )
00124       return FT_Err_Unknown_File_Format;
00125 
00126     error = FT_Stream_Seek( stream, map_pos + type_list );
00127     if ( error )
00128       return error;
00129 
00130     *map_offset = map_pos + type_list;
00131     return FT_Err_Ok;
00132   }
00133 
00134 
00135   static int
00136   ft_raccess_sort_ref_by_id( FT_RFork_Ref*  a,
00137                              FT_RFork_Ref*  b )
00138   {
00139     if ( a->res_id < b->res_id )
00140       return -1;
00141     else if ( a->res_id > b->res_id )
00142       return 1;
00143     else
00144       return 0;
00145   }
00146 
00147 
00148   FT_BASE_DEF( FT_Error )
00149   FT_Raccess_Get_DataOffsets( FT_Library  library,
00150                               FT_Stream   stream,
00151                               FT_Long     map_offset,
00152                               FT_Long     rdata_pos,
00153                               FT_Long     tag,
00154                               FT_Long   **offsets,
00155                               FT_Long    *count )
00156   {
00157     FT_Error      error;
00158     int           i, j, cnt, subcnt;
00159     FT_Long       tag_internal, rpos;
00160     FT_Memory     memory = library->memory;
00161     FT_Long       temp;
00162     FT_Long       *offsets_internal;
00163     FT_RFork_Ref  *ref;
00164 
00165 
00166     error = FT_Stream_Seek( stream, map_offset );
00167     if ( error )
00168       return error;
00169 
00170     if ( FT_READ_USHORT( cnt ) )
00171       return error;
00172     cnt++;
00173 
00174     for ( i = 0; i < cnt; ++i )
00175     {
00176       if ( FT_READ_LONG( tag_internal ) ||
00177            FT_READ_USHORT( subcnt )     ||
00178            FT_READ_USHORT( rpos )       )
00179         return error;
00180 
00181       FT_TRACE2(( "Resource tags: %c%c%c%c\n",
00182                   (char)( 0xff & ( tag_internal >> 24 ) ),
00183                   (char)( 0xff & ( tag_internal >> 16 ) ),
00184                   (char)( 0xff & ( tag_internal >>  8 ) ),
00185                   (char)( 0xff & ( tag_internal >>  0 ) ) ));
00186 
00187       if ( tag_internal == tag )
00188       {
00189         *count = subcnt + 1;
00190         rpos  += map_offset;
00191 
00192         error = FT_Stream_Seek( stream, rpos );
00193         if ( error )
00194           return error;
00195 
00196         if ( FT_NEW_ARRAY( ref, *count ) )
00197           return error;
00198 
00199         for ( j = 0; j < *count; ++j )
00200         {
00201           if ( FT_READ_USHORT( ref[j].res_id ) )
00202             goto Exit;
00203           if ( FT_STREAM_SKIP( 2 ) ) /* resource name */
00204             goto Exit;
00205           if ( FT_READ_LONG( temp ) )
00206             goto Exit;
00207           if ( FT_STREAM_SKIP( 4 ) ) /* mbz */
00208             goto Exit;
00209 
00210           ref[j].offset = temp & 0xFFFFFFL;
00211         }
00212 
00213         ft_qsort( ref, *count, sizeof ( FT_RFork_Ref ),
00214                   ( int(*)(const void*, const void*) )
00215                   ft_raccess_sort_ref_by_id );
00216 
00217         if ( FT_NEW_ARRAY( offsets_internal, *count ) )
00218           goto Exit;
00219 
00220         /* XXX: duplicated reference ID,
00221          *      gap between reference IDs are acceptable?
00222          *      further investigation on Apple implementation is needed.
00223          */
00224         for ( j = 0; j < *count; ++j )
00225           offsets_internal[j] = rdata_pos + ref[j].offset;
00226 
00227         *offsets = offsets_internal;
00228         error    = FT_Err_Ok;
00229 
00230       Exit:
00231         FT_FREE( ref );
00232         return error;
00233       }
00234     }
00235 
00236     return FT_Err_Cannot_Open_Resource;
00237   }
00238 
00239 
00240 #ifdef FT_CONFIG_OPTION_GUESSING_EMBEDDED_RFORK
00241 
00242   /*************************************************************************/
00243   /*************************************************************************/
00244   /*************************************************************************/
00245   /****                                                                 ****/
00246   /****                                                                 ****/
00247   /****                     Guessing functions                          ****/
00248   /****                                                                 ****/
00249   /****            When you add a new guessing function,                ****/
00250   /****           update FT_RACCESS_N_RULES in ftrfork.h.               ****/
00251   /****                                                                 ****/
00252   /*************************************************************************/
00253   /*************************************************************************/
00254   /*************************************************************************/
00255 
00256   typedef FT_Error
00257   (*raccess_guess_func)( FT_Library  library,
00258                          FT_Stream   stream,
00259                          char       *base_file_name,
00260                          char      **result_file_name,
00261                          FT_Long    *result_offset );
00262 
00263 
00264   static FT_Error
00265   raccess_guess_apple_double( FT_Library  library,
00266                               FT_Stream   stream,
00267                               char       *base_file_name,
00268                               char      **result_file_name,
00269                               FT_Long    *result_offset );
00270 
00271   static FT_Error
00272   raccess_guess_apple_single( FT_Library  library,
00273                               FT_Stream   stream,
00274                               char       *base_file_name,
00275                               char      **result_file_name,
00276                               FT_Long    *result_offset );
00277 
00278   static FT_Error
00279   raccess_guess_darwin_ufs_export( FT_Library  library,
00280                                    FT_Stream   stream,
00281                                    char       *base_file_name,
00282                                    char      **result_file_name,
00283                                    FT_Long    *result_offset );
00284 
00285   static FT_Error
00286   raccess_guess_darwin_newvfs( FT_Library  library,
00287                                FT_Stream   stream,
00288                                char       *base_file_name,
00289                                char      **result_file_name,
00290                                FT_Long    *result_offset );
00291 
00292   static FT_Error
00293   raccess_guess_darwin_hfsplus( FT_Library  library,
00294                                 FT_Stream   stream,
00295                                 char       *base_file_name,
00296                                 char      **result_file_name,
00297                                 FT_Long    *result_offset );
00298 
00299   static FT_Error
00300   raccess_guess_vfat( FT_Library  library,
00301                       FT_Stream   stream,
00302                       char       *base_file_name,
00303                       char      **result_file_name,
00304                       FT_Long    *result_offset );
00305 
00306   static FT_Error
00307   raccess_guess_linux_cap( FT_Library  library,
00308                            FT_Stream   stream,
00309                            char       *base_file_name,
00310                            char      **result_file_name,
00311                            FT_Long    *result_offset );
00312 
00313   static FT_Error
00314   raccess_guess_linux_double( FT_Library  library,
00315                               FT_Stream   stream,
00316                               char       *base_file_name,
00317                               char      **result_file_name,
00318                               FT_Long    *result_offset );
00319 
00320   static FT_Error
00321   raccess_guess_linux_netatalk( FT_Library  library,
00322                                 FT_Stream   stream,
00323                                 char       *base_file_name,
00324                                 char      **result_file_name,
00325                                 FT_Long    *result_offset );
00326 
00327 
00328   /*************************************************************************/
00329   /****                                                                 ****/
00330   /****                       Helper functions                          ****/
00331   /****                                                                 ****/
00332   /*************************************************************************/
00333 
00334   static FT_Error
00335   raccess_guess_apple_generic( FT_Library  library,
00336                                FT_Stream   stream,
00337                                char       *base_file_name,
00338                                FT_Int32    magic,
00339                                FT_Long    *result_offset );
00340 
00341   static FT_Error
00342   raccess_guess_linux_double_from_file_name( FT_Library  library,
00343                                              char *      file_name,
00344                                              FT_Long    *result_offset );
00345 
00346   static char *
00347   raccess_make_file_name( FT_Memory    memory,
00348                           const char  *original_name,
00349                           const char  *insertion );
00350 
00351 
00352   typedef enum  FT_RFork_Rule_ {
00353     FT_RFork_Rule_invalid = -2,
00354     FT_RFork_Rule_uknown, /* -1 */
00355     FT_RFork_Rule_apple_double,
00356     FT_RFork_Rule_apple_single,
00357     FT_RFork_Rule_darwin_ufs_export,
00358     FT_RFork_Rule_darwin_newvfs,
00359     FT_RFork_Rule_darwin_hfsplus,
00360     FT_RFork_Rule_vfat,
00361     FT_RFork_Rule_linux_cap,
00362     FT_RFork_Rule_linux_double,
00363     FT_RFork_Rule_linux_netatalk
00364   } FT_RFork_Rule;
00365 
00366   /* For fast translation between rule index and rule type,
00367    * the macros FT_RFORK_xxx should be kept consistent with
00368    * the raccess_guess_funcs table
00369    */
00370   typedef struct raccess_guess_rec_ {
00371     raccess_guess_func  func;
00372     FT_RFork_Rule       type;
00373   } raccess_guess_rec;
00374 
00375   static raccess_guess_rec  raccess_guess_table[FT_RACCESS_N_RULES] =
00376   {
00377     { raccess_guess_apple_double,   FT_RFork_Rule_apple_double, },
00378     { raccess_guess_apple_single,   FT_RFork_Rule_apple_single, },
00379     { raccess_guess_darwin_ufs_export,  FT_RFork_Rule_darwin_ufs_export, },
00380     { raccess_guess_darwin_newvfs,  FT_RFork_Rule_darwin_newvfs, },
00381     { raccess_guess_darwin_hfsplus, FT_RFork_Rule_darwin_hfsplus, },
00382     { raccess_guess_vfat,       FT_RFork_Rule_vfat, },
00383     { raccess_guess_linux_cap,      FT_RFork_Rule_linux_cap, },
00384     { raccess_guess_linux_double,   FT_RFork_Rule_linux_double, },
00385     { raccess_guess_linux_netatalk, FT_RFork_Rule_linux_netatalk, },
00386   };
00387 
00388   FT_BASE_DEF( void )
00389   FT_Raccess_Guess( FT_Library  library,
00390                     FT_Stream   stream,
00391                     char*       base_name,
00392                     char      **new_names,
00393                     FT_Long    *offsets,
00394                     FT_Error   *errors )
00395   {
00396     FT_Long  i;
00397 
00398 
00399     for ( i = 0; i < FT_RACCESS_N_RULES; i++ )
00400     {
00401       new_names[i] = NULL;
00402       if ( NULL != stream )
00403         errors[i] = FT_Stream_Seek( stream, 0 );
00404       else
00405         errors[i] = FT_Err_Ok;
00406 
00407       if ( errors[i] )
00408         continue ;
00409 
00410       errors[i] = (raccess_guess_table[i].func)( library,
00411                                                  stream, base_name,
00412                                                  &(new_names[i]),
00413                                                  &(offsets[i]) );
00414     }
00415 
00416     return;
00417   }
00418 
00419 
00420   static FT_RFork_Rule
00421   raccess_get_rule_type_from_rule_index( FT_UInt  rule_index )
00422   {
00423     if ( rule_index >= FT_RACCESS_N_RULES )
00424       return FT_RFork_Rule_invalid;
00425 
00426     return raccess_guess_table[rule_index].type;
00427   }
00428 
00429 
00430   FT_LOCAL_DEF( FT_Bool )
00431   raccess_rule_by_darwin_vfs( FT_UInt  rule_index )
00432   {
00433     switch( raccess_get_rule_type_from_rule_index( rule_index ) )
00434     {
00435       case FT_RFork_Rule_darwin_newvfs:
00436       case FT_RFork_Rule_darwin_hfsplus:
00437         return TRUE;
00438 
00439       default:
00440         return FALSE;
00441     }
00442   }
00443 
00444 
00445   static FT_Error
00446   raccess_guess_apple_double( FT_Library  library,
00447                               FT_Stream   stream,
00448                               char       *base_file_name,
00449                               char      **result_file_name,
00450                               FT_Long    *result_offset )
00451   {
00452     FT_Int32  magic = ( 0x00 << 24 ) |
00453                       ( 0x05 << 16 ) |
00454                       ( 0x16 <<  8 ) |
00455                         0x07;
00456 
00457 
00458     *result_file_name = NULL;
00459     if ( NULL == stream )
00460       return FT_Err_Cannot_Open_Stream;
00461 
00462     return raccess_guess_apple_generic( library, stream, base_file_name,
00463                                         magic, result_offset );
00464   }
00465 
00466 
00467   static FT_Error
00468   raccess_guess_apple_single( FT_Library  library,
00469                               FT_Stream   stream,
00470                               char       *base_file_name,
00471                               char      **result_file_name,
00472                               FT_Long    *result_offset )
00473   {
00474     FT_Int32  magic = ( 0x00 << 24 ) |
00475                       ( 0x05 << 16 ) |
00476                       ( 0x16 <<  8 ) |
00477                         0x00;
00478 
00479 
00480     *result_file_name = NULL;
00481     if ( NULL == stream )
00482       return FT_Err_Cannot_Open_Stream;
00483 
00484     return raccess_guess_apple_generic( library, stream, base_file_name,
00485                                         magic, result_offset );
00486   }
00487 
00488 
00489   static FT_Error
00490   raccess_guess_darwin_ufs_export( FT_Library  library,
00491                                    FT_Stream   stream,
00492                                    char       *base_file_name,
00493                                    char      **result_file_name,
00494                                    FT_Long    *result_offset )
00495   {
00496     char*      newpath;
00497     FT_Error   error;
00498     FT_Memory  memory;
00499 
00500     FT_UNUSED( stream );
00501 
00502 
00503     memory  = library->memory;
00504     newpath = raccess_make_file_name( memory, base_file_name, "._" );
00505     if ( !newpath )
00506       return FT_Err_Out_Of_Memory;
00507 
00508     error = raccess_guess_linux_double_from_file_name( library, newpath,
00509                                                        result_offset );
00510     if ( !error )
00511       *result_file_name = newpath;
00512     else
00513       FT_FREE( newpath );
00514 
00515     return error;
00516   }
00517 
00518 
00519   static FT_Error
00520   raccess_guess_darwin_hfsplus( FT_Library  library,
00521                                 FT_Stream   stream,
00522                                 char       *base_file_name,
00523                                 char      **result_file_name,
00524                                 FT_Long    *result_offset )
00525   {
00526     /*
00527       Only meaningful on systems with hfs+ drivers (or Macs).
00528      */
00529     FT_Error   error;
00530     char*      newpath;
00531     FT_Memory  memory;
00532     FT_Long    base_file_len = ft_strlen( base_file_name );
00533 
00534     FT_UNUSED( stream );
00535 
00536 
00537     memory = library->memory;
00538 
00539     if ( base_file_len + 6 > FT_INT_MAX )
00540       return FT_Err_Array_Too_Large;
00541 
00542     if ( FT_ALLOC( newpath, base_file_len + 6 ) )
00543       return error;
00544 
00545     FT_MEM_COPY( newpath, base_file_name, base_file_len );
00546     FT_MEM_COPY( newpath + base_file_len, "/rsrc", 6 );
00547 
00548     *result_file_name = newpath;
00549     *result_offset    = 0;
00550 
00551     return FT_Err_Ok;
00552   }
00553 
00554 
00555   static FT_Error
00556   raccess_guess_darwin_newvfs( FT_Library  library,
00557                                FT_Stream   stream,
00558                                char       *base_file_name,
00559                                char      **result_file_name,
00560                                FT_Long    *result_offset )
00561   {
00562     /*
00563       Only meaningful on systems with Mac OS X (> 10.1).
00564      */
00565     FT_Error   error;
00566     char*      newpath;
00567     FT_Memory  memory;
00568     FT_Long    base_file_len = ft_strlen( base_file_name );
00569 
00570     FT_UNUSED( stream );
00571 
00572 
00573     memory = library->memory;
00574 
00575     if ( base_file_len + 18 > FT_INT_MAX )
00576       return FT_Err_Array_Too_Large;
00577 
00578     if ( FT_ALLOC( newpath, base_file_len + 18 ) )
00579       return error;
00580 
00581     FT_MEM_COPY( newpath, base_file_name, base_file_len );
00582     FT_MEM_COPY( newpath + base_file_len, "/..namedfork/rsrc", 18 );
00583 
00584     *result_file_name = newpath;
00585     *result_offset    = 0;
00586 
00587     return FT_Err_Ok;
00588   }
00589 
00590 
00591   static FT_Error
00592   raccess_guess_vfat( FT_Library  library,
00593                       FT_Stream   stream,
00594                       char       *base_file_name,
00595                       char      **result_file_name,
00596                       FT_Long    *result_offset )
00597   {
00598     char*      newpath;
00599     FT_Memory  memory;
00600 
00601     FT_UNUSED( stream );
00602 
00603 
00604     memory = library->memory;
00605 
00606     newpath = raccess_make_file_name( memory, base_file_name,
00607                                       "resource.frk/" );
00608     if ( !newpath )
00609       return FT_Err_Out_Of_Memory;
00610 
00611     *result_file_name = newpath;
00612     *result_offset    = 0;
00613 
00614     return FT_Err_Ok;
00615   }
00616 
00617 
00618   static FT_Error
00619   raccess_guess_linux_cap( FT_Library  library,
00620                            FT_Stream   stream,
00621                            char       *base_file_name,
00622                            char      **result_file_name,
00623                            FT_Long    *result_offset )
00624   {
00625     char*      newpath;
00626     FT_Memory  memory;
00627 
00628     FT_UNUSED( stream );
00629 
00630 
00631     memory = library->memory;
00632 
00633     newpath = raccess_make_file_name( memory, base_file_name, ".resource/" );
00634     if ( !newpath )
00635       return FT_Err_Out_Of_Memory;
00636 
00637     *result_file_name = newpath;
00638     *result_offset    = 0;
00639 
00640     return FT_Err_Ok;
00641   }
00642 
00643 
00644   static FT_Error
00645   raccess_guess_linux_double( FT_Library  library,
00646                               FT_Stream   stream,
00647                               char       *base_file_name,
00648                               char      **result_file_name,
00649                               FT_Long    *result_offset )
00650   {
00651     char*      newpath;
00652     FT_Error   error;
00653     FT_Memory  memory;
00654 
00655     FT_UNUSED( stream );
00656 
00657 
00658     memory = library->memory;
00659 
00660     newpath = raccess_make_file_name( memory, base_file_name, "%" );
00661     if ( !newpath )
00662       return FT_Err_Out_Of_Memory;
00663 
00664     error = raccess_guess_linux_double_from_file_name( library, newpath,
00665                                                        result_offset );
00666     if ( !error )
00667       *result_file_name = newpath;
00668     else
00669       FT_FREE( newpath );
00670 
00671     return error;
00672   }
00673 
00674 
00675   static FT_Error
00676   raccess_guess_linux_netatalk( FT_Library  library,
00677                                 FT_Stream   stream,
00678                                 char       *base_file_name,
00679                                 char      **result_file_name,
00680                                 FT_Long    *result_offset )
00681   {
00682     char*      newpath;
00683     FT_Error   error;
00684     FT_Memory  memory;
00685 
00686     FT_UNUSED( stream );
00687 
00688 
00689     memory = library->memory;
00690 
00691     newpath = raccess_make_file_name( memory, base_file_name,
00692                                       ".AppleDouble/" );
00693     if ( !newpath )
00694       return FT_Err_Out_Of_Memory;
00695 
00696     error = raccess_guess_linux_double_from_file_name( library, newpath,
00697                                                        result_offset );
00698     if ( !error )
00699       *result_file_name = newpath;
00700     else
00701       FT_FREE( newpath );
00702 
00703     return error;
00704   }
00705 
00706 
00707   static FT_Error
00708   raccess_guess_apple_generic( FT_Library  library,
00709                                FT_Stream   stream,
00710                                char       *base_file_name,
00711                                FT_Int32    magic,
00712                                FT_Long    *result_offset )
00713   {
00714     FT_Int32   magic_from_stream;
00715     FT_Error   error;
00716     FT_Int32   version_number = 0;
00717     FT_UShort  n_of_entries;
00718 
00719     int        i;
00720     FT_UInt32  entry_id, entry_offset, entry_length = 0;
00721 
00722     const FT_UInt32  resource_fork_entry_id = 0x2;
00723 
00724     FT_UNUSED( library );
00725     FT_UNUSED( base_file_name );
00726     FT_UNUSED( version_number );
00727     FT_UNUSED( entry_length   );
00728 
00729 
00730     if ( FT_READ_LONG( magic_from_stream ) )
00731       return error;
00732     if ( magic_from_stream != magic )
00733       return FT_Err_Unknown_File_Format;
00734 
00735     if ( FT_READ_LONG( version_number ) )
00736       return error;
00737 
00738     /* filler */
00739     error = FT_Stream_Skip( stream, 16 );
00740     if ( error )
00741       return error;
00742 
00743     if ( FT_READ_USHORT( n_of_entries ) )
00744       return error;
00745     if ( n_of_entries == 0 )
00746       return FT_Err_Unknown_File_Format;
00747 
00748     for ( i = 0; i < n_of_entries; i++ )
00749     {
00750       if ( FT_READ_LONG( entry_id ) )
00751         return error;
00752       if ( entry_id == resource_fork_entry_id )
00753       {
00754         if ( FT_READ_LONG( entry_offset ) ||
00755              FT_READ_LONG( entry_length ) )
00756           continue;
00757         *result_offset = entry_offset;
00758 
00759         return FT_Err_Ok;
00760       }
00761       else
00762       {
00763         error = FT_Stream_Skip( stream, 4 + 4 );    /* offset + length */
00764         if ( error )
00765           return error;
00766       }
00767     }
00768 
00769     return FT_Err_Unknown_File_Format;
00770   }
00771 
00772 
00773   static FT_Error
00774   raccess_guess_linux_double_from_file_name( FT_Library  library,
00775                                              char       *file_name,
00776                                              FT_Long    *result_offset )
00777   {
00778     FT_Open_Args  args2;
00779     FT_Stream     stream2;
00780     char *        nouse = NULL;
00781     FT_Error      error;
00782 
00783 
00784     args2.flags    = FT_OPEN_PATHNAME;
00785     args2.pathname = file_name;
00786     error = FT_Stream_New( library, &args2, &stream2 );
00787     if ( error )
00788       return error;
00789 
00790     error = raccess_guess_apple_double( library, stream2, file_name,
00791                                         &nouse, result_offset );
00792 
00793     FT_Stream_Free( stream2, 0 );
00794 
00795     return error;
00796   }
00797 
00798 
00799   static char*
00800   raccess_make_file_name( FT_Memory    memory,
00801                           const char  *original_name,
00802                           const char  *insertion )
00803   {
00804     char*        new_name = NULL;
00805     const char*  tmp;
00806     const char*  slash;
00807     size_t       new_length;
00808     FT_Error     error = FT_Err_Ok;
00809 
00810     FT_UNUSED( error );
00811 
00812 
00813     new_length = ft_strlen( original_name ) + ft_strlen( insertion );
00814     if ( FT_ALLOC( new_name, new_length + 1 ) )
00815       return NULL;
00816 
00817     tmp = ft_strrchr( original_name, '/' );
00818     if ( tmp )
00819     {
00820       ft_strncpy( new_name, original_name, tmp - original_name + 1 );
00821       new_name[tmp - original_name + 1] = '\0';
00822       slash = tmp + 1;
00823     }
00824     else
00825     {
00826       slash       = original_name;
00827       new_name[0] = '\0';
00828     }
00829 
00830     ft_strcat( new_name, insertion );
00831     ft_strcat( new_name, slash );
00832 
00833     return new_name;
00834   }
00835 
00836 
00837 #else   /* !FT_CONFIG_OPTION_GUESSING_EMBEDDED_RFORK */
00838 
00839 
00840   /*************************************************************************/
00841   /*                  Dummy function; just sets errors                     */
00842   /*************************************************************************/
00843 
00844   FT_BASE_DEF( void )
00845   FT_Raccess_Guess( FT_Library  library,
00846                     FT_Stream   stream,
00847                     char       *base_name,
00848                     char      **new_names,
00849                     FT_Long    *offsets,
00850                     FT_Error   *errors )
00851   {
00852     int  i;
00853 
00854     FT_UNUSED( library );
00855     FT_UNUSED( stream );
00856     FT_UNUSED( base_name );
00857 
00858 
00859     for ( i = 0; i < FT_RACCESS_N_RULES; i++ )
00860     {
00861       new_names[i] = NULL;
00862       offsets[i]   = 0;
00863       errors[i]    = FT_Err_Unimplemented_Feature;
00864     }
00865   }
00866 
00867 
00868 #endif  /* !FT_CONFIG_OPTION_GUESSING_EMBEDDED_RFORK */
00869 
00870 
00871 /* END */

Generated on Sun May 27 2012 04:33:46 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.