Improve basename(3) and dirname(3).

This commit is contained in:
Jonas 'Sortie' Termansen 2014-01-08 23:16:04 +01:00
parent 0ac60d68ea
commit f13074afd1
2 changed files with 8 additions and 14 deletions

View File

@ -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';

View File

@ -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';