From: Thomas Cort Date: Sun, 14 Aug 2011 12:41:39 +0000 (+0000) Subject: mkdir: allow 'mkdir -p' with trailing '/' X-Git-Tag: v3.2.0~368 X-Git-Url: http://zhaoyanbai.com/repos/man.delv.html?a=commitdiff_plain;h=940bbe18b6cc0fb8b0ca1162b5bf0b1405ea0734;p=minix.git mkdir: allow 'mkdir -p' with trailing '/' Let's suppose that /usr/tmp exists and one wants /usr/tmp/a/b If one runs "mkdir -p /usr/tmp/a/b/" (the '/' at the end is important), then a "File exists" error comes up. Example: $ rm -rf /usr/tmp/a $ mkdir -p /usr/tmp/a/b/ /usr/tmp/a/b/: File exists This breaks gcc47 installation when C++ is enabled, and this isn't the behaviour of mkdir on NetBSD nor Linix. This patch fixes the above issue by dropping the trailing '/'. --- diff --git a/commands/mkdir/mkdir.c b/commands/mkdir/mkdir.c index d02734676..e8df1e2d5 100644 --- a/commands/mkdir/mkdir.c +++ b/commands/mkdir/mkdir.c @@ -231,6 +231,10 @@ char *fordir; int makedir(dirname) char *dirname; { + while (strlen(dirname) > 1 && dirname[strlen(dirname) - 1] == '/') { + dirname[strlen(dirname) - 1] = '\0'; /* trim trailing '/' */ + } + if (mkdir(dirname, DEFAULT_MODE)) { if (!pflag) { perror(dirname);