libroot: Replace dirname, basename with musl versions.
From latest musl release (1.2.5). Change-Id: I6850b6fc9f05a46348a6d858bc58d66e34d0a172 Reviewed-on: https://review.haiku-os.org/c/haiku/+/9059 Reviewed-by: waddlesplash <[email protected]>
This commit is contained in:
committed by
waddlesplash
parent
4b099fb795
commit
45d0d854ee
@@ -36,7 +36,6 @@ for architectureObject in [ MultiArchSubDirSetup ] {
|
||||
fcntl.cpp
|
||||
glob.c
|
||||
inttypes.c
|
||||
libgen.cpp
|
||||
poll.cpp
|
||||
$(PWD_BACKEND)
|
||||
scheduler.cpp
|
||||
|
||||
@@ -1,61 +0,0 @@
|
||||
/*
|
||||
* Copyright 2009, Haiku Inc. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Salvatore Benedetto <[email protected]>
|
||||
*/
|
||||
|
||||
#include <libgen.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
char*
|
||||
basename(char *filepath)
|
||||
{
|
||||
if (filepath == NULL || filepath[0] == '\0')
|
||||
return (char *)".";
|
||||
|
||||
size_t length = strlen(filepath);
|
||||
/* Remove trailing slashes if any */
|
||||
while (filepath[--length] == '/' && length)
|
||||
filepath[length] = '\0';
|
||||
|
||||
char *last = strrchr(filepath, '/');
|
||||
/* If no slash were found return the whole string */
|
||||
if (last == NULL)
|
||||
return filepath;
|
||||
|
||||
/* If the next char is the end it means we got only "/"
|
||||
* and we don't have to truncate */
|
||||
if (*(last + 1) != '\0')
|
||||
++last;
|
||||
|
||||
return last;
|
||||
}
|
||||
|
||||
|
||||
char*
|
||||
dirname(char *filepath)
|
||||
{
|
||||
if (filepath == NULL || filepath[0] == '\0')
|
||||
return (char *)".";
|
||||
|
||||
size_t length = strlen(filepath);
|
||||
/* Remove trailing slashes if any */
|
||||
while (filepath[--length] == '/' && length)
|
||||
filepath[length] = '\0';
|
||||
|
||||
char *last = strrchr(filepath, '/');
|
||||
/* If no slash were found return a dot */
|
||||
if (last == NULL)
|
||||
return (char *)".";
|
||||
|
||||
/* In case we got just "/" don't truncate it */
|
||||
if (last == filepath)
|
||||
last++;
|
||||
|
||||
*last = '\0';
|
||||
|
||||
return filepath;
|
||||
}
|
||||
@@ -11,6 +11,8 @@ for architectureObject in [ MultiArchSubDirSetup ] {
|
||||
|
||||
MergeObject <$(architecture)>posix_musl_misc.o :
|
||||
a64l.c
|
||||
basename.c
|
||||
dirname.c
|
||||
ffs.c
|
||||
ftw.c
|
||||
getsubopt.c
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
#include <string.h>
|
||||
#include <libgen.h>
|
||||
|
||||
char *basename(char *s)
|
||||
{
|
||||
size_t i;
|
||||
if (!s || !*s) return ".";
|
||||
i = strlen(s)-1;
|
||||
for (; i&&s[i]=='/'; i--) s[i] = 0;
|
||||
for (; i&&s[i-1]!='/'; i--);
|
||||
return s+i;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
#include <string.h>
|
||||
#include <libgen.h>
|
||||
|
||||
char *dirname(char *s)
|
||||
{
|
||||
size_t i;
|
||||
if (!s || !*s) return ".";
|
||||
i = strlen(s)-1;
|
||||
for (; s[i]=='/'; i--) if (!i) return "/";
|
||||
for (; s[i]!='/'; i--) if (!i) return ".";
|
||||
for (; s[i]=='/'; i--) if (!i) return "/";
|
||||
s[i+1] = 0;
|
||||
return s;
|
||||
}
|
||||
Reference in New Issue
Block a user