aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2014-12-31 16:22:31 -0600
committerRob Landley <rob@landley.net>2014-12-31 16:22:31 -0600
commitde699accf6804e8b1d8042b46c85500ee8c672c6 (patch)
tree7b12adea478bcfd9355a4fda982d74c40810f42b
parent774c599c7979392f4ec95e9b48ac25f0353c0c47 (diff)
downloadtoybox-de699accf6804e8b1d8042b46c85500ee8c672c6.tar.gz
When you include the posix header libgen.h, glibc #defines basename to some random other symbol name (because gnu) and this screws up nontrivial macro expansions of NEWTOY(basename), so work around it in portability.h.
-rw-r--r--lib/portability.c8
-rw-r--r--lib/portability.h9
-rw-r--r--toys.h1
-rw-r--r--toys/posix/dirname.c1
4 files changed, 18 insertions, 1 deletions
diff --git a/lib/portability.c b/lib/portability.c
index 7d6d85f3..4fd1e224 100644
--- a/lib/portability.c
+++ b/lib/portability.c
@@ -6,6 +6,14 @@
#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 1464c656..8bbbdb25 100644
--- a/lib/portability.h
+++ b/lib/portability.h
@@ -60,6 +60,15 @@ int wcwidth(wchar_t wc);
#include <time.h>
char *strptime(const char *buf, const char *format, struct tm *tm);
+// They didn't like posix basename so they defined another function with the
+// same name and if you include libgen.h it #defines basename to something
+// else (where they implemented the real basename), and that define breaks
+// 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);
+
// uClibc pretends to be glibc and copied a lot of its bugs, but has a few more
#if defined(__UCLIBC__)
#include <unistd.h>
diff --git a/toys.h b/toys.h
index 6b5f87aa..3b508497 100644
--- a/toys.h
+++ b/toys.h
@@ -17,7 +17,6 @@
#include <grp.h>
#include <inttypes.h>
#include <limits.h>
-#include <libgen.h>
#include <math.h>
#include <pwd.h>
#include <regex.h>
diff --git a/toys/posix/dirname.c b/toys/posix/dirname.c
index 06470ad8..7f51e9f0 100644
--- a/toys/posix/dirname.c
+++ b/toys/posix/dirname.c
@@ -16,6 +16,7 @@ config DIRNAME
*/
#include "toys.h"
+#include <libgen.h>
void dirname_main(void)
{