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>
David Aguilar committed
May 31, 2009 at 01:35 UTC
e1c068869216c8c231c1585bbfa9fda42b4756f8
5 files changed
+37
Makefile
+8
@@ -54,6 +54,8 @@ all::
54
#
55
# Define NO_MKSTEMPS if you don't have mkstemps in the C library.
56
#
57
+# Define NO_LIBGEN_H if you don't have libgen.h.
58
+#
59
# Define NO_SYS_SELECT_H if you don't have sys/select.h.
60
#
61
# Define NO_SYMLINK_HEAD if you never want .git/HEAD to be a symbolic link.
@@ -834,6 +836,7 @@ ifneq (,$(findstring MINGW,$(uname_S)))
836
NO_PREAD = YesPlease
837
NO_OPENSSL = YesPlease
838
NO_CURL = YesPlease
839
+ NO_LIBGEN_H = YesPlease
840
NO_SYMLINK_HEAD = YesPlease
841
NO_IPV6 = YesPlease
842
NO_SETENV = YesPlease
@@ -899,6 +902,11 @@ ifndef CC_LD_DYNPATH
902
endif
903
endif
904
905
+ifdef NO_LIBGEN_H
906
+ COMPAT_CFLAGS += -DNO_LIBGEN_H
907
+ COMPAT_OBJS += compat/basename.o
908
+endif
909
+
910
ifdef NO_CURL
911
BASIC_CFLAGS += -DNO_CURL
912
else
compat/basename.c
new
+15
@@ -0,0 +1,15 @@
1
+#include "../git-compat-util.h"
2
+
3
+/* Adapted from libiberty's basename.c. */
4
+char *gitbasename (char *path)
5
+{
6
+ const char *base;
7
+ /* Skip over the disk name in MSDOS pathnames. */
8
+ if (has_dos_drive_prefix(path))
9
+ path += 2;
10
+ for (base = path; *path; path++) {
11
+ if (is_dir_sep(*path))
12
+ base = path + 1;
13
+ }
14
+ return (char *)base;
15
+}
config.mak.in
+1
@@ -30,6 +30,7 @@ NEEDS_SSL_WITH_CRYPTO=@NEEDS_SSL_WITH_CRYPTO@
30
NO_OPENSSL=@NO_OPENSSL@
31
NO_CURL=@NO_CURL@
32
NO_EXPAT=@NO_EXPAT@
33
+NO_LIBGEN_H=@NO_LIBGEN_H@
34
NEEDS_LIBICONV=@NEEDS_LIBICONV@
35
NEEDS_SOCKET=@NEEDS_SOCKET@
36
NO_SYS_SELECT_H=@NO_SYS_SELECT_H@
configure.ac
+6
@@ -627,6 +627,12 @@ AC_SUBST(SNPRINTF_RETURNS_BOGUS)
627
## (in default C library and libraries checked by AC_CHECK_LIB)
628
AC_MSG_NOTICE([CHECKS for library functions])
629
#
630
+# Define NO_LIBGEN_H if you don't have libgen.h.
631
+AC_CHECK_HEADER([libgen.h],
632
+[NO_LIBGEN_H=],
633
+[NO_LIBGEN_H=YesPlease])
634
+AC_SUBST(NO_LIBGEN_H)
635
+#
636
# Define NO_STRCASESTR if you don't have strcasestr.
637
GIT_CHECK_FUNC(strcasestr,
638
[NO_STRCASESTR=],
git-compat-util.h
+7
@@ -97,6 +97,13 @@
97
#include "compat/mingw.h"
98
#endif /* __MINGW32__ */
99
100
+#ifndef NO_LIBGEN_H
101
+#include <libgen.h>
102
+#else
103
+#define basename gitbasename
104
+extern char *gitbasename(char *);
105
+#endif
106
+
107
#ifndef NO_ICONV
108
#include <iconv.h>
109
#endif