import NetBSD mkdir
. add symlink from old location /usr/bin/mkdir for for compatability
This commit is contained in:
		
							parent
							
								
									c78308f469
								
							
						
					
					
						commit
						12d9a08f0d
					
				| @ -2,6 +2,6 @@ | |||||||
| 
 | 
 | ||||||
| .include <bsd.own.mk> | .include <bsd.own.mk> | ||||||
| 
 | 
 | ||||||
| SUBDIR= | SUBDIR= mkdir | ||||||
| 
 | 
 | ||||||
| .include <bsd.subdir.mk> | .include <bsd.subdir.mk> | ||||||
|  | |||||||
							
								
								
									
										7
									
								
								bin/mkdir/Makefile
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								bin/mkdir/Makefile
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,7 @@ | |||||||
|  | #	$NetBSD: Makefile,v 1.8 1997/07/20 22:37:21 christos Exp $
 | ||||||
|  | #	@(#)Makefile	8.1 (Berkeley) 5/31/93
 | ||||||
|  | 
 | ||||||
|  | PROG=	mkdir | ||||||
|  | SYMLINKS=	$(BINDIR)/$(PROG) /usr/bin/$(PROG) | ||||||
|  | 
 | ||||||
|  | .include <bsd.prog.mk> | ||||||
							
								
								
									
										0
									
								
								bin/mkdir/minix-port.patch
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								bin/mkdir/minix-port.patch
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										94
									
								
								bin/mkdir/mkdir.1
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										94
									
								
								bin/mkdir/mkdir.1
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,94 @@ | |||||||
|  | .\"	$NetBSD: mkdir.1,v 1.16 2003/08/07 09:05:16 agc Exp $ | ||||||
|  | .\" | ||||||
|  | .\" Copyright (c) 1989, 1990, 1993 | ||||||
|  | .\"	The Regents of the University of California.  All rights reserved. | ||||||
|  | .\" | ||||||
|  | .\" This code is derived from software contributed to Berkeley by | ||||||
|  | .\" the Institute of Electrical and Electronics Engineers, Inc. | ||||||
|  | .\" | ||||||
|  | .\" Redistribution and use in source and binary forms, with or without | ||||||
|  | .\" modification, are permitted provided that the following conditions | ||||||
|  | .\" are met: | ||||||
|  | .\" 1. Redistributions of source code must retain the above copyright | ||||||
|  | .\"    notice, this list of conditions and the following disclaimer. | ||||||
|  | .\" 2. Redistributions in binary form must reproduce the above copyright | ||||||
|  | .\"    notice, this list of conditions and the following disclaimer in the | ||||||
|  | .\"    documentation and/or other materials provided with the distribution. | ||||||
|  | .\" 3. Neither the name of the University nor the names of its contributors | ||||||
|  | .\"    may be used to endorse or promote products derived from this software | ||||||
|  | .\"    without specific prior written permission. | ||||||
|  | .\" | ||||||
|  | .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | ||||||
|  | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||||||
|  | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||||||
|  | .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | ||||||
|  | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||||||
|  | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||||||
|  | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||||||
|  | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||||||
|  | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||||||
|  | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||||||
|  | .\" SUCH DAMAGE. | ||||||
|  | .\" | ||||||
|  | .\"	@(#)mkdir.1	8.2 (Berkeley) 1/25/94 | ||||||
|  | .\" | ||||||
|  | .Dd January 25, 1994 | ||||||
|  | .Dt MKDIR 1 | ||||||
|  | .Os | ||||||
|  | .Sh NAME | ||||||
|  | .Nm mkdir | ||||||
|  | .Nd make directories | ||||||
|  | .Sh SYNOPSIS | ||||||
|  | .Nm | ||||||
|  | .Op Fl p | ||||||
|  | .Op Fl m Ar mode | ||||||
|  | .Ar directory_name  ... | ||||||
|  | .Sh DESCRIPTION | ||||||
|  | .Nm | ||||||
|  | creates the directories named as operands, in the order specified, | ||||||
|  | using mode | ||||||
|  | .Li rwxrwxrwx (\&0777) | ||||||
|  | as modified by the current | ||||||
|  | .Xr umask  2  . | ||||||
|  | .Pp | ||||||
|  | The options are as follows: | ||||||
|  | .Pp | ||||||
|  | .Bl -tag -width indent | ||||||
|  | .It Fl m | ||||||
|  | Set the file permission bits of the final created directory to | ||||||
|  | the specified mode. | ||||||
|  | The mode argument can be in any of the formats specified to the | ||||||
|  | .Xr chmod 1 | ||||||
|  | utility. | ||||||
|  | If a symbolic mode is specified, the operation characters | ||||||
|  | .Dq + | ||||||
|  | and | ||||||
|  | .Dq - | ||||||
|  | are interpreted relative to an initial mode of | ||||||
|  | .Dq a=rwx . | ||||||
|  | .It Fl p | ||||||
|  | Create intermediate directories as required. | ||||||
|  | If this option is not specified, the full path prefix of each | ||||||
|  | operand must already exist. | ||||||
|  | Intermediate directories are created with permission bits of | ||||||
|  | .Li rwxrwxrwx (\&0777) | ||||||
|  | as modified by the current umask, plus write and search | ||||||
|  | permission for the owner. | ||||||
|  | Do not consider it an error if the argument directory already exists. | ||||||
|  | .El | ||||||
|  | .Pp | ||||||
|  | The user must have write permission in the parent directory. | ||||||
|  | .Sh EXIT STATUS | ||||||
|  | .Nm | ||||||
|  | exits 0 if successful, and \*[Gt]0 if an error occurred. | ||||||
|  | .Sh SEE ALSO | ||||||
|  | .Xr chmod 1 , | ||||||
|  | .Xr rmdir 1 , | ||||||
|  | .Xr mkdir 2 , | ||||||
|  | .Xr umask 2 | ||||||
|  | .Sh STANDARDS | ||||||
|  | The | ||||||
|  | .Nm | ||||||
|  | utility is expected to be | ||||||
|  | .St -p1003.2 | ||||||
|  | compatible. | ||||||
							
								
								
									
										224
									
								
								bin/mkdir/mkdir.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										224
									
								
								bin/mkdir/mkdir.c
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,224 @@ | |||||||
|  | /* $NetBSD: mkdir.c,v 1.37 2008/07/20 00:52:40 lukem Exp $ */ | ||||||
|  | 
 | ||||||
|  | /*
 | ||||||
|  |  * Copyright (c) 1983, 1992, 1993 | ||||||
|  |  *	The Regents of the University of California.  All rights reserved. | ||||||
|  |  * | ||||||
|  |  * Redistribution and use in source and binary forms, with or without | ||||||
|  |  * modification, are permitted provided that the following conditions | ||||||
|  |  * are met: | ||||||
|  |  * 1. Redistributions of source code must retain the above copyright | ||||||
|  |  *    notice, this list of conditions and the following disclaimer. | ||||||
|  |  * 2. Redistributions in binary form must reproduce the above copyright | ||||||
|  |  *    notice, this list of conditions and the following disclaimer in the | ||||||
|  |  *    documentation and/or other materials provided with the distribution. | ||||||
|  |  * 3. Neither the name of the University nor the names of its contributors | ||||||
|  |  *    may be used to endorse or promote products derived from this software | ||||||
|  |  *    without specific prior written permission. | ||||||
|  |  * | ||||||
|  |  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | ||||||
|  |  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||||||
|  |  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||||||
|  |  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | ||||||
|  |  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||||||
|  |  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||||||
|  |  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||||||
|  |  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||||||
|  |  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||||||
|  |  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||||||
|  |  * SUCH DAMAGE. | ||||||
|  |  */ | ||||||
|  | 
 | ||||||
|  | #include <sys/cdefs.h> | ||||||
|  | #ifndef lint | ||||||
|  | __COPYRIGHT("@(#) Copyright (c) 1983, 1992, 1993\
 | ||||||
|  |  The Regents of the University of California.  All rights reserved."); | ||||||
|  | #endif /* not lint */ | ||||||
|  | 
 | ||||||
|  | #ifndef lint | ||||||
|  | #if 0 | ||||||
|  | static char sccsid[] = "@(#)mkdir.c	8.2 (Berkeley) 1/25/94"; | ||||||
|  | #else | ||||||
|  | __RCSID("$NetBSD: mkdir.c,v 1.37 2008/07/20 00:52:40 lukem Exp $"); | ||||||
|  | #endif | ||||||
|  | #endif /* not lint */ | ||||||
|  | 
 | ||||||
|  | #include <sys/param.h> | ||||||
|  | #include <sys/stat.h> | ||||||
|  | #include <sys/types.h> | ||||||
|  | 
 | ||||||
|  | #include <err.h> | ||||||
|  | #include <errno.h> | ||||||
|  | #include <locale.h> | ||||||
|  | #include <stdio.h> | ||||||
|  | #include <stdlib.h> | ||||||
|  | #include <string.h> | ||||||
|  | #include <unistd.h> | ||||||
|  | 
 | ||||||
|  | int	mkpath(char *, mode_t, mode_t); | ||||||
|  | void	usage(void); | ||||||
|  | int	main(int, char *[]); | ||||||
|  | 
 | ||||||
|  | int | ||||||
|  | main(int argc, char *argv[]) | ||||||
|  | { | ||||||
|  | 	int ch, exitval, pflag; | ||||||
|  | 	void *set; | ||||||
|  | 	mode_t mode, dir_mode; | ||||||
|  | 
 | ||||||
|  | 	setprogname(argv[0]); | ||||||
|  | 	(void)setlocale(LC_ALL, ""); | ||||||
|  | 
 | ||||||
|  | 	/*
 | ||||||
|  | 	 * The default file mode is a=rwx (0777) with selected permissions | ||||||
|  | 	 * removed in accordance with the file mode creation mask.  For | ||||||
|  | 	 * intermediate path name components, the mode is the default modified | ||||||
|  | 	 * by u+wx so that the subdirectories can always be created. | ||||||
|  | 	 */ | ||||||
|  | 	mode = (S_IRWXU | S_IRWXG | S_IRWXO) & ~umask(0); | ||||||
|  | 	dir_mode = mode | S_IWUSR | S_IXUSR; | ||||||
|  | 
 | ||||||
|  | 	pflag = 0; | ||||||
|  | 	while ((ch = getopt(argc, argv, "m:p")) != -1) | ||||||
|  | 		switch (ch) { | ||||||
|  | 		case 'p': | ||||||
|  | 			pflag = 1; | ||||||
|  | 			break; | ||||||
|  | 		case 'm': | ||||||
|  | 			if ((set = setmode(optarg)) == NULL) { | ||||||
|  | 				err(EXIT_FAILURE, "Cannot set file mode `%s'", | ||||||
|  | 				    optarg); | ||||||
|  | 				/* NOTREACHED */ | ||||||
|  | 			} | ||||||
|  | 			mode = getmode(set, S_IRWXU | S_IRWXG | S_IRWXO); | ||||||
|  | 			free(set); | ||||||
|  | 			break; | ||||||
|  | 		case '?': | ||||||
|  | 		default: | ||||||
|  | 			usage(); | ||||||
|  | 			/* NOTREACHED */ | ||||||
|  | 		} | ||||||
|  | 	argc -= optind; | ||||||
|  | 	argv += optind; | ||||||
|  | 
 | ||||||
|  | 	if (*argv == NULL) { | ||||||
|  | 		usage(); | ||||||
|  | 		/* NOTREACHED */ | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	for (exitval = EXIT_SUCCESS; *argv != NULL; ++argv) { | ||||||
|  | #ifdef notdef | ||||||
|  | 		char *slash; | ||||||
|  | 
 | ||||||
|  | 		/* Kernel takes care of this */ | ||||||
|  | 		/* Remove trailing slashes, per POSIX. */ | ||||||
|  | 		slash = strrchr(*argv, '\0'); | ||||||
|  | 		while (--slash > *argv && *slash == '/') | ||||||
|  | 			*slash = '\0'; | ||||||
|  | #endif | ||||||
|  | 
 | ||||||
|  | 		if (pflag) { | ||||||
|  | 			if (mkpath(*argv, mode, dir_mode) < 0) | ||||||
|  | 				exitval = EXIT_FAILURE; | ||||||
|  | 		} else { | ||||||
|  | 			if (mkdir(*argv, mode) < 0) { | ||||||
|  | 				warn("%s", *argv); | ||||||
|  | 				exitval = EXIT_FAILURE; | ||||||
|  | 			} else { | ||||||
|  | 				/*
 | ||||||
|  | 				 * The mkdir() and umask() calls both honor | ||||||
|  | 				 * only the file permission bits, so if you try | ||||||
|  | 				 * to set a mode including the sticky, setuid, | ||||||
|  | 				 * setgid bits you lose them. So chmod(). | ||||||
|  | 				 */ | ||||||
|  | 				if ((mode & ~(S_IRWXU|S_IRWXG|S_IRWXO)) != 0 && | ||||||
|  | 				    chmod(*argv, mode) == -1) { | ||||||
|  | 					warn("%s", *argv); | ||||||
|  | 					exitval = EXIT_FAILURE; | ||||||
|  | 				} | ||||||
|  | 			} | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | 	exit(exitval); | ||||||
|  | 	/* NOTREACHED */ | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | /*
 | ||||||
|  |  * mkpath -- create directories. | ||||||
|  |  *	path     - path | ||||||
|  |  *	mode     - file mode of terminal directory | ||||||
|  |  *	dir_mode - file mode of intermediate directories | ||||||
|  |  */ | ||||||
|  | int | ||||||
|  | mkpath(char *path, mode_t mode, mode_t dir_mode) | ||||||
|  | { | ||||||
|  | 	struct stat sb; | ||||||
|  | 	char *slash; | ||||||
|  | 	int done, rv; | ||||||
|  | 
 | ||||||
|  | 	done = 0; | ||||||
|  | 	slash = path; | ||||||
|  | 
 | ||||||
|  | 	for (;;) { | ||||||
|  | 		slash += strspn(slash, "/"); | ||||||
|  | 		slash += strcspn(slash, "/"); | ||||||
|  | 
 | ||||||
|  | 		done = (*slash == '\0'); | ||||||
|  | 		*slash = '\0'; | ||||||
|  | 
 | ||||||
|  | 		rv = mkdir(path, done ? mode : dir_mode); | ||||||
|  | 		if (rv < 0) { | ||||||
|  | 			/*
 | ||||||
|  | 			 * Can't create; path exists or no perms. | ||||||
|  | 			 * stat() path to determine what's there now. | ||||||
|  | 			 */ | ||||||
|  | 			int	sverrno; | ||||||
|  | 
 | ||||||
|  | 			sverrno = errno; | ||||||
|  | 			if (stat(path, &sb) < 0) { | ||||||
|  | 					/* Not there; use mkdir()s error */ | ||||||
|  | 				errno = sverrno; | ||||||
|  | 				warn("%s", path); | ||||||
|  | 				return -1; | ||||||
|  | 			} | ||||||
|  | 			if (!S_ISDIR(sb.st_mode)) { | ||||||
|  | 					/* Is there, but isn't a directory */ | ||||||
|  | 				errno = ENOTDIR; | ||||||
|  | 				warn("%s", path); | ||||||
|  | 				return -1; | ||||||
|  | 			} | ||||||
|  | 		} else if (done) { | ||||||
|  | 			/*
 | ||||||
|  | 			 * Created ok, and this is the last element | ||||||
|  | 			 */ | ||||||
|  | 			/*
 | ||||||
|  | 			 * The mkdir() and umask() calls both honor only the | ||||||
|  | 			 * file permission bits, so if you try to set a mode | ||||||
|  | 			 * including the sticky, setuid, setgid bits you lose | ||||||
|  | 			 * them. So chmod(). | ||||||
|  | 			 */ | ||||||
|  | 			if ((mode & ~(S_IRWXU|S_IRWXG|S_IRWXO)) != 0 && | ||||||
|  | 			    chmod(path, mode) == -1) { | ||||||
|  | 				warn("%s", path); | ||||||
|  | 				return -1; | ||||||
|  | 			} | ||||||
|  | 		} | ||||||
|  | 
 | ||||||
|  | 		if (done) { | ||||||
|  | 			break; | ||||||
|  | 		} | ||||||
|  | 		*slash = '/'; | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	return 0; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | void | ||||||
|  | usage(void) | ||||||
|  | { | ||||||
|  | 
 | ||||||
|  | 	(void)fprintf(stderr, "usage: %s [-p] [-m mode] dirname ...\n", | ||||||
|  | 	    getprogname()); | ||||||
|  | 	exit(EXIT_FAILURE); | ||||||
|  | 	/* NOTREACHED */ | ||||||
|  | } | ||||||
| @ -17,7 +17,7 @@ SUBDIR=	aal add_route adduser arp ash at autil awk \ | |||||||
| 	intr ipcrm ipcs irdpd isoread join kill last leave \
 | 	intr ipcrm ipcs irdpd isoread join kill last leave \
 | ||||||
| 	less lex loadkeys loadramdisk logger login look lp \
 | 	less lex loadkeys loadramdisk logger login look lp \
 | ||||||
| 	lpd ls lspci M mail make  MAKEDEV man \
 | 	lpd ls lspci M mail make  MAKEDEV man \
 | ||||||
| 	mdb mdocml mesg mined ackmkdep mkdir mkfifo mkfs.mfs mknod \
 | 	mdb mdocml mesg mined ackmkdep mkfifo mkfs.mfs mknod \
 | ||||||
| 	mkproto modem mount mt netconf newroot nice acknm nohup \
 | 	mkproto modem mount mt netconf newroot nice acknm nohup \
 | ||||||
| 	nonamed od passwd paste patch pax \
 | 	nonamed od passwd paste patch pax \
 | ||||||
| 	ping postinstall poweroff pr prep printf printroot \
 | 	ping postinstall poweroff pr prep printf printroot \
 | ||||||
|  | |||||||
| @ -1,4 +0,0 @@ | |||||||
| PROG=	mkdir |  | ||||||
| MAN= |  | ||||||
| 
 |  | ||||||
| .include <bsd.prog.mk> |  | ||||||
| @ -1,269 +0,0 @@ | |||||||
| /* mkdir - Make directories		Author: V. Archer */ |  | ||||||
| 
 |  | ||||||
| /* Copyright 1991 by Vincent Archer
 |  | ||||||
|  *	You may freely redistribute this software, in source or binary |  | ||||||
|  *	form, provided that you do not alter this copyright mention in any |  | ||||||
|  *	way. |  | ||||||
|  */ |  | ||||||
| 
 |  | ||||||
| #include <sys/types.h> |  | ||||||
| #include <sys/stat.h> |  | ||||||
| #include <minix/minlib.h> |  | ||||||
| #include <limits.h> |  | ||||||
| #include <errno.h> |  | ||||||
| #include <string.h> |  | ||||||
| #include <stdlib.h> |  | ||||||
| #include <unistd.h> |  | ||||||
| #include <stdio.h> |  | ||||||
| 
 |  | ||||||
| extern int optind, opterr; |  | ||||||
| extern char *optarg; |  | ||||||
| 
 |  | ||||||
| #define USR_MODES (S_ISUID|S_IRWXU) |  | ||||||
| #define GRP_MODES (S_ISGID|S_IRWXG) |  | ||||||
| #define EXE_MODES (S_IXUSR|S_IXGRP|S_IXOTH) |  | ||||||
| #ifdef S_ISVTX |  | ||||||
| #define ALL_MODES (USR_MODES|GRP_MODES|S_IRWXO|S_ISVTX) |  | ||||||
| #else |  | ||||||
| #define ALL_MODES (USR_MODES|GRP_MODES|S_IRWXO) |  | ||||||
| #endif |  | ||||||
| #define DEFAULT_MODE (S_IRWXU|S_IRWXG|S_IRWXO) |  | ||||||
| #define USER_WX (S_IWUSR|S_IXUSR) |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| /* Global variables */ |  | ||||||
| int pflag; |  | ||||||
| char *symbolic; |  | ||||||
| mode_t u_mask; |  | ||||||
| struct stat st; |  | ||||||
| 
 |  | ||||||
| _PROTOTYPE(int main, (int argc, char **argv)); |  | ||||||
| _PROTOTYPE(mode_t parsemode, (char *symbolic, mode_t oldmode)); |  | ||||||
| _PROTOTYPE(int makepath, (char *fordir)); |  | ||||||
| _PROTOTYPE(int makedir, (char *dirname)); |  | ||||||
| _PROTOTYPE(void usage, (void)); |  | ||||||
| 
 |  | ||||||
| /* Parse a P1003.2 4.7.7-conformant symbolic mode. */ |  | ||||||
| mode_t parsemode(char *symbolic, mode_t oldmode) |  | ||||||
| { |  | ||||||
|   mode_t who, mask, newmode, tmpmask; |  | ||||||
|   char action; |  | ||||||
|   char *end; |  | ||||||
|   unsigned long octalmode; |  | ||||||
| 
 |  | ||||||
|   octalmode = strtoul(symbolic, &end, 010); |  | ||||||
|   if (octalmode < ALL_MODES && *end == 0 && end != symbolic) return octalmode; |  | ||||||
| 
 |  | ||||||
|   newmode = oldmode & ALL_MODES; |  | ||||||
|   while (*symbolic) { |  | ||||||
| 	who = 0; |  | ||||||
| 	for (; *symbolic; symbolic++) { |  | ||||||
| 		if (*symbolic == 'a') { |  | ||||||
| 			who |= ALL_MODES; |  | ||||||
| 			continue; |  | ||||||
| 		} |  | ||||||
| 		if (*symbolic == 'u') { |  | ||||||
| 			who |= USR_MODES; |  | ||||||
| 			continue; |  | ||||||
| 		} |  | ||||||
| 		if (*symbolic == 'g') { |  | ||||||
| 			who |= GRP_MODES; |  | ||||||
| 			continue; |  | ||||||
| 		} |  | ||||||
| 		if (*symbolic == 'o') { |  | ||||||
| 			who |= S_IRWXO; |  | ||||||
| 			continue; |  | ||||||
| 		} |  | ||||||
| 		break; |  | ||||||
| 	} |  | ||||||
| 	if (!*symbolic || *symbolic == ',') usage(); |  | ||||||
| 	while (*symbolic) { |  | ||||||
| 		if (*symbolic == ',') break; |  | ||||||
| 		switch (*symbolic) { |  | ||||||
| 		    default: |  | ||||||
| 			usage(); |  | ||||||
| 		    case '+': |  | ||||||
| 		    case '-': |  | ||||||
| 		    case '=':	action = *symbolic++; |  | ||||||
| 		} |  | ||||||
| 		mask = 0; |  | ||||||
| 		for (; *symbolic; symbolic++) { |  | ||||||
| 			if (*symbolic == 'u') { |  | ||||||
| 				tmpmask = newmode & S_IRWXU; |  | ||||||
| 				mask |= tmpmask | (tmpmask << 3) | (tmpmask << 6); |  | ||||||
| 				symbolic++; |  | ||||||
| 				break; |  | ||||||
| 			} |  | ||||||
| 			if (*symbolic == 'g') { |  | ||||||
| 				tmpmask = newmode & S_IRWXG; |  | ||||||
| 				mask |= tmpmask | (tmpmask >> 3) | (tmpmask << 3); |  | ||||||
| 				symbolic++; |  | ||||||
| 				break; |  | ||||||
| 			} |  | ||||||
| 			if (*symbolic == 'o') { |  | ||||||
| 				tmpmask = newmode & S_IRWXO; |  | ||||||
| 				mask |= tmpmask | (tmpmask >> 3) | (tmpmask >> 6); |  | ||||||
| 				symbolic++; |  | ||||||
| 				break; |  | ||||||
| 			} |  | ||||||
| 			if (*symbolic == 'r') { |  | ||||||
| 				mask |= S_IRUSR | S_IRGRP | S_IROTH; |  | ||||||
| 				continue; |  | ||||||
| 			} |  | ||||||
| 			if (*symbolic == 'w') { |  | ||||||
| 				mask |= S_IWUSR | S_IWGRP | S_IWOTH; |  | ||||||
| 				continue; |  | ||||||
| 			} |  | ||||||
| 			if (*symbolic == 'x') { |  | ||||||
| 				mask |= EXE_MODES; |  | ||||||
| 				continue; |  | ||||||
| 			} |  | ||||||
| 			if (*symbolic == 's') { |  | ||||||
| 				mask |= S_ISUID | S_ISGID; |  | ||||||
| 				continue; |  | ||||||
| 			} |  | ||||||
| 			if (*symbolic == 'X') { |  | ||||||
| 				if (S_ISDIR(oldmode) || (oldmode & EXE_MODES)) |  | ||||||
| 					mask |= EXE_MODES; |  | ||||||
| 				continue; |  | ||||||
| 			} |  | ||||||
| #ifdef S_ISVTX |  | ||||||
| 			if (*symbolic == 't') { |  | ||||||
| 				mask |= S_ISVTX; |  | ||||||
| 				who |= S_ISVTX; |  | ||||||
| 				continue; |  | ||||||
| 			} |  | ||||||
| #endif |  | ||||||
| 			break; |  | ||||||
| 		} |  | ||||||
| 		switch (action) { |  | ||||||
| 		    case '=': |  | ||||||
| 			if (who) |  | ||||||
| 				newmode &= ~who; |  | ||||||
| 			else |  | ||||||
| 				newmode = 0; |  | ||||||
| 		    case '+': |  | ||||||
| 			if (who) |  | ||||||
| 				newmode |= who & mask; |  | ||||||
| 			else |  | ||||||
| 				newmode |= mask & (~u_mask); |  | ||||||
| 			break; |  | ||||||
| 		    case '-': |  | ||||||
| 			if (who) |  | ||||||
| 				newmode &= ~(who & mask); |  | ||||||
| 			else |  | ||||||
| 				newmode &= ~mask | u_mask; |  | ||||||
| 		} |  | ||||||
| 	} |  | ||||||
| 	if (*symbolic) symbolic++; |  | ||||||
|   } |  | ||||||
|   return(newmode); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| /* Main module. */ |  | ||||||
| int main(argc, argv) |  | ||||||
| int argc; |  | ||||||
| char **argv; |  | ||||||
| { |  | ||||||
|   int error, c; |  | ||||||
| 
 |  | ||||||
|   opterr = 0; |  | ||||||
|   pflag = 0; |  | ||||||
|   symbolic = (char *) 0; |  | ||||||
|   u_mask = umask(0); |  | ||||||
|   umask(u_mask); |  | ||||||
|   while ((c = getopt(argc, argv, "m:p")) != EOF) switch (c) { |  | ||||||
| 	    case 'm':	symbolic = optarg;	break; |  | ||||||
| 	    case 'p':	pflag = 1;	break; |  | ||||||
| 	    default:	usage(); |  | ||||||
| 	} |  | ||||||
|   if (optind >= argc) usage(); |  | ||||||
| 
 |  | ||||||
|   error = 0; |  | ||||||
|   while (optind < argc) error |= makedir(argv[optind++]); |  | ||||||
|   return(error); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| /* P1003.2 requires that missing intermediate pathname components should be
 |  | ||||||
|  *	created if the -p option is specified (4.40.3). |  | ||||||
|  */ |  | ||||||
| int makepath(fordir) |  | ||||||
| char *fordir; |  | ||||||
| { |  | ||||||
|   char parent[PATH_MAX + 1], *end, *last; |  | ||||||
| 
 |  | ||||||
|   strcpy(parent, fordir); |  | ||||||
|   do { |  | ||||||
| 	  if (!(end = strrchr(parent, '/'))) return(0); |  | ||||||
| 	  *end = '\0'; |  | ||||||
| 	  if (!parent[0] || !strcmp(parent, ".")) return(0); |  | ||||||
|   } while((last = strrchr(parent, '/')) && !strcmp(last+1, ".")); |  | ||||||
| 
 |  | ||||||
|   if (!stat(parent, &st)) { |  | ||||||
| 	if (S_ISDIR(st.st_mode)) return(0); |  | ||||||
| 	errno = ENOTDIR; |  | ||||||
| 	perror(parent); |  | ||||||
| 	return(1); |  | ||||||
|   } |  | ||||||
|   if (mkdir(parent, DEFAULT_MODE)) { |  | ||||||
| 	if (makepath(parent)) return(1); |  | ||||||
| 	if (mkdir(parent, DEFAULT_MODE)) { |  | ||||||
| 		perror(parent); |  | ||||||
| 		return(1); |  | ||||||
| 	} |  | ||||||
|   } |  | ||||||
| 
 |  | ||||||
| /* P1003.2 states that, regardless of umask() value, intermediate paths
 |  | ||||||
|  *	should have at least write and search (x) permissions (4.40.10). |  | ||||||
|  */ |  | ||||||
|   if ((u_mask & USER_WX) && |  | ||||||
|       chmod(parent, ((~u_mask) | USER_WX)) & DEFAULT_MODE) { |  | ||||||
| 	perror(parent); |  | ||||||
| 	return(1); |  | ||||||
|   } |  | ||||||
|   return(0); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| /* Actual directory creation, using a mkdir() system call. */ |  | ||||||
| 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); |  | ||||||
| 		return(1); |  | ||||||
| 	} |  | ||||||
| 	if (!stat(dirname, &st)) { |  | ||||||
| 		if (S_ISDIR(st.st_mode)) return(0); |  | ||||||
| 		errno = ENOTDIR; |  | ||||||
| 		perror(dirname); |  | ||||||
| 		return(1); |  | ||||||
| 	} |  | ||||||
| 	if (makepath(dirname)) return(1); |  | ||||||
| 	if (mkdir(dirname, DEFAULT_MODE)) { |  | ||||||
| 		perror(dirname); |  | ||||||
| 		return(1); |  | ||||||
| 	} |  | ||||||
|   } |  | ||||||
|   if (symbolic && (stat(dirname, &st) || |  | ||||||
| 		 chmod(dirname, parsemode(symbolic, st.st_mode)))) { |  | ||||||
| 	perror(dirname); |  | ||||||
| 	return(1); |  | ||||||
|   } |  | ||||||
|   return(0); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| /* Posix command prototype. */ |  | ||||||
| void usage() |  | ||||||
| { |  | ||||||
|   std_err("Usage: mkdir [-p] [-m mode] dir...\n"); |  | ||||||
|   exit(1); |  | ||||||
| } |  | ||||||
| @ -11,7 +11,7 @@ MAN=	acd.1 anm.1 ar.1 ash.1 asize.1 at.1 banner.1 basename.1 \ | |||||||
| 	install.1 isodir.1 isoinfo.1 isoread.1 join.1 kill.1 \
 | 	install.1 isodir.1 isoinfo.1 isoread.1 join.1 kill.1 \
 | ||||||
| 	last.1 leave.1 loadfont.1 loadkeys.1 logger.1 login.1 \
 | 	last.1 leave.1 loadfont.1 loadkeys.1 logger.1 login.1 \
 | ||||||
| 	look.1 lp.1 ls.1 lspci.1 M.1 mail.1  \
 | 	look.1 lp.1 ls.1 lspci.1 M.1 mail.1  \
 | ||||||
| 	mesg.1 mixer.1 ackmkdep.1 mkdir.1 mkfs.1 \
 | 	mesg.1 mixer.1 ackmkdep.1 mkfs.1 \
 | ||||||
| 	mkproto.1 modem.1 mount.1 mt.1 nice.1 nm.1 nohup.1 od.1 \
 | 	mkproto.1 modem.1 mount.1 mt.1 nice.1 nm.1 nohup.1 od.1 \
 | ||||||
| 	ossinfo.1 ossmix.1 ossplay.1 ossrecord.1 osstest.1 passwd.1 \
 | 	ossinfo.1 ossmix.1 ossplay.1 ossrecord.1 osstest.1 passwd.1 \
 | ||||||
| 	paste.1 ping.1 playwave.1 postmort.1 pr.1 prep.1 \
 | 	paste.1 ping.1 playwave.1 postmort.1 pr.1 prep.1 \
 | ||||||
|  | |||||||
| @ -1,33 +0,0 @@ | |||||||
| .TH MKDIR 1 |  | ||||||
| .SH NAME |  | ||||||
| mkdir \- make a directory |  | ||||||
| .SH SYNOPSIS |  | ||||||
| \fBmkdir [\fB\-p\fR] [\fB\-m \fImode\fR] \fIdirectory ...\fR |  | ||||||
| .br |  | ||||||
| .de FL |  | ||||||
| .TP |  | ||||||
| \\fB\\$1\\fR |  | ||||||
| \\$2 |  | ||||||
| .. |  | ||||||
| .de EX |  | ||||||
| .TP 20 |  | ||||||
| \\fB\\$1\\fR |  | ||||||
| # \\$2 |  | ||||||
| .. |  | ||||||
| .SH OPTIONS |  | ||||||
| .FL "\-m" "Create directory with mode" |  | ||||||
| .FL "\-p" "Create missing intermediate directories" |  | ||||||
| .SH EXAMPLES |  | ||||||
| .EX "mkdir dir" "Create \fIdir\fP in the current directory" |  | ||||||
| .EX "mkdir \-p /user/ast/dir" "Create the \fI/user/ast\fP and \fI/user/ast/dir\fP" |  | ||||||
| .SH DESCRIPTION |  | ||||||
| .PP |  | ||||||
| The specified directory or directories are created and initialized. If any |  | ||||||
| intermediate directory is missing and \fB\-p\fR is specified, the missing |  | ||||||
| component will be created and no error displayed if directory already |  | ||||||
| exists. If the \fB\-m\fR flag is used, this will be equivalent to a chmod |  | ||||||
| on the directory after its creation. |  | ||||||
| .SH "SEE ALSO" |  | ||||||
| .BR chmod (1), |  | ||||||
| .BR rmdir (1), |  | ||||||
| .BR mkdir (2). |  | ||||||
| @ -5,6 +5,7 @@ lib/libcrypt		src/lib/libcrypt | |||||||
| lib/libterminfo		src/lib/libterminfo | lib/libterminfo		src/lib/libterminfo | ||||||
| lib/libcurses		src/lib/libcurses | lib/libcurses		src/lib/libcurses | ||||||
| nbsd_include		src/include | nbsd_include		src/include | ||||||
|  | bin/mkdir		src/bin/mkdir | ||||||
| usr.bin/m4		src/usr.bin/m4 | usr.bin/m4		src/usr.bin/m4 | ||||||
| usr.bin/indent		src/usr.bin/indent | usr.bin/indent		src/usr.bin/indent | ||||||
| usr.bin/sed		src/usr.bin/sed | usr.bin/sed		src/usr.bin/sed | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Vivek Prakash
						Vivek Prakash