changeset 1665:5d003cc2fa16

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.
author Rob Landley <rob@landley.net>
date Sun, 18 Jan 2015 13:44:24 -0600
parents 692be264d4f0
children 10922d83392a
files lib/portability.c lib/portability.h toys/posix/dirname.c
diffstat 3 files changed, 8 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/lib/portability.c	Sun Jan 18 13:36:31 2015 -0600
+++ b/lib/portability.c	Sun Jan 18 13:44:24 2015 -0600
@@ -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)
 {
--- a/lib/portability.h	Sun Jan 18 13:36:31 2015 -0600
+++ b/lib/portability.h	Sun Jan 18 13:44:24 2015 -0600
@@ -66,8 +66,12 @@
 // 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 @@
 #ifndef MNT_DETACH
 #define MNT_DETACH 2
 #endif
-#endif
+#endif // Old glibc
 
-#endif
+#endif // glibc in general
 
 #ifndef __GLIBC__
 // POSIX basename.
--- a/toys/posix/dirname.c	Sun Jan 18 13:36:31 2015 -0600
+++ b/toys/posix/dirname.c	Sun Jan 18 13:44:24 2015 -0600
@@ -16,7 +16,6 @@
 */
 
 #include "toys.h"
-#include <libgen.h>
 
 void dirname_main(void)
 {