From f6af979d2e5e1a6e859c8acce38849306eb23cee Mon Sep 17 00:00:00 2001 From: suzuki toshiya Date: Thu, 6 Jan 2011 18:34:36 +0900 Subject: introduce ft_basename(): if libgen.h is available, it is a macro to system basename() --- builds/unix/configure.raw | 2 +- builds/unix/ftconfig.in | 1 + include/freetype/internal/ftobjs.h | 8 ++++++++ src/base/ftobjs.c | 21 +++++++++++++++++++++ 4 files changed, 31 insertions(+), 1 deletion(-) diff --git a/builds/unix/configure.raw b/builds/unix/configure.raw index cb10ef481..6e4c1c287 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 680fc7f2d..3bb68fb82 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' */ diff --git a/include/freetype/internal/ftobjs.h b/include/freetype/internal/ftobjs.h index 670eb78a8..4cffb1318 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/ftobjs.c b/src/base/ftobjs.c index 6b01f43d5..afe299501 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 */ -- cgit v1.2.1