00001 /* mkdir.c -- BSD compatible make directory function for System V 00002 Copyright (C) 1988, 1990 Free Software Foundation, Inc. 00003 00004 This program is free software; you can redistribute it and/or modify 00005 it under the terms of the GNU General Public License as published by 00006 the Free Software Foundation; either version 2, or (at your option) 00007 any later version. 00008 00009 This program is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 GNU General Public License for more details. 00013 00014 You should have received a copy of the GNU General Public License 00015 along with this program; if not, write to the Free Software 00016 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA. */ 00017 00018 #ifdef HAVE_CONFIG_H 00019 #include <config.h> 00020 #endif 00021 00022 #ifndef HAVE_MKDIR 00023 00024 #ifdef HAVE_SYS_TYPES_H 00025 #include <sys/types.h> 00026 #endif 00027 #include <sys/stat.h> 00028 #include <errno.h> 00029 #ifndef errno 00030 extern int errno; 00031 #endif 00032 00033 #ifdef STAT_MACROS_BROKEN 00034 #undef S_ISDIR 00035 #endif 00036 00037 #if !defined(S_ISDIR) && defined(S_IFDIR) 00038 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) 00039 #endif 00040 00041 #include "safe-stat.h" 00042 00043 /* mkdir adapted from GNU tar. */ 00044 00045 /* Make directory DPATH, with permission mode DMODE. 00046 00047 Written by Robert Rother, Mariah Corporation, August 1985 00048 (sdcsvax!rmr or rmr@uscd). If you want it, it's yours. 00049 00050 Severely hacked over by John Gilmore to make a 4.2BSD compatible 00051 subroutine. 11Mar86; hoptoad!gnu 00052 00053 Modified by rmtodd@uokmax 6-28-87 -- when making an already existing dir, 00054 subroutine didn't return EEXIST. It does now. */ 00055 00056 int 00057 mkdir (dpath, dmode) 00058 char *dpath; 00059 int dmode; 00060 { 00061 int cpid, status; 00062 struct stat statbuf; 00063 00064 if (SAFE_STAT (dpath, &statbuf) == 0) 00065 { 00066 errno = EEXIST; /* stat worked, so it already exists. */ 00067 return -1; 00068 } 00069 00070 /* If stat fails for a reason other than non-existence, return error. */ 00071 if (errno != ENOENT) 00072 return -1; 00073 00074 cpid = fork (); 00075 switch (cpid) 00076 { 00077 case -1: /* Cannot fork. */ 00078 return -1; /* errno is already set. */ 00079 00080 case 0: /* Child process. */ 00081 /* Cheap hack to set mode of new directory. Since this child 00082 process is going away anyway, we zap its umask. 00083 This won't suffice to set SUID, SGID, etc. on this 00084 directory, so the parent process calls chmod afterward. */ 00085 status = umask (0); /* Get current umask. */ 00086 umask (status | (0777 & ~dmode)); /* Set for mkdir. */ 00087 execl ("/bin/mkdir", "mkdir", dpath, (char *) 0); 00088 _exit (1); 00089 00090 default: /* Parent process. */ 00091 /* Wait for kid to finish. */ 00092 while (wait (&status) != cpid) 00093 /* Do nothing. */ ; 00094 00095 if (status & 0xFFFF) 00096 { 00097 /* /bin/mkdir failed. */ 00098 errno = EIO; 00099 return -1; 00100 } 00101 return chmod (dpath, dmode); 00102 } 00103 } 00104 00105 #endif
SEO | [PR] 爆速!無料ブログ 無料ホームページ開設 無料ライブ放送 | ||