From cf969517dc72faa5247e5a5cc06a6e08f3ccc230 Mon Sep 17 00:00:00 2001 From: Matt Kraai Date: Wed, 5 Sep 2001 19:45:39 +0000 Subject: [PATCH] Backport the rest of dirname(3) interface change. --- busybox/archival/tar.c | 6 ++++-- busybox/libbb/make_directory.c | 18 +++++++++++------- busybox/tar.c | 6 ++++-- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/busybox/archival/tar.c b/busybox/archival/tar.c index cf65798ff..389d7f02e 100644 --- a/busybox/archival/tar.c +++ b/busybox/archival/tar.c @@ -342,9 +342,11 @@ tarExtractRegularFile(TarInfo *header, int extractFlag, int tostdoutFlag) if (extractFlag==TRUE && tostdoutFlag==FALSE) { /* Create the path to the file, just in case it isn't there... * This should not screw up path permissions or anything. */ - char *dir = dirname (header->name); + char *buf, *dir; + buf = xstrdup (header->name); + dir = dirname (buf); make_directory (dir, -1, FILEUTILS_RECUR); - free (dir); + free (buf); if ((outFd=open(header->name, O_CREAT|O_TRUNC|O_WRONLY, header->mode & ~S_IFMT)) < 0) { error_msg(io_error, header->name, strerror(errno)); diff --git a/busybox/libbb/make_directory.c b/busybox/libbb/make_directory.c index 0a9d7b160..a06a410d2 100644 --- a/busybox/libbb/make_directory.c +++ b/busybox/libbb/make_directory.c @@ -49,16 +49,20 @@ int make_directory (char *path, long mode, int flags) struct stat st; if (stat (path, &st) < 0 && errno == ENOENT) { - char *parent = dirname (path); - mode_t mask = umask (0); + int status; + char *buf, *parent; + mode_t mask; + + mask = umask (0); umask (mask); - if (make_directory (parent, (0777 & ~mask) | 0300, - FILEUTILS_RECUR) < 0) - return -1; - free (parent); + buf = xstrdup (path); + parent = dirname (buf); + status = make_directory (parent, (0777 & ~mask) | 0300, + FILEUTILS_RECUR); + free (buf); - if (make_directory (path, mode, 0) < 0) + if (status < 0 || make_directory (path, mode, 0) < 0) return -1; } } diff --git a/busybox/tar.c b/busybox/tar.c index cf65798ff..389d7f02e 100644 --- a/busybox/tar.c +++ b/busybox/tar.c @@ -342,9 +342,11 @@ tarExtractRegularFile(TarInfo *header, int extractFlag, int tostdoutFlag) if (extractFlag==TRUE && tostdoutFlag==FALSE) { /* Create the path to the file, just in case it isn't there... * This should not screw up path permissions or anything. */ - char *dir = dirname (header->name); + char *buf, *dir; + buf = xstrdup (header->name); + dir = dirname (buf); make_directory (dir, -1, FILEUTILS_RECUR); - free (dir); + free (buf); if ((outFd=open(header->name, O_CREAT|O_TRUNC|O_WRONLY, header->mode & ~S_IFMT)) < 0) { error_msg(io_error, header->name, strerror(errno)); -- 2.25.1