mirror of
https://gitlab.com/sortix/sortix.git
synced 2023-02-13 20:55:38 -05:00
Improve basename(3) and dirname(3).
This commit is contained in:
parent
0ac60d68ea
commit
f13074afd1
2 changed files with 8 additions and 14 deletions
|
@ -1,6 +1,6 @@
|
|||
/*******************************************************************************
|
||||
|
||||
Copyright(C) Jonas 'Sortie' Termansen 2013.
|
||||
Copyright(C) Jonas 'Sortie' Termansen 2013, 2014.
|
||||
|
||||
This file is part of the Sortix C Library.
|
||||
|
||||
|
@ -25,15 +25,12 @@
|
|||
#include <libgen.h>
|
||||
#include <string.h>
|
||||
|
||||
static const char current_directory[2] = ".";
|
||||
|
||||
extern "C" char* basename(char* path)
|
||||
{
|
||||
static char static_stuff[2];
|
||||
if ( !path || !*path )
|
||||
{
|
||||
static_stuff[0] = '.';
|
||||
static_stuff[1] = '\0';
|
||||
return static_stuff;
|
||||
}
|
||||
return (char*) current_directory;
|
||||
size_t path_len = strlen(path);
|
||||
while ( 2 <= path_len && path[path_len-1] == '/' )
|
||||
path[--path_len] = '\0';
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*******************************************************************************
|
||||
|
||||
Copyright(C) Jonas 'Sortie' Termansen 2013.
|
||||
Copyright(C) Jonas 'Sortie' Termansen 2013, 2014.
|
||||
|
||||
This file is part of the Sortix C Library.
|
||||
|
||||
|
@ -25,15 +25,12 @@
|
|||
#include <libgen.h>
|
||||
#include <string.h>
|
||||
|
||||
static const char current_directory[2] = ".";
|
||||
|
||||
extern "C" char* dirname(char* path)
|
||||
{
|
||||
static char static_stuff[2];
|
||||
if ( !path || !*path )
|
||||
{
|
||||
static_stuff[0] = '.';
|
||||
static_stuff[1] = '\0';
|
||||
return static_stuff;
|
||||
}
|
||||
return (char*) current_directory;
|
||||
size_t path_len = strlen(path);
|
||||
while ( 2 <= path_len && path[path_len-1] == '/' )
|
||||
path[--path_len] = '\0';
|
||||
|
|
Loading…
Add table
Reference in a new issue