introduce ft_basename(): if libgen.h is available, it is a macro to system basename()

This commit is contained in:
suzuki toshiya 2011-01-06 18:34:36 +09:00
parent dfaf70a056
commit f6af979d2e
4 changed files with 31 additions and 1 deletions

View File

@ -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

View File

@ -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' */

View File

@ -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 <libgen.h>
#define ft_basename( p ) basename( ( p ) )
#else
FT_BASE( char* )
ft_basename( char* path );
#endif
/*************************************************************************/
/*************************************************************************/

View File

@ -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 */