Rewrote mkdir (and touched lots of things in the process).
authorMatt Kraai <kraai@debian.org>
Thu, 21 Jun 2001 19:41:37 +0000 (19:41 -0000)
committerMatt Kraai <kraai@debian.org>
Thu, 21 Jun 2001 19:41:37 +0000 (19:41 -0000)
17 files changed:
Makefile
archival/dpkg.c
archival/tar.c
coreutils/dirname.c
coreutils/mkdir.c
dirname.c
dpkg.c
editors/sed.c
include/libbb.h
libbb/create_path.c [deleted file]
libbb/dirname.c [new file with mode: 0644]
libbb/libbb.h
libbb/make_directory.c [new file with mode: 0644]
libbb/strdup_substr.c [new file with mode: 0644]
mkdir.c
sed.c
tar.c

index 03feb6306b044f4b5e5ef5690a0c98fbd962c93b..89d56d50cd61d0a797a39716bd7278186cc43158 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -237,7 +237,7 @@ endif
 LIBBB    = libbb
 LIBBB_LIB = libbb.a
 LIBBB_CSRC= ask_confirmation.c chomp.c concat_path_file.c copy_file.c \
-copy_file_chunk.c create_path.c daemon.c device_open.c error_msg.c \
+copy_file_chunk.c daemon.c device_open.c error_msg.c \
 error_msg_and_die.c fgets_str.c find_mount_point.c find_pid_by_name.c \
 find_root_device.c full_read.c full_write.c get_console.c \
 get_last_path_component.c get_line_from_file.c gz_open.c human_readable.c \
@@ -248,7 +248,8 @@ print_file.c process_escape_sequence.c read_package_field.c recursive_action.c \
 safe_read.c safe_strncpy.c syscalls.c syslog_msg_with_name.c time_string.c \
 trim.c unarchive.c unzip.c vdprintf.c verror_msg.c vperror_msg.c wfopen.c xfuncs.c \
 xgetcwd.c xreadlink.c xregcomp.c interface.c remove_file.c last_char_is.c \
-copyfd.c vherror_msg.c herror_msg.c herror_msg_and_die.c xgethostbyname.c
+copyfd.c vherror_msg.c herror_msg.c herror_msg_and_die.c xgethostbyname.c \
+dirname.c make_directory.c strdup_substr.c
 LIBBB_OBJS=$(patsubst %.c,$(LIBBB)/%.o, $(LIBBB_CSRC))
 LIBBB_CFLAGS = -I$(LIBBB)
 ifneq ($(strip $(BB_SRC_DIR)),)
index 4224672ec2a18051b6ccb2c118c5264779b894db..7dd46be0c9a7234e0a6197b0a0e7e72ada1049e1 100644 (file)
@@ -837,7 +837,7 @@ extern int dpkg_main(int argc, char **argv)
                optind++;
        }
 
-       create_path(infodir, S_IRWXU);
+       make_directory(infodir, S_IRWXU, FILEUTILS_RECUR);
 
        status = status_read();
 
index 55fb12c2ca699fc87fbc72c97844b38779d11179..e68194ff79ef65d12589682c9a8b5c5f7e32bb4f 100644 (file)
@@ -338,7 +338,9 @@ 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. */
-               create_path(header->name, 0777);
+               char *dir = dirname (header->name);
+               make_directory (dir, -1, FILEUTILS_RECUR);
+               free (dir);
                if ((outFd=open(header->name, O_CREAT|O_TRUNC|O_WRONLY, 
                                                header->mode & ~S_IFMT)) < 0) {
                        error_msg(io_error, header->name, strerror(errno)); 
@@ -397,8 +399,7 @@ tarExtractDirectory(TarInfo *header, int extractFlag, int tostdoutFlag)
        if (extractFlag==FALSE || tostdoutFlag==TRUE)
                return( TRUE);
 
-       if (create_path(header->name, header->mode) != TRUE) {
-               perror_msg("%s: Cannot mkdir", header->name); 
+       if (make_directory(header->name, header->mode, FILEUTILS_RECUR) < 0) {
                return( FALSE);
        }
        /* make the final component, just in case it was
index 935a8313c406d2e8ff646940a7c5ed6a2b954166..b534e6950a4345ae467c9279342b6f444b910440 100644 (file)
 
 extern int dirname_main(int argc, char **argv)
 {
-       char* s;
-
        if ((argc < 2) || (**(argv + 1) == '-'))
                show_usage();
        argv++;
 
-       s=*argv+strlen(*argv)-1;
-       while (s > *argv && *s == '/') {
-               *s-- = '\0';
-       }
-       s = strrchr(*argv, '/');
-       if (s != NULL && s == *argv)
-               s[1] = '\0';
-       else if (s != NULL)
-               *s = '\0';
-       puts(s ? *argv : ".");
+       puts (dirname (argv[0]));
+
        return EXIT_SUCCESS;
 }
index d78f57e2bb4786288d729528189416d62d27ea86..03c49f0983cfa96486cc3d09c5c35c3619a112a1 100644 (file)
@@ -2,8 +2,7 @@
 /*
  * Mini mkdir implementation for busybox
  *
- * Copyright (C) 1999,2000,2001 by Lineo, inc.
- * Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
+ * Copyright (C) 2001 Matt Kraai <kraai@alumni.carnegiemellon.edu>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  *
  */
 
-#include <stdio.h>
 #include <errno.h>
-#include <string.h>
+#include <getopt.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include <unistd.h>
 #include <stdlib.h>
-#include "busybox.h"
-
-
-static int parentFlag = FALSE;
-static mode_t mode = 0777;
+#include <string.h>
 
+#include "busybox.h"
 
-extern int mkdir_main(int argc, char **argv)
+extern int mkdir_main (int argc, char **argv)
 {
-       int i = FALSE;
+       mode_t mode = -1;
+       int flags = 0;
+       int status = 0;
+       int i, opt;
 
-       argc--;
-       argv++;
-
-       /* Parse any options */
-       while (argc > 0 && **argv == '-') {
-               while (i == FALSE && *++(*argv)) {
-                       switch (**argv) {
-                       case 'm':
-                               if (--argc == 0)
-                                       show_usage();
-                               /* Find the specified modes */
-                               mode = 0;
-                               if (parse_mode(*(++argv), &mode) == FALSE) {
-                                       error_msg_and_die("Unknown mode: %s", *argv);
-                               }
-                               /* Set the umask for this process so it doesn't 
-                                * screw up whatever the user just entered. */
-                               umask(0);
-                               i = TRUE;
-                               break;
-                       case 'p':
-                               parentFlag = TRUE;
-                               break;
-                       default:
-                               show_usage();
-                       }
+       while ((opt = getopt (argc, argv, "m:p")) != -1) {
+               switch (opt) {
+               case 'm':
+                       mode = 0777;
+                       if (!parse_mode (optarg, &mode))
+                               error_msg_and_die ("invalid mode `%s'", optarg);
+                       break;
+               case 'p':
+                       flags |= FILEUTILS_RECUR;
+                       break;
+               default:
+                       show_usage ();
                }
-               argc--;
-               argv++;
        }
 
-       if (argc < 1) {
-               show_usage();
-       }
+       if (optind == argc)
+               show_usage ();
 
-       while (argc > 0) {
-               int status;
-               struct stat statBuf;
-               char buf[BUFSIZ + 1];
+       for (i = optind; i < argc; i++)
+               if (make_directory (argv[i], mode, flags) < 0)
+                       status = 1;
 
-               if (strlen(*argv) > BUFSIZ - 1) {
-                       error_msg_and_die(name_too_long);
-               }
-               strcpy(buf, *argv);
-               status = stat(buf, &statBuf);
-               if (parentFlag == FALSE && status != -1 && errno != ENOENT) {
-                       error_msg_and_die("%s: File exists", buf);
-               }
-               if (parentFlag == TRUE) {
-                       strcat(buf, "/");
-                       create_path(buf, mode);
-               } else {
-                       if (mkdir(buf, mode) != 0 && parentFlag == FALSE) {
-                               perror_msg_and_die(buf);
-                       }
-               }
-               argc--;
-               argv++;
-       }
-       return EXIT_SUCCESS;
+       return status;
 }
index 935a8313c406d2e8ff646940a7c5ed6a2b954166..b534e6950a4345ae467c9279342b6f444b910440 100644 (file)
--- a/dirname.c
+++ b/dirname.c
 
 extern int dirname_main(int argc, char **argv)
 {
-       char* s;
-
        if ((argc < 2) || (**(argv + 1) == '-'))
                show_usage();
        argv++;
 
-       s=*argv+strlen(*argv)-1;
-       while (s > *argv && *s == '/') {
-               *s-- = '\0';
-       }
-       s = strrchr(*argv, '/');
-       if (s != NULL && s == *argv)
-               s[1] = '\0';
-       else if (s != NULL)
-               *s = '\0';
-       puts(s ? *argv : ".");
+       puts (dirname (argv[0]));
+
        return EXIT_SUCCESS;
 }
diff --git a/dpkg.c b/dpkg.c
index 4224672ec2a18051b6ccb2c118c5264779b894db..7dd46be0c9a7234e0a6197b0a0e7e72ada1049e1 100644 (file)
--- a/dpkg.c
+++ b/dpkg.c
@@ -837,7 +837,7 @@ extern int dpkg_main(int argc, char **argv)
                optind++;
        }
 
-       create_path(infodir, S_IRWXU);
+       make_directory(infodir, S_IRWXU, FILEUTILS_RECUR);
 
        status = status_read();
 
index e7208b0b550dfbcc93bce36e512c8e1bd2b4ec75..89b16682fd30f58fc3948388869900d461003c54 100644 (file)
@@ -195,15 +195,6 @@ static int get_address(struct sed_cmd *sed_cmd, const char *str, int *linenum, r
        return idx;
 }
 
-static char *strdup_substr(const char *str, int start, int end)
-{
-       int size = end - start + 1;
-       char *newstr = xmalloc(size);
-       memcpy(newstr, str+start, size-1);
-       newstr[size-1] = '\0';
-       return newstr;
-}
-
 static int parse_subst_cmd(struct sed_cmd *sed_cmd, const char *substr)
 {
        int oldidx, cflags = REG_NEWLINE;
index e42ca9f2bf934f919e95d6fc2e1265791cb7b8db..c83cb7e7c0051fef183603f651a3e7d5aab3a3ec 100644 (file)
@@ -243,6 +243,10 @@ extern FILE *gz_open(FILE *compressed_file, int *pid);
 
 extern struct hostent *xgethostbyname(const char *name);
 
+char *dirname (const char *path);
+char *strdup_substr (const char *s, int start, int end);
+int make_directory (char *path, mode_t mode, int flags);
+
 #define CT_AUTO        0
 #define CT_UNIX2DOS    1
 #define CT_DOS2UNIX    2
diff --git a/libbb/create_path.c b/libbb/create_path.c
deleted file mode 100644 (file)
index 328afc3..0000000
+++ /dev/null
@@ -1,71 +0,0 @@
-/* vi: set sw=4 ts=4: */
-/*
- * Utility routines.
- *
- * Copyright (C) tons of folks.  Tracking down who wrote what
- * isn't something I'm going to worry about...  If you wrote something
- * here, please feel free to acknowledge your work.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * Based in part on code from sash, Copyright (c) 1999 by David I. Bell 
- * Permission has been granted to redistribute this code under the GPL.
- *
- */
-
-#include <stdio.h>
-#include <errno.h>
-#include <string.h>
-#include "libbb.h"
-
-/*
- * Attempt to create the directories along the specified path, except for
- * the final component.  The mode is given for the final directory only,
- * while all previous ones get default protections.  Errors are not reported
- * here, as failures to restore files can be reported later.
- */
-extern int create_path(const char *name, int mode)
-{
-       char *cp;
-       char *cpOld;
-       char buf[BUFSIZ + 1];
-       int retVal = 0;
-
-       strcpy(buf, name);
-       for (cp = buf; *cp == '/'; cp++);
-       cp = strchr(cp, '/');
-       while (cp) {
-               cpOld = cp;
-               cp = strchr(cp + 1, '/');
-               *cpOld = '\0';
-               retVal = mkdir(buf, cp ? 0777 : mode);
-               if (retVal != 0 && errno != EEXIST) {
-                       perror_msg("%s", buf);
-                       return FALSE;
-               }
-               *cpOld = '/';
-       }
-       return TRUE;
-}
-
-
-/* END CODE */
-/*
-Local Variables:
-c-file-style: "linux"
-c-basic-offset: 4
-tab-width: 4
-End:
-*/
diff --git a/libbb/dirname.c b/libbb/dirname.c
new file mode 100644 (file)
index 0000000..2e89fc1
--- /dev/null
@@ -0,0 +1,48 @@
+/* vi: set sw=4 ts=4: */
+/*
+ * Mini dirname function.
+ *
+ * Copyright (C) 2001  Matt Kraai.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include "libbb.h"
+
+/* Return a string on the heap containing the directory component of PATH.  */
+
+char *dirname(const char *path)
+{
+       const char *s;
+
+       /* Go to the end of the string.  */
+       s = path + strlen(path) - 1;
+
+       /* Strip off trailing /s (unless it is also the leading /).  */
+       while (path < s && s[0] == '/')
+               s--;
+
+       /* Strip the last component.  */
+       while (path <= s && s[0] != '/')
+               s--;
+
+       while (path < s && s[0] == '/')
+               s--;
+
+       if (s < path)
+               return xstrdup (".");
+       else
+               return strdup_substr (path, 0, s - path + 1);
+}
index e42ca9f2bf934f919e95d6fc2e1265791cb7b8db..c83cb7e7c0051fef183603f651a3e7d5aab3a3ec 100644 (file)
@@ -243,6 +243,10 @@ extern FILE *gz_open(FILE *compressed_file, int *pid);
 
 extern struct hostent *xgethostbyname(const char *name);
 
+char *dirname (const char *path);
+char *strdup_substr (const char *s, int start, int end);
+int make_directory (char *path, mode_t mode, int flags);
+
 #define CT_AUTO        0
 #define CT_UNIX2DOS    1
 #define CT_DOS2UNIX    2
diff --git a/libbb/make_directory.c b/libbb/make_directory.c
new file mode 100644 (file)
index 0000000..e2e28a8
--- /dev/null
@@ -0,0 +1,66 @@
+/* vi: set sw=4 ts=4: */
+/*
+ * Mini make_directory implementation for busybox
+ *
+ * Copyright (C) 2001  Matt Kraai.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+#include <errno.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#include "libbb.h"
+
+/* Create the directory PATH with mode MODE, or the default if MODE is -1.
+ * Also create parent directories as necessary if flags contains
+ * FILEUTILS_RECUR.  */
+
+int make_directory (char *path, mode_t mode, int flags)
+{
+       if (!(flags & FILEUTILS_RECUR)) {
+               if (mkdir (path, 0777) < 0) {
+                       perror_msg ("Cannot create directory `%s'", path);
+                       return -1;
+               }
+
+               if (mode != -1 && chmod (path, mode) < 0) {
+                       perror_msg ("Cannot set permissions of directory `%s'", path);
+                       return -1;
+               }
+       } else {
+               struct stat st;
+
+               if (stat (path, &st) < 0 && errno == ENOENT) {
+                       char *parent = dirname (path);
+                       mode_t mask = umask (0);
+                       umask (mask);
+
+                       if (make_directory (parent, (0777 & ~mask) | 0300,
+                                               FILEUTILS_RECUR) < 0)
+                               return -1;
+                       free (parent);
+
+                       if (make_directory (path, mode, 0) < 0)
+                               return -1;
+               }
+       }
+
+       return 0;
+}
diff --git a/libbb/strdup_substr.c b/libbb/strdup_substr.c
new file mode 100644 (file)
index 0000000..4542d5f
--- /dev/null
@@ -0,0 +1,32 @@
+/* vi: set sw=4 ts=4: */
+/*
+ * Mini strdup_substr function.
+ *
+ * Copyright (C) 2001  Mark Whitley.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+/* Return a substring of STR, starting at index START and ending at END,
+ * allocated on the heap.  */
+
+char *strdup_substr(const char *str, int start, int end)
+{
+       int size = end - start + 1;
+       char *newstr = xmalloc(size);
+       memcpy(newstr, str+start, size-1);
+       newstr[size-1] = '\0';
+       return newstr;
+}
diff --git a/mkdir.c b/mkdir.c
index d78f57e2bb4786288d729528189416d62d27ea86..03c49f0983cfa96486cc3d09c5c35c3619a112a1 100644 (file)
--- a/mkdir.c
+++ b/mkdir.c
@@ -2,8 +2,7 @@
 /*
  * Mini mkdir implementation for busybox
  *
- * Copyright (C) 1999,2000,2001 by Lineo, inc.
- * Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
+ * Copyright (C) 2001 Matt Kraai <kraai@alumni.carnegiemellon.edu>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  *
  */
 
-#include <stdio.h>
 #include <errno.h>
-#include <string.h>
+#include <getopt.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include <unistd.h>
 #include <stdlib.h>
-#include "busybox.h"
-
-
-static int parentFlag = FALSE;
-static mode_t mode = 0777;
+#include <string.h>
 
+#include "busybox.h"
 
-extern int mkdir_main(int argc, char **argv)
+extern int mkdir_main (int argc, char **argv)
 {
-       int i = FALSE;
+       mode_t mode = -1;
+       int flags = 0;
+       int status = 0;
+       int i, opt;
 
-       argc--;
-       argv++;
-
-       /* Parse any options */
-       while (argc > 0 && **argv == '-') {
-               while (i == FALSE && *++(*argv)) {
-                       switch (**argv) {
-                       case 'm':
-                               if (--argc == 0)
-                                       show_usage();
-                               /* Find the specified modes */
-                               mode = 0;
-                               if (parse_mode(*(++argv), &mode) == FALSE) {
-                                       error_msg_and_die("Unknown mode: %s", *argv);
-                               }
-                               /* Set the umask for this process so it doesn't 
-                                * screw up whatever the user just entered. */
-                               umask(0);
-                               i = TRUE;
-                               break;
-                       case 'p':
-                               parentFlag = TRUE;
-                               break;
-                       default:
-                               show_usage();
-                       }
+       while ((opt = getopt (argc, argv, "m:p")) != -1) {
+               switch (opt) {
+               case 'm':
+                       mode = 0777;
+                       if (!parse_mode (optarg, &mode))
+                               error_msg_and_die ("invalid mode `%s'", optarg);
+                       break;
+               case 'p':
+                       flags |= FILEUTILS_RECUR;
+                       break;
+               default:
+                       show_usage ();
                }
-               argc--;
-               argv++;
        }
 
-       if (argc < 1) {
-               show_usage();
-       }
+       if (optind == argc)
+               show_usage ();
 
-       while (argc > 0) {
-               int status;
-               struct stat statBuf;
-               char buf[BUFSIZ + 1];
+       for (i = optind; i < argc; i++)
+               if (make_directory (argv[i], mode, flags) < 0)
+                       status = 1;
 
-               if (strlen(*argv) > BUFSIZ - 1) {
-                       error_msg_and_die(name_too_long);
-               }
-               strcpy(buf, *argv);
-               status = stat(buf, &statBuf);
-               if (parentFlag == FALSE && status != -1 && errno != ENOENT) {
-                       error_msg_and_die("%s: File exists", buf);
-               }
-               if (parentFlag == TRUE) {
-                       strcat(buf, "/");
-                       create_path(buf, mode);
-               } else {
-                       if (mkdir(buf, mode) != 0 && parentFlag == FALSE) {
-                               perror_msg_and_die(buf);
-                       }
-               }
-               argc--;
-               argv++;
-       }
-       return EXIT_SUCCESS;
+       return status;
 }
diff --git a/sed.c b/sed.c
index e7208b0b550dfbcc93bce36e512c8e1bd2b4ec75..89b16682fd30f58fc3948388869900d461003c54 100644 (file)
--- a/sed.c
+++ b/sed.c
@@ -195,15 +195,6 @@ static int get_address(struct sed_cmd *sed_cmd, const char *str, int *linenum, r
        return idx;
 }
 
-static char *strdup_substr(const char *str, int start, int end)
-{
-       int size = end - start + 1;
-       char *newstr = xmalloc(size);
-       memcpy(newstr, str+start, size-1);
-       newstr[size-1] = '\0';
-       return newstr;
-}
-
 static int parse_subst_cmd(struct sed_cmd *sed_cmd, const char *substr)
 {
        int oldidx, cflags = REG_NEWLINE;
diff --git a/tar.c b/tar.c
index 55fb12c2ca699fc87fbc72c97844b38779d11179..e68194ff79ef65d12589682c9a8b5c5f7e32bb4f 100644 (file)
--- a/tar.c
+++ b/tar.c
@@ -338,7 +338,9 @@ 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. */
-               create_path(header->name, 0777);
+               char *dir = dirname (header->name);
+               make_directory (dir, -1, FILEUTILS_RECUR);
+               free (dir);
                if ((outFd=open(header->name, O_CREAT|O_TRUNC|O_WRONLY, 
                                                header->mode & ~S_IFMT)) < 0) {
                        error_msg(io_error, header->name, strerror(errno)); 
@@ -397,8 +399,7 @@ tarExtractDirectory(TarInfo *header, int extractFlag, int tostdoutFlag)
        if (extractFlag==FALSE || tostdoutFlag==TRUE)
                return( TRUE);
 
-       if (create_path(header->name, header->mode) != TRUE) {
-               perror_msg("%s: Cannot mkdir", header->name); 
+       if (make_directory(header->name, header->mode, FILEUTILS_RECUR) < 0) {
                return( FALSE);
        }
        /* make the final component, just in case it was