aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2016-04-08 18:25:59 -0500
committerRob Landley <rob@landley.net>2016-04-08 18:25:59 -0500
commit1c028ca33dc059a9d8f18daafcd77b5950268f41 (patch)
treef1a6ac81fdecd28b72a864d20c5e65f18b302ee3
parent9b93dd397b4a00063073fdbd59b181a508470e70 (diff)
downloadtoybox-1c028ca33dc059a9d8f18daafcd77b5950268f41.tar.gz
Redefining basename_r to mean something random seems popular (bionic and freebsd
both did it) so use getbasename instead.
-rw-r--r--lib/lib.c5
-rw-r--r--lib/lib.h2
-rw-r--r--lib/portability.h10
-rw-r--r--toys/pending/modprobe.c2
-rw-r--r--toys/pending/netstat.c2
5 files changed, 8 insertions, 13 deletions
diff --git a/lib/lib.c b/lib/lib.c
index 3ca7052a..0380c13b 100644
--- a/lib/lib.c
+++ b/lib/lib.c
@@ -919,11 +919,14 @@ void mode_to_string(mode_t mode, char *buf)
*buf = c;
}
-char *basename_r(char *name)
+// basename() can modify its argument or return a pointer to a constant string
+// This just gives after the last '/' or the whole stirng if no /
+char *getbasename(char *name)
{
char *s = strrchr(name, '/');
if (s) return s+1;
+
return name;
}
diff --git a/lib/lib.h b/lib/lib.h
index 52ddc28e..23a3b2b3 100644
--- a/lib/lib.h
+++ b/lib/lib.h
@@ -286,7 +286,7 @@ char *num_to_sig(int sig);
mode_t string_to_mode(char *mode_str, mode_t base);
void mode_to_string(mode_t mode, char *buf);
-char *basename_r(char *name);
+char *getbasename(char *name);
void names_to_pid(char **names, int (*callback)(pid_t pid, char *name));
pid_t xvforkwrap(pid_t pid);
diff --git a/lib/portability.h b/lib/portability.h
index d11cc9c6..fdee5fcf 100644
--- a/lib/portability.h
+++ b/lib/portability.h
@@ -157,19 +157,11 @@ int utimensat(int fd, const char *path, const struct timespec times[2], int flag
#endif // glibc in general
-#if !defined(__GLIBC__) && !defined(__BIONIC__)
+#if !defined(__GLIBC__)
// POSIX basename.
#include <libgen.h>
#endif
-// glibc was handled above; for 32-bit bionic we need to avoid a collision
-// with toybox's basename_r so we can't include <libgen.h> even though that
-// would give us a POSIX basename(3).
-#if defined(__BIONIC__)
-char *basename(char *path);
-char *dirname(char *path);
-#endif
-
// Work out how to do endianness
#ifndef __APPLE__
diff --git a/toys/pending/modprobe.c b/toys/pending/modprobe.c
index 6813dec3..7a35c186 100644
--- a/toys/pending/modprobe.c
+++ b/toys/pending/modprobe.c
@@ -70,7 +70,7 @@ static char *path2mod(char *file, char *mod)
if (!file) return NULL;
if (!mod) mod = xmalloc(MODNAME_LEN);
- from = basename_r(file);
+ from = getbasename(file);
for (i = 0; i < (MODNAME_LEN-1) && from[i] && from[i] != '.'; i++)
mod[i] = (from[i] == '-') ? '_' : from[i];
diff --git a/toys/pending/netstat.c b/toys/pending/netstat.c
index d6acd7a3..02ab4fc2 100644
--- a/toys/pending/netstat.c
+++ b/toys/pending/netstat.c
@@ -440,7 +440,7 @@ static void scan_pid(int pid)
if ((p = strchr(line, ' '))) *p = 0; // "/bin/netstat -ntp" -> "/bin/netstat"
snprintf(TT.current_name, sizeof(TT.current_name), "%d/%s",
- pid, basename_r(line)); // "584/netstat"
+ pid, getbasename(line)); // "584/netstat"
free(line);
fd_dir = xmprintf("/proc/%d/fd", pid);