|
|
@@ -177,8 +177,8 @@ void filename(const char* path, char* str, size_t len)
|
|
|
|
|
|
/// Returns the basename of the path.
|
|
|
/// @note
|
|
|
-/// e.g. "/home/babbeo/texture.tga" -> "texture"
|
|
|
-/// e.g. "/home/babbeo" -> "babbeo"
|
|
|
+/// e.g. "/home/project/texture.tga" -> "texture"
|
|
|
+/// e.g. "/home/project" -> "project"
|
|
|
/// e.g. "/" -> ""
|
|
|
void basename(const char* path, char* str, size_t len)
|
|
|
{
|
|
|
@@ -189,17 +189,11 @@ void basename(const char* path, char* str, size_t len)
|
|
|
|
|
|
int32_t last_separator = string::find_last(path, '/');
|
|
|
int32_t last_dot = string::find_last(path, '.');
|
|
|
-
|
|
|
- printf("path-len = %d\n", path_len);
|
|
|
- printf("last-separator = %d\n", last_separator);
|
|
|
- printf("last-dot = %d\n", last_dot);
|
|
|
|
|
|
if (last_separator != -1 && last_dot != -1)
|
|
|
{
|
|
|
size_t basename_length = path_len - (last_separator + (path_len - last_dot)) - 1;
|
|
|
|
|
|
- printf("basename-length = %d\n", basename_length);
|
|
|
-
|
|
|
size_t final_len = (len >= (size_t)(basename_length)) ? basename_length : len;
|
|
|
|
|
|
string::strncpy(str, path + last_separator + 1, final_len);
|