diff options
author | David Aguilar <davvid@gmail.com> | 2009-05-31 12:35:51 +0400 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2009-06-01 04:57:59 +0400 |
commit | e1c068869216c8c231c1585bbfa9fda42b4756f8 (patch) | |
tree | 929b5984b0ce8bfaba925a84ebb5ae04e7559e28 /compat/basename.c | |
parent | 0620b39b3b7b1f27bf863d9591fd8146a9a8931d (diff) |
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.c | 15 |
1 files changed, 15 insertions, 0 deletions
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; +} |