aboutsummaryrefslogtreecommitdiff
path: root/compat
diff options
context:
space:
mode:
authorDavid Aguilar <davvid@gmail.com>2009-05-31 01:35:51 -0700
committerJunio C Hamano <gitster@pobox.com>2009-05-31 17:57:59 -0700
commite1c068869216c8c231c1585bbfa9fda42b4756f8 (patch)
tree929b5984b0ce8bfaba925a84ebb5ae04e7559e28 /compat
parent0620b39b3b7b1f27bf863d9591fd8146a9a8931d (diff)
downloadgit-e1c068869216c8c231c1585bbfa9fda42b4756f8.tar.gz
git-e1c068869216c8c231c1585bbfa9fda42b4756f8.tar.xz
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>
Diffstat (limited to 'compat')
-rw-r--r--compat/basename.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/compat/basename.c b/compat/basename.c
new file mode 100644
index 000000000..d8f8a3c6d
--- /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;
+}