X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fmakepath.c;h=f0303fa8f5de78c900cb6ca6d237205d42de3d87;hb=5b60c6dfee0e445f95117a760622cd33944119d8;hp=4c19630e661a782ab1f520338e05a4ffee3aefed;hpb=d7b5315b0e0d2ebba292ccf0de92fd0e7a2123e8;p=gnulib.git diff --git a/lib/makepath.c b/lib/makepath.c index 4c19630e6..f0303fa8f 100644 --- a/lib/makepath.c +++ b/lib/makepath.c @@ -18,6 +18,10 @@ /* Written by David MacKenzie and Jim Meyering . */ +#ifdef HAVE_CONFIG_H +#include +#endif + #ifdef __GNUC__ #define alloca __builtin_alloca #else @@ -38,14 +42,24 @@ char *alloca (); #ifdef HAVE_UNISTD_H #include #endif + +#ifdef STAT_MACROS_BROKEN +#undef S_ISDIR +#endif /* STAT_MACROS_BROKEN. */ + #if !defined(S_ISDIR) && defined(S_IFDIR) -#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) +#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) #endif #ifdef STDC_HEADERS -#include #include -#else +#endif + +#ifdef HAVE_ERRNO_H +#include +#endif + +#ifndef STDC_HEADERS extern int errno; #endif @@ -63,6 +77,7 @@ typedef int uid_t; typedef int gid_t; #endif +#include "safe-stat.h" void error (); /* Ensure that the directory ARGPATH exists. @@ -98,7 +113,7 @@ make_path (argpath, mode, parent_mode, owner, group, verbose_fmt_string) dirpath = (char *) alloca (strlen (argpath) + 1); strcpy (dirpath, argpath); - if (stat (dirpath, &stats)) + if (SAFE_STAT (dirpath, &stats)) { char *slash; int tmp_mode; /* Initial perms for leading dirs. */ @@ -132,7 +147,7 @@ make_path (argpath, mode, parent_mode, owner, group, verbose_fmt_string) while ((slash = index (slash, '/'))) { *slash = '\0'; - if (stat (dirpath, &stats)) + if (SAFE_STAT (dirpath, &stats)) { if (mkdir (dirpath, tmp_mode)) { @@ -147,7 +162,7 @@ make_path (argpath, mode, parent_mode, owner, group, verbose_fmt_string) if (owner != (uid_t) -1 && group != (gid_t) -1 && chown (dirpath, owner, group) -#ifdef AFS +#if defined(AFS) && defined (EPERM) && errno != EPERM #endif ) @@ -183,7 +198,10 @@ make_path (argpath, mode, parent_mode, owner, group, verbose_fmt_string) /* We're done making leading directories. Make the final component of the path. */ - if (mkdir (dirpath, mode)) + /* The path could end in "/." or contain "/..", so test + if we really have to create the directory. */ + + if (SAFE_STAT (dirpath, &stats) && mkdir (dirpath, mode)) { error (0, errno, "cannot make directory `%s'", dirpath); umask (oldmask);