1 /* BSD compatible make directory function 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 Foundation,
16 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
22 #include <sys/types.h>
29 #if STAT_MACROS_BROKEN
33 #if !defined(S_ISDIR) && defined(S_IFDIR)
34 # define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
37 /* mkdir adapted from GNU tar. */
39 /* Make directory DPATH, with permission mode DMODE.
41 Written by Robert Rother, Mariah Corporation, August 1985
42 (sdcsvax!rmr or rmr@uscd). If you want it, it's yours.
44 Severely hacked over by John Gilmore to make a 4.2BSD compatible
45 subroutine. 11Mar86; hoptoad!gnu
47 Modified by rmtodd@uokmax 6-28-87 -- when making an already existing dir,
48 subroutine didn't return EEXIST. It does now. */
58 if (stat (dpath
, &statbuf
) == 0)
60 errno
= EEXIST
; /* stat worked, so it already exists. */
64 /* If stat fails for a reason other than non-existence, return error. */
71 case -1: /* Cannot fork. */
72 return -1; /* errno is already set. */
74 case 0: /* Child process. */
75 /* Cheap hack to set mode of new directory. Since this child
76 process is going away anyway, we zap its umask.
77 This won't suffice to set SUID, SGID, etc. on this
78 directory, so the parent process calls chmod afterward. */
79 status
= umask (0); /* Get current umask. */
80 umask (status
| (0777 & ~dmode
)); /* Set for mkdir. */
81 execl ("/bin/mkdir", "mkdir", dpath
, (char *) 0);
84 default: /* Parent process. */
85 /* Wait for kid to finish. */
86 while (wait (&status
) != cpid
)
91 /* /bin/mkdir failed. */
95 return chmod (dpath
, dmode
);