summaryrefslogtreecommitdiff
path: root/compat/basename.c
diff options
context:
space:
mode:
authorDavid Aguilar <davvid@gmail.com>2009-05-31 08:35:51 (GMT)
committerJunio C Hamano <gitster@pobox.com>2009-06-01 00:57:59 (GMT)
commite1c068869216c8c231c1585bbfa9fda42b4756f8 (patch)
tree929b5984b0ce8bfaba925a84ebb5ae04e7559e28 /compat/basename.c
parent0620b39b3b7b1f27bf863d9591fd8146a9a8931d (diff)
downloadgit-e1c068869216c8c231c1585bbfa9fda42b4756f8.zip
git-e1c068869216c8c231c1585bbfa9fda42b4756f8.tar.gz
git-e1c068869216c8c231c1585bbfa9fda42b4756f8.tar.bz2
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/basename.c')
-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 0000000..d8f8a3c
--- /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;
+}