diff options
author | David Aguilar <davvid@gmail.com> | 2009-05-31 01:35:51 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2009-05-31 17:57:59 -0700 |
commit | e1c068869216c8c231c1585bbfa9fda42b4756f8 (patch) | |
tree | 929b5984b0ce8bfaba925a84ebb5ae04e7559e28 | |
parent | 0620b39b3b7b1f27bf863d9591fd8146a9a8931d (diff) | |
download | git-e1c068869216c8c231c1585bbfa9fda42b4756f8.tar.gz |
compat: add a basename() compatibility function
Some systems such as Windows lack libgen.h so provide a
basename() implementation for cross-platform use.
This introduces the NO_LIBGEN_H construct to the Makefile
and autoconf scripts.
Signed-off-by: David Aguilar <davvid@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r-- | Makefile | 8 | ||||
-rw-r--r-- | compat/basename.c | 15 | ||||
-rw-r--r-- | config.mak.in | 1 | ||||
-rw-r--r-- | configure.ac | 6 | ||||
-rw-r--r-- | git-compat-util.h | 7 |
5 files changed, 37 insertions, 0 deletions
@@ -54,6 +54,8 @@ all:: # # Define NO_MKSTEMPS if you don't have mkstemps in the C library. # +# Define NO_LIBGEN_H if you don't have libgen.h. +# # Define NO_SYS_SELECT_H if you don't have sys/select.h. # # Define NO_SYMLINK_HEAD if you never want .git/HEAD to be a symbolic link. @@ -834,6 +836,7 @@ ifneq (,$(findstring MINGW,$(uname_S))) NO_PREAD = YesPlease NO_OPENSSL = YesPlease NO_CURL = YesPlease + NO_LIBGEN_H = YesPlease NO_SYMLINK_HEAD = YesPlease NO_IPV6 = YesPlease NO_SETENV = YesPlease @@ -899,6 +902,11 @@ ifndef CC_LD_DYNPATH endif endif +ifdef NO_LIBGEN_H + COMPAT_CFLAGS += -DNO_LIBGEN_H + COMPAT_OBJS += compat/basename.o +endif + ifdef NO_CURL BASIC_CFLAGS += -DNO_CURL else diff --git a/compat/basename.c b/compat/basename.c new file mode 100644 index 0000000000..d8f8a3c6dc --- /dev/null +++ b/compat/basename.c @@ -0,0 +1,15 @@ +#include "../git-compat-util.h" + +/* Adapted from libiberty's basename.c. */ +char *gitbasename (char *path) +{ + const char *base; + /* Skip over the disk name in MSDOS pathnames. */ + if (has_dos_drive_prefix(path)) + path += 2; + for (base = path; *path; path++) { + if (is_dir_sep(*path)) + base = path + 1; + } + return (char *)base; +} diff --git a/config.mak.in b/config.mak.in index b6619af1b9..e8d96e88b9 100644 --- a/config.mak.in +++ b/config.mak.in @@ -30,6 +30,7 @@ NEEDS_SSL_WITH_CRYPTO=@NEEDS_SSL_WITH_CRYPTO@ NO_OPENSSL=@NO_OPENSSL@ NO_CURL=@NO_CURL@ NO_EXPAT=@NO_EXPAT@ +NO_LIBGEN_H=@NO_LIBGEN_H@ NEEDS_LIBICONV=@NEEDS_LIBICONV@ NEEDS_SOCKET=@NEEDS_SOCKET@ NO_SYS_SELECT_H=@NO_SYS_SELECT_H@ diff --git a/configure.ac b/configure.ac index 953da07131..108a97fa8b 100644 --- a/configure.ac +++ b/configure.ac @@ -627,6 +627,12 @@ AC_SUBST(SNPRINTF_RETURNS_BOGUS) ## (in default C library and libraries checked by AC_CHECK_LIB) AC_MSG_NOTICE([CHECKS for library functions]) # +# Define NO_LIBGEN_H if you don't have libgen.h. +AC_CHECK_HEADER([libgen.h], +[NO_LIBGEN_H=], +[NO_LIBGEN_H=YesPlease]) +AC_SUBST(NO_LIBGEN_H) +# # Define NO_STRCASESTR if you don't have strcasestr. GIT_CHECK_FUNC(strcasestr, [NO_STRCASESTR=], diff --git a/git-compat-util.h b/git-compat-util.h index f7217ad430..71445c6aac 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -97,6 +97,13 @@ #include "compat/mingw.h" #endif /* __MINGW32__ */ +#ifndef NO_LIBGEN_H +#include <libgen.h> +#else +#define basename gitbasename +extern char *gitbasename(char *); +#endif + #ifndef NO_ICONV #include <iconv.h> #endif |