diff --git a/src/system/libroot/posix/Jamfile b/src/system/libroot/posix/Jamfile index 6af92bd9fd..ab39d6b896 100644 --- a/src/system/libroot/posix/Jamfile +++ b/src/system/libroot/posix/Jamfile @@ -36,7 +36,6 @@ for architectureObject in [ MultiArchSubDirSetup ] { fcntl.cpp glob.c inttypes.c - libgen.cpp poll.cpp $(PWD_BACKEND) scheduler.cpp diff --git a/src/system/libroot/posix/libgen.cpp b/src/system/libroot/posix/libgen.cpp deleted file mode 100644 index 91fcfada59..0000000000 --- a/src/system/libroot/posix/libgen.cpp +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright 2009, Haiku Inc. All rights reserved. - * Distributed under the terms of the MIT License. - * - * Authors: - * Salvatore Benedetto - */ - -#include -#include - - -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; -} diff --git a/src/system/libroot/posix/musl/misc/Jamfile b/src/system/libroot/posix/musl/misc/Jamfile index afa139f6c3..4b807cefe2 100644 --- a/src/system/libroot/posix/musl/misc/Jamfile +++ b/src/system/libroot/posix/musl/misc/Jamfile @@ -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 diff --git a/src/system/libroot/posix/musl/misc/basename.c b/src/system/libroot/posix/musl/misc/basename.c new file mode 100644 index 0000000000..c87e00cdcd --- /dev/null +++ b/src/system/libroot/posix/musl/misc/basename.c @@ -0,0 +1,12 @@ +#include +#include + +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; +} diff --git a/src/system/libroot/posix/musl/misc/dirname.c b/src/system/libroot/posix/musl/misc/dirname.c new file mode 100644 index 0000000000..dd570883d8 --- /dev/null +++ b/src/system/libroot/posix/musl/misc/dirname.c @@ -0,0 +1,14 @@ +#include +#include + +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; +}