aboutsummaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
authorMatt Kraai <kraai@debian.org>2001-08-24 19:51:54 +0000
committerMatt Kraai <kraai@debian.org>2001-08-24 19:51:54 +0000
commitac20ce1924a0eb563acfda6533a80701cd611bfa (patch)
tree5209668fde99a5caa4ed41d8d61c73770fcae646 /libbb
parent2a953aed3831f8705444e720783ad4781904a625 (diff)
downloadbusybox-ac20ce1924a0eb563acfda6533a80701cd611bfa.tar.gz
Canonicalize dirname(3) behavior.
Diffstat (limited to 'libbb')
-rw-r--r--libbb/dirname.c10
-rw-r--r--libbb/make_directory.c10
-rw-r--r--libbb/unarchive.c6
3 files changed, 17 insertions, 9 deletions
diff --git a/libbb/dirname.c b/libbb/dirname.c
index 5f839945d..87db1f24f 100644
--- a/libbb/dirname.c
+++ b/libbb/dirname.c
@@ -22,7 +22,8 @@
#include <string.h>
#include "libbb.h"
-/* Return a string on the heap containing the directory component of PATH. */
+/* Return a string containing the path name of the parent
+ * directory of PATH. */
char *dirname(const char *path)
{
@@ -43,7 +44,8 @@ char *dirname(const char *path)
s--;
if (s < path)
- return xstrdup (".");
- else
- return xstrndup (path, s - path + 1);
+ return ".";
+
+ s[1] = '\0';
+ return path;
}
diff --git a/libbb/make_directory.c b/libbb/make_directory.c
index 7b7fde911..a06a410d2 100644
--- a/libbb/make_directory.c
+++ b/libbb/make_directory.c
@@ -50,13 +50,17 @@ int make_directory (char *path, long mode, int flags)
if (stat (path, &st) < 0 && errno == ENOENT) {
int status;
- char *parent = dirname (path);
- mode_t mask = umask (0);
+ char *buf, *parent;
+ mode_t mask;
+
+ mask = umask (0);
umask (mask);
+ buf = xstrdup (path);
+ parent = dirname (buf);
status = make_directory (parent, (0777 & ~mask) | 0300,
FILEUTILS_RECUR);
- free (parent);
+ free (buf);
if (status < 0 || make_directory (path, mode, 0) < 0)
return -1;
diff --git a/libbb/unarchive.c b/libbb/unarchive.c
index 0d414a3a8..2d171b4ce 100644
--- a/libbb/unarchive.c
+++ b/libbb/unarchive.c
@@ -127,13 +127,15 @@ char *extract_archive(FILE *src_stream, FILE *out_stream, const file_header_t *f
}
}
if (function & extract_create_leading_dirs) { /* Create leading directories with default umask */
- char *parent = dirname(full_name);
+ char *buf, *parent;
+ buf = xstrdup(full_name);
+ parent = dirname(full_name);
if (make_directory (parent, -1, FILEUTILS_RECUR) != 0) {
if ((function & extract_quiet) != extract_quiet) {
error_msg("couldn't create leading directories");
}
}
- free (parent);
+ free (buf);
}
switch(file_entry->mode & S_IFMT) {
case S_IFREG: