Alfred Perlstein wrote:

[ mkdir ]

> I'll commit the patch shortly.

Here's a better patch, it checks for multiple slashes, so mkdir
/tmp/aa///bb//// will give:

mkdir: /tmp/aa: No such file or directory

Also, renamed the function to dirname as it does the same as dirname(1).

Regards,

Wouter
diff -ruN /usr/src/bin/mkdir.orig/mkdir.c /usr/src/bin/mkdir/mkdir.c
--- /usr/src/bin/mkdir.orig/mkdir.c     Sat Sep  4 05:19:38 1999
+++ /usr/src/bin/mkdir/mkdir.c  Sat Jan 13 10:45:07 2001
@@ -58,6 +58,8 @@
 
 int    build __P((char *, mode_t));
 void   usage __P((void));
+char   *dirname __P((char *));
+
 
 int vflag;
 
@@ -108,7 +110,10 @@
                        if (build(*argv, omode))
                                success = 0;
                } else if (mkdir(*argv, omode) < 0) {
-                       warn("%s", *argv);
+                       if (errno == ENOTDIR || errno == ENOENT)
+                               warn("%s", dirname(*argv));
+                       else
+                               warn("%s", *argv);
                        success = 0;
                } else if (vflag)
                        (void)printf("%s\n", *argv);
@@ -129,6 +134,22 @@
        }
        exit(exitval);
 }
+
+
+char *dirname(char *path) {
+       char *slash;
+
+       while (path[ strlen(path)-1 ] == '/') path[ strlen(path)-1 ] = 0;
+
+       slash = strrchr(path, '/');
+       if (slash) {
+               *slash = 0;
+               while (path[ strlen(path)-1 ] == '/') path[ strlen(path)-1 ] = 0;
+       }
+
+       return path;
+}
+
 
 int
 build(path, omode)

Reply via email to