Canonicalize dirname(3) behavior.
diff --git a/libbb/make_directory.c b/libbb/make_directory.c
index 7b7fde9..a06a410 100644
--- a/libbb/make_directory.c
+++ b/libbb/make_directory.c
@@ -50,13 +50,17 @@
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;