X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;ds=sidebyside;f=lib%2Fmkdir.c;h=1829a9e2575a46ac39a541b0ffae53c2c723e11b;hb=825548e25793fe043c31a8c71975eb958b7cc53f;hp=95fb1a6d40e383a799af444057b629118e856d15;hpb=974c1be5ddd0807bca0dcfd4bdf023213d99a2ba;p=gnulib.git diff --git a/lib/mkdir.c b/lib/mkdir.c index 95fb1a6d4..1829a9e25 100644 --- a/lib/mkdir.c +++ b/lib/mkdir.c @@ -1,5 +1,5 @@ /* BSD compatible make directory function for System V - Copyright (C) 1988, 1990 Free Software Foundation, Inc. + Copyright (C) 1988, 1990, 1998 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -34,6 +34,16 @@ extern int errno; # define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) #endif +#ifndef S_IRWXU +# define S_IRWXU 0700 +#endif +#ifndef S_IRWXG +# define S_IRWXG 0070 +#endif +#ifndef S_IRWXO +# define S_IRWXO 0007 +#endif + /* mkdir adapted from GNU tar. */ /* Make directory DPATH, with permission mode DMODE. @@ -48,11 +58,11 @@ extern int errno; subroutine didn't return EEXIST. It does now. */ int -mkdir (dpath, dmode) - char *dpath; - int dmode; +mkdir (const char *dpath, mode_t dmode) { - int cpid, status; + pid_t cpid; + mode_t mode; + int status; struct stat statbuf; if (stat (dpath, &statbuf) == 0) @@ -76,8 +86,9 @@ mkdir (dpath, dmode) process is going away anyway, we zap its umask. This won't suffice to set SUID, SGID, etc. on this directory, so the parent process calls chmod afterward. */ - status = umask (0); /* Get current umask. */ - umask (status | (0777 & ~dmode)); /* Set for mkdir. */ + mode = umask (0); /* Get current umask. */ + /* Set for mkdir. */ + umask (mode | ((S_IRWXU | S_IRWXG | S_IRWXO) & ~dmode)); execl ("/bin/mkdir", "mkdir", dpath, (char *) 0); _exit (1); @@ -86,7 +97,7 @@ mkdir (dpath, dmode) while (wait (&status) != cpid) /* Do nothing. */ ; - if (status & 0xFFFF) + if (status) { /* /bin/mkdir failed. */ errno = EIO;