1 /* mkdir.c -- BSD compatible directory functions for System V
2 Copyright (C) 1988, 1990 Free Software Foundation, Inc.
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
19 #if defined (CONFIG_BROKETS)
20 /* We use <config.h> instead of "config.h" so that a compilation
21 using -I. -I$srcdir will use ./config.h rather than $srcdir/config.h
22 (which it would do because it found this file in $srcdir). */
29 #include <sys/types.h>
36 #ifdef STAT_MACROS_BROKEN
38 #endif /* STAT_MACROS_BROKEN. */
40 #if !defined(S_ISDIR) && defined(S_IFDIR)
41 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
44 #include "safe-stat.h"
46 /* mkdir and rmdir adapted from GNU tar. */
48 /* Make directory DPATH, with permission mode DMODE.
50 Written by Robert Rother, Mariah Corporation, August 1985
51 (sdcsvax!rmr or rmr@uscd). If you want it, it's yours.
53 Severely hacked over by John Gilmore to make a 4.2BSD compatible
54 subroutine. 11Mar86; hoptoad!gnu
56 Modified by rmtodd@uokmax 6-28-87 -- when making an already existing dir,
57 subroutine didn't return EEXIST. It does now. */
67 if (SAFE_STAT (dpath, &statbuf) == 0)
69 errno = EEXIST; /* stat worked, so it already exists. */
73 /* If stat fails for a reason other than non-existence, return error. */
80 case -1: /* Cannot fork. */
81 return -1; /* errno is set already. */
83 case 0: /* Child process. */
84 /* Cheap hack to set mode of new directory. Since this child
85 process is going away anyway, we zap its umask.
86 This won't suffice to set SUID, SGID, etc. on this
87 directory, so the parent process calls chmod afterward. */
88 status = umask (0); /* Get current umask. */
89 umask (status | (0777 & ~dmode)); /* Set for mkdir. */
90 execl ("/bin/mkdir", "mkdir", dpath, (char *) 0);
93 default: /* Parent process. */
94 while (wait (&status) != cpid) /* Wait for kid to finish. */
99 errno = EIO; /* /bin/mkdir failed. */
102 return chmod (dpath, dmode);
106 /* Remove directory DPATH.
107 Return 0 if successful, -1 if not. */
116 if (SAFE_STAT (dpath, &statbuf) != 0)
117 return -1; /* stat set errno. */
119 if (!S_ISDIR (statbuf.st_mode))
128 case -1: /* Cannot fork. */
129 return -1; /* errno is set already. */
131 case 0: /* Child process. */
132 execl ("/bin/rmdir", "rmdir", dpath, (char *) 0);
135 default: /* Parent process. */
136 while (wait (&status) != cpid) /* Wait for kid to finish. */
141 errno = EIO; /* /bin/rmdir failed. */