diff --git a/builds/unix/configure.raw b/builds/unix/configure.raw index cb10ef4..6e4c1c2 100644 --- a/builds/unix/configure.raw +++ b/builds/unix/configure.raw @@ -111,7 +111,7 @@ esac # checks for header files AC_HEADER_STDC -AC_CHECK_HEADERS([fcntl.h unistd.h]) +AC_CHECK_HEADERS([fcntl.h unistd.h libgen.h]) # checks for typedefs, structures, and compiler characteristics diff --git a/builds/unix/ftconfig.in b/builds/unix/ftconfig.in index 4c81187..3bb68fb 100644 --- a/builds/unix/ftconfig.in +++ b/builds/unix/ftconfig.in @@ -60,6 +60,7 @@ FT_BEGIN_HEADER #undef HAVE_UNISTD_H #undef HAVE_FCNTL_H #undef HAVE_STDINT_H +#undef HAVE_LIBGEN_H /* There are systems (like the Texas Instruments 'C54x) where a `char' */ @@ -167,6 +168,26 @@ FT_BEGIN_HEADER #endif + /*************************************************************************/ + /* */ + /* Pathname separator used by resource-fork accessor & ft_basename() */ + /* */ + +#ifdef PLATFORM_DIR_SEPARATOR + /* explicitly defined, do nothing */ +#elif defined( __DOS__ ) || defined( __OS2__ ) || defined( _WIN32 ) || \ + defined( __SYMBIAN32__ ) +#define PLATFORM_DIR_SEPARATOR "\\" +#elif defined( FT_MACINTOSH ) && !defined( __MACH__ ) +#define PLATFORM_DIR_SEPARATOR ":" +#elif defined( __riscos__ ) || defined( VMS ) +#define PLATFORM_DIR_SEPARATOR "." +#else +#define PLATFORM_DIR_SEPARATOR "/" +#endif + + + /* Fix compiler warning with sgi compiler */ #if defined( __sgi ) && !defined( __GNUC__ ) #if defined( _COMPILER_VERSION ) && ( _COMPILER_VERSION >= 730 ) diff --git a/include/freetype/config/ftconfig.h b/include/freetype/config/ftconfig.h index cbe30f2..cd0fa27 100644 --- a/include/freetype/config/ftconfig.h +++ b/include/freetype/config/ftconfig.h @@ -147,6 +147,25 @@ FT_BEGIN_HEADER /*************************************************************************/ /* */ + /* Pathname separator used by resource-fork accessor & ft_basename() */ + /* */ + +#ifdef PLATFORM_DIR_SEPARATOR + /* explicitly defined, do nothing */ +#elif defined( __DOS__ ) || defined( __OS2__ ) || defined( _WIN32 ) || \ + defined( __SYMBIAN32__ ) +#define PLATFORM_DIR_SEPARATOR "\\" +#elif defined( FT_MACINTOSH ) && !defined( __MACH__ ) +#define PLATFORM_DIR_SEPARATOR ":" +#elif defined( __riscos__ ) || defined( VMS ) +#define PLATFORM_DIR_SEPARATOR "." +#else +#define PLATFORM_DIR_SEPARATOR "/" +#endif + + + /*************************************************************************/ + /* */ /*
*/ /* basic_types */ /* */ diff --git a/include/freetype/internal/ftobjs.h b/include/freetype/internal/ftobjs.h index 670eb78..4cffb13 100644 --- a/include/freetype/internal/ftobjs.h +++ b/include/freetype/internal/ftobjs.h @@ -108,6 +108,14 @@ FT_BEGIN_HEADER #define ft_isalpha( x ) ( ft_isupper( x ) || ft_islower( x ) ) #define ft_isalnum( x ) ( ft_isdigit( x ) || ft_isalpha( x ) ) +#ifdef HAVE_LIBGEN_H +#include +#define ft_basename( p ) basename( ( p ) ) +#else + FT_BASE( char* ) + ft_basename( char* path ); +#endif + /*************************************************************************/ /*************************************************************************/ diff --git a/src/base/ftdbgmem.c b/src/base/ftdbgmem.c index bb04f68..538c086 100644 --- a/src/base/ftdbgmem.c +++ b/src/base/ftdbgmem.c @@ -521,7 +521,7 @@ ft_mem_get_env_val_for_source( FT_MemSource source, const char* env_var_name ) { - char *file_name = (char*)source->file_name; + char *file_name = ft_basename( (char*)source->file_name ); char *c, *c0; @@ -534,7 +534,12 @@ while ( NULL != ( c = ft_strstr( c, file_name ) ) ) { /* matched token is 1st or after separator space? */ - if ( c != c0 && *(c-1) != ' ' ) + if ( c != c0 && *(c-1) != ' ' && +#ifndef macintosh + *(c-1) != '/' && *(c-1) != '\\' ) +#else + *(c-1) != ':' ) +#endif goto NextToken; /* check ':', a separator between pathname & line number */ @@ -767,7 +772,8 @@ "FT2_ALLOC_CUR_MAX_SITE" ); if ( FT_HAS_LIMITER( site ) ) FT_TRACE6(( "ft_mem_table_set() invoked by %s:%lu, limit:( ", - source->file_name, source->line_no )); + ft_basename( (char*)source->file_name ), + source->line_no )); FT_TRACE6_DEFINED_LIMIT( req_all, mem_limit_site_total ); if ( FT_HAS_MULTI_LIMITERS( site ) ) FT_TRACE6(( " && " )); @@ -785,7 +791,8 @@ { FT_TRACE6(( "ft_mem_table_set() returns NULL to %s:%lu," " allocation request exceeds %s-limit (%lu > %lu)\n", - source->file_name, source->line_no, + ft_basename( (char*)source->file_name ), + source->line_no, ( exceeds_limit_site_total ? "site-total" : "site-current" ), ( exceeds_limit_site_total ? req_all : diff --git a/src/base/ftobjs.c b/src/base/ftobjs.c index 6b01f43..afe2995 100644 --- a/src/base/ftobjs.c +++ b/src/base/ftobjs.c @@ -1226,6 +1226,27 @@ } +#ifndef HAVE_LIBGEN_H + FT_BASE_DEF( char* ) + ft_basename( char* pathname ) + { + char* c; + + + c = pathname + ft_strlen( pathname ); + + /* skip trailing separator */ + while ( pathname < c && *c == PLATFORM_DIR_SEPARATOR[0] ) + c--; + + while ( pathname < c && *(c-1) != PLATFORM_DIR_SEPARATOR[0] ) + c--; + + return c; + } +#endif + + #ifdef FT_CONFIG_OPTION_MAC_FONTS /* The behavior here is very similar to that in base/ftmac.c, but it */ diff --git a/src/base/ftrfork.c b/src/base/ftrfork.c index b01ecb9..01be277 100644 --- a/src/base/ftrfork.c +++ b/src/base/ftrfork.c @@ -544,7 +544,8 @@ return error; FT_MEM_COPY( newpath, base_file_name, base_file_len ); - FT_MEM_COPY( newpath + base_file_len, "/rsrc", 6 ); + FT_MEM_COPY( newpath + base_file_len, + PLATFORM_DIR_SEPARATOR "rsrc", 6 ); *result_file_name = newpath; *result_offset = 0; @@ -580,7 +581,9 @@ return error; FT_MEM_COPY( newpath, base_file_name, base_file_len ); - FT_MEM_COPY( newpath + base_file_len, "/..namedfork/rsrc", 18 ); + FT_MEM_COPY( newpath + base_file_len, + PLATFORM_DIR_SEPARATOR "..namedfork" + PLATFORM_DIR_SEPARATOR "rsrc", 18 ); *result_file_name = newpath; *result_offset = 0; @@ -605,7 +608,8 @@ memory = library->memory; newpath = raccess_make_file_name( memory, base_file_name, - "resource.frk/" ); + "resource.frk" + PLATFORM_DIR_SEPARATOR ); if ( !newpath ) return FT_Err_Out_Of_Memory; @@ -631,7 +635,9 @@ memory = library->memory; - newpath = raccess_make_file_name( memory, base_file_name, ".resource/" ); + newpath = raccess_make_file_name( memory, base_file_name, + ".resource" + PLATFORM_DIR_SEPARATOR ); if ( !newpath ) return FT_Err_Out_Of_Memory; @@ -690,7 +696,8 @@ memory = library->memory; newpath = raccess_make_file_name( memory, base_file_name, - ".AppleDouble/" ); + ".AppleDouble" + PLATFORM_DIR_SEPARATOR ); if ( !newpath ) return FT_Err_Out_Of_Memory; @@ -815,7 +822,7 @@ if ( FT_ALLOC( new_name, new_length + 1 ) ) return NULL; - tmp = ft_strrchr( original_name, '/' ); + tmp = ft_strrchr( original_name, PLATFORM_DIR_SEPARATOR[0] ); if ( tmp ) { ft_strncpy( new_name, original_name, tmp - original_name + 1 );