aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2015-01-18 13:44:24 -0600
committerRob Landley <rob@landley.net>2015-01-18 13:44:24 -0600
commit468f155ecefec275e6d2299470d35bd912f69a94 (patch)
tree8d84fadd049c0d1475946706f64b9c7f19037a04
parente910826c812fcde8d122990a1e43e17f46b6d03f (diff)
downloadtoybox-468f155ecefec275e6d2299470d35bd912f69a94.tar.gz
Lift the basename/libgen.h shenanigans back out of portability.c and make it a static inline in portability.h, and prototype dirname() while we're at it.
-rw-r--r--lib/portability.c8
-rw-r--r--lib/portability.h12
-rw-r--r--toys/posix/dirname.c1
3 files changed, 8 insertions, 13 deletions
diff --git a/lib/portability.c b/lib/portability.c
index 4fd1e224..7d6d85f3 100644
--- a/lib/portability.c
+++ b/lib/portability.c
@@ -6,14 +6,6 @@
#include "toys.h"
-#if defined(__GLIBC__)
-#include <libgen.h>
-char *basename(char *path)
-{
- return __xpg_basename(path);
-}
-#endif
-
#if !defined(__uClinux__)
pid_t xfork(void)
{
diff --git a/lib/portability.h b/lib/portability.h
index bb1f5aee..143d10f6 100644
--- a/lib/portability.h
+++ b/lib/portability.h
@@ -66,8 +66,12 @@ char *strptime(const char *buf, const char *format, struct tm *tm);
// the table entry for the basename command. They didn't make a new function
// with a different name for their new behavior because gnu.
//
-// Implement our own in portability.c and don't use their broken header.
-char *basename(char *path);
+// Solution: don't use their broken header, provide an inline to redirect the
+// correct name to the broken name.
+
+char *dirname(char *path);
+char *__xpg_basename (char *path);
+static inline char *basename(char *path) { return __xpg_basename(path); }
// uClibc pretends to be glibc and copied a lot of its bugs, but has a few more
#if defined(__UCLIBC__)
@@ -137,9 +141,9 @@ int utimensat(int fd, const char *path, const struct timespec times[2], int flag
#ifndef MNT_DETACH
#define MNT_DETACH 2
#endif
-#endif
+#endif // Old glibc
-#endif
+#endif // glibc in general
#ifndef __GLIBC__
// POSIX basename.
diff --git a/toys/posix/dirname.c b/toys/posix/dirname.c
index 7f51e9f0..06470ad8 100644
--- a/toys/posix/dirname.c
+++ b/toys/posix/dirname.c
@@ -16,7 +16,6 @@ config DIRNAME
*/
#include "toys.h"
-#include <libgen.h>
void dirname_main(void)
{