
According to POSIX, basename("/path/") should return "path", not "path/". Likewise, basename(NULL) and basename("") should both return "." to conform. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
28 lines
463 B
C
28 lines
463 B
C
#include "../git-compat-util.h"
|
|
|
|
/* Adapted from libiberty's basename.c. */
|
|
char *gitbasename (char *path)
|
|
{
|
|
const char *base;
|
|
|
|
if (path)
|
|
skip_dos_drive_prefix(&path);
|
|
|
|
if (!path || !*path)
|
|
return ".";
|
|
|
|
for (base = path; *path; path++) {
|
|
if (!is_dir_sep(*path))
|
|
continue;
|
|
do {
|
|
path++;
|
|
} while (is_dir_sep(*path));
|
|
if (*path)
|
|
base = path;
|
|
else
|
|
while (--path != base && is_dir_sep(*path))
|
|
*path = '\0';
|
|
}
|
|
return (char *)base;
|
|
}
|