mirror of
https://gitlab.com/sortix/sortix.git
synced 2023-02-13 20:55:38 -05:00
Fix basename(3) and dirname(3) returning incorrect strings.
This commit is contained in:
parent
2e855f4095
commit
00a3579940
2 changed files with 9 additions and 5 deletions
|
@ -36,7 +36,7 @@ extern "C" char* basename(char* path)
|
|||
path[--path_len] = '\0';
|
||||
if ( strcmp(path, "/") == 0 )
|
||||
return path;
|
||||
char* last_slash = strchr(path, '/');
|
||||
char* last_slash = strrchr(path, '/');
|
||||
if ( !last_slash )
|
||||
return path;
|
||||
return last_slash + 1;
|
||||
|
|
|
@ -36,9 +36,13 @@ extern "C" char* dirname(char* path)
|
|||
path[--path_len] = '\0';
|
||||
if ( strcmp(path, "/") == 0 )
|
||||
return path;
|
||||
char* last_slash = strchr(path, '/');
|
||||
if ( !last_slash )
|
||||
return dirname(NULL);
|
||||
*last_slash = '\0';
|
||||
if ( !strchr(path, '/') )
|
||||
return (char*) current_directory;
|
||||
while ( 1 <= path_len && path[path_len-1] != '/' )
|
||||
path[--path_len] = '\0';
|
||||
while ( 1 <= path_len && path[path_len-1] == '/' )
|
||||
path[--path_len] = '\0';
|
||||
if ( !path[0] )
|
||||
strcpy(path, "/");
|
||||
return path;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue