2009-05-31 12:35:51 +04:00
|
|
|
#include "../git-compat-util.h"
|
|
|
|
|
|
|
|
/* Adapted from libiberty's basename.c. */
|
|
|
|
char *gitbasename (char *path)
|
|
|
|
{
|
|
|
|
const char *base;
|
2016-01-12 10:57:30 +03:00
|
|
|
|
|
|
|
if (path)
|
|
|
|
skip_dos_drive_prefix(&path);
|
|
|
|
|
|
|
|
if (!path || !*path)
|
|
|
|
return ".";
|
|
|
|
|
2009-05-31 12:35:51 +04:00
|
|
|
for (base = path; *path; path++) {
|
2016-01-12 10:57:30 +03:00
|
|
|
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';
|
2009-05-31 12:35:51 +04:00
|
|
|
}
|
|
|
|
return (char *)base;
|
|
|
|
}
|