1*b30d1939SAndy Fiddaman /*********************************************************************** 2*b30d1939SAndy Fiddaman * * 3*b30d1939SAndy Fiddaman * This software is part of the ast package * 4*b30d1939SAndy Fiddaman * Copyright (c) 1985-2011 AT&T Intellectual Property * 5*b30d1939SAndy Fiddaman * and is licensed under the * 6*b30d1939SAndy Fiddaman * Eclipse Public License, Version 1.0 * 7*b30d1939SAndy Fiddaman * by AT&T Intellectual Property * 8*b30d1939SAndy Fiddaman * * 9*b30d1939SAndy Fiddaman * A copy of the License is available at * 10*b30d1939SAndy Fiddaman * http://www.eclipse.org/org/documents/epl-v10.html * 11*b30d1939SAndy Fiddaman * (with md5 checksum b35adb5213ca9657e911e9befb180842) * 12*b30d1939SAndy Fiddaman * * 13*b30d1939SAndy Fiddaman * Information and Software Systems Research * 14*b30d1939SAndy Fiddaman * AT&T Research * 15*b30d1939SAndy Fiddaman * Florham Park NJ * 16*b30d1939SAndy Fiddaman * * 17*b30d1939SAndy Fiddaman * Glenn Fowler <gsf@research.att.com> * 18*b30d1939SAndy Fiddaman * David Korn <dgk@research.att.com> * 19*b30d1939SAndy Fiddaman * Phong Vo <kpv@research.att.com> * 20*b30d1939SAndy Fiddaman * * 21*b30d1939SAndy Fiddaman ***********************************************************************/ 22*b30d1939SAndy Fiddaman #pragma prototyped 23*b30d1939SAndy Fiddaman 24*b30d1939SAndy Fiddaman #include <ast.h> 25*b30d1939SAndy Fiddaman 26*b30d1939SAndy Fiddaman #if _lib_mkdir 27*b30d1939SAndy Fiddaman 28*b30d1939SAndy Fiddaman NoN(mkdir) 29*b30d1939SAndy Fiddaman 30*b30d1939SAndy Fiddaman #else 31*b30d1939SAndy Fiddaman 32*b30d1939SAndy Fiddaman #include <ls.h> 33*b30d1939SAndy Fiddaman #include <wait.h> 34*b30d1939SAndy Fiddaman #include <error.h> 35*b30d1939SAndy Fiddaman 36*b30d1939SAndy Fiddaman int 37*b30d1939SAndy Fiddaman mkdir(const char* path, mode_t mode) 38*b30d1939SAndy Fiddaman { 39*b30d1939SAndy Fiddaman register int n; 40*b30d1939SAndy Fiddaman char* av[3]; 41*b30d1939SAndy Fiddaman 42*b30d1939SAndy Fiddaman static char* cmd[] = { "/bin/mkdir", 0 }; 43*b30d1939SAndy Fiddaman 44*b30d1939SAndy Fiddaman 45*b30d1939SAndy Fiddaman n = errno; 46*b30d1939SAndy Fiddaman if (!access(path, F_OK)) 47*b30d1939SAndy Fiddaman { 48*b30d1939SAndy Fiddaman errno = EEXIST; 49*b30d1939SAndy Fiddaman return(-1); 50*b30d1939SAndy Fiddaman } 51*b30d1939SAndy Fiddaman if (errno != ENOENT) return(-1); 52*b30d1939SAndy Fiddaman errno = n; 53*b30d1939SAndy Fiddaman av[0] = "mkdir"; 54*b30d1939SAndy Fiddaman av[1] = path; 55*b30d1939SAndy Fiddaman av[2] = 0; 56*b30d1939SAndy Fiddaman for (n = 0; n < elementsof(cmd); n++) 57*b30d1939SAndy Fiddaman if (procclose(procopen(cmd[n], av, NiL, NiL, 0)) != -1) 58*b30d1939SAndy Fiddaman break; 59*b30d1939SAndy Fiddaman return(chmod(path, mode)); 60*b30d1939SAndy Fiddaman } 61*b30d1939SAndy Fiddaman 62*b30d1939SAndy Fiddaman #endif 63