mkdir.c revision da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin/***********************************************************************
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* This software is part of the ast package *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* Copyright (c) 1992-2007 AT&T Knowledge Ventures *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* and is licensed under the *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* Common Public License, Version 1.0 *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* by AT&T Knowledge Ventures *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* A copy of the License is available at *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* Information and Software Systems Research *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* AT&T Research *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* Florham Park NJ *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* Glenn Fowler <gsf@research.att.com> *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* David Korn <dgk@research.att.com> *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin***********************************************************************/
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * David Korn
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * AT&T Bell Laboratories
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinstatic const char usage[] =
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin"[-?\n@(#)$Id: mkdir (AT&T Research) 2006-08-27 $\n]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin"[+NAME?mkdir - make directories]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin"[+DESCRIPTION?\bmkdir\b creates one or more directories. By "
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "default, the mode of created directories is \ba=rwx\b minus the "
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "bits set in the \bumask\b(1).]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin"[m:mode]:[mode?Set the mode of created directories to \amode\a. "
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "\amode\a is symbolic or octal mode as in \bchmod\b(1). Relative "
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "modes assume an initial mode of \ba=rwx\b.]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin"[p:parents?Create any missing intermediate pathname components. For "
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "each dir operand that does not name an existing directory, effects "
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "equivalent to those caused by the following command shall occur: "
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "\vmkdir -p -m $(umask -S),u+wx $(dirname dir) && mkdir [-m mode]] "
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "dir\v where the \b-m\b mode option represents that option supplied to "
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "the original invocation of \bmkdir\b, if any. Each dir operand that "
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "names an existing directory shall be ignored without error.]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin"\ndirectory ...\n"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin"[+EXIT STATUS?]{"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "[+0?All directories created successfully, or the \b-p\b option "
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "was specified and all the specified directories now exist.]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "[+>0?An error occurred.]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin"[+SEE ALSO?\bchmod\b(1), \brmdir\b(1), \bumask\b(1)]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin register char* arg;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin register int n;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin register int mflag = 0;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin register int pflag = 0;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin mode = strperm(arg = opt_info.arg, &opt_info.arg, mode);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (!pflag || !(errno == ENOENT || errno == EEXIST || errno == ENOTDIR))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * -p option, preserve intermediates
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * first eliminate trailing /'s
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin /* skip over slashes */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin /* skip to next component */