/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1992-2012 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* David Korn <dgk@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* David Korn
* AT&T Bell Laboratories
*
* mkdir
*/
static const char usage[] =
"[-?\n@(#)$Id: mkdir (AT&T Research) 2010-04-08 $\n]"
"[+NAME?mkdir - make directories]"
"[+DESCRIPTION?\bmkdir\b creates one or more directories. By "
"default, the mode of created directories is \ba=rwx\b minus the "
"bits set in the \bumask\b(1).]"
"[m:mode]:[mode?Set the mode of created directories to \amode\a. "
"\amode\a is symbolic or octal mode as in \bchmod\b(1). Relative "
"modes assume an initial mode of \ba=rwx\b.]"
"[p:parents?Create any missing intermediate pathname components. For "
"each dir operand that does not name an existing directory, effects "
"equivalent to those caused by the following command shall occur: "
"\vmkdir -p -m $(umask -S),u+wx $(dirname dir) && mkdir [-m mode]] "
"dir\v where the \b-m\b mode option represents that option supplied to "
"the original invocation of \bmkdir\b, if any. Each dir operand that "
"names an existing directory shall be ignored without error.]"
"[v:verbose?Print a message on the standard error for each created "
"directory.]"
"\n"
"\ndirectory ...\n"
"\n"
"[+EXIT STATUS?]{"
"[+0?All directories created successfully, or the \b-p\b option "
"was specified and all the specified directories now exist.]"
"[+>0?An error occurred.]"
"}"
"[+SEE ALSO?\bchmod\b(1), \brmdir\b(1), \bumask\b(1)]"
;
#include <cmd.h>
#include <ls.h>
int
{
register char* path;
register int n;
register int mflag = 0;
register int pflag = 0;
register int vflag = 0;
int made;
char* part;
for (;;)
{
{
case 'm':
mflag = 1;
if (*part)
continue;
case 'p':
pflag = 1;
continue;
case 'v':
vflag = 1;
continue;
case ':':
break;
case '?':
break;
}
break;
}
{
if (!mflag)
}
else
{
mask = 0;
}
{
{
if (vflag)
made = 1;
}
{
continue;
}
continue;
else
{
/*
* -p option, preserve intermediates
* first eliminate trailing /'s
*/
made = 0;
while (n > 0 && path[--n] == '/');
path[n + 1] = 0;
{
/* skip over slashes */
while (*part == '/')
part++;
/* skip to next component */
while ((n = *part) && n != '/')
part++;
*part = 0;
{
*part = n;
break;
}
if (vflag)
if (!(*part = n))
{
made = 1;
break;
}
}
}
{
{
break;
}
if ((st.st_mode & (S_ISVTX|S_ISUID|S_ISGID)) != (mode & (S_ISVTX|S_ISUID|S_ISGID)) && chmod(path, mode))
{
error(ERROR_system(0), "%s: cannot change mode from %s to %s", path, fmtperm(st.st_mode & (S_ISVTX|S_ISUID|S_ISGID)), fmtperm(mode));
break;
}
}
}
if (mask)
return error_info.errors != 0;
}