# HG changeset patch # User Rob Landley # Date 1420064551 21600 # Node ID aafd2f28245aa3186e45447ab770a692b145cf95 # Parent 44e86486a57d758c85e37088047bca9b07c86ce5 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. diff -r 44e86486a57d -r aafd2f28245a lib/portability.c --- a/lib/portability.c Tue Dec 30 14:49:02 2014 -0600 +++ b/lib/portability.c Wed Dec 31 16:22:31 2014 -0600 @@ -6,6 +6,14 @@ #include "toys.h" +#if defined(__GLIBC__) +#include +char *basename(char *path) +{ + return __xpg_basename(path); +} +#endif + #if !defined(__uClinux__) pid_t xfork(void) { diff -r 44e86486a57d -r aafd2f28245a lib/portability.h --- a/lib/portability.h Tue Dec 30 14:49:02 2014 -0600 +++ b/lib/portability.h Wed Dec 31 16:22:31 2014 -0600 @@ -60,6 +60,15 @@ #include 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 diff -r 44e86486a57d -r aafd2f28245a toys.h --- a/toys.h Tue Dec 30 14:49:02 2014 -0600 +++ b/toys.h Wed Dec 31 16:22:31 2014 -0600 @@ -17,7 +17,6 @@ #include #include #include -#include #include #include #include diff -r 44e86486a57d -r aafd2f28245a toys/posix/dirname.c --- a/toys/posix/dirname.c Tue Dec 30 14:49:02 2014 -0600 +++ b/toys/posix/dirname.c Wed Dec 31 16:22:31 2014 -0600 @@ -16,6 +16,7 @@ */ #include "toys.h" +#include void dirname_main(void) {