.
[gnulib.git] / lib / makepath.c
index b592116..028e172 100644 (file)
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
+   along with this program; if not, write to the Free Software Foundation,
+   Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 
-/* Written by David MacKenzie <djm@gnu.ai.mit.edu> and
-   Jim Meyering <meyering@cs.utexas.edu>.  */
+/* Written by David MacKenzie <djm@gnu.ai.mit.edu> and Jim Meyering.  */
 
-#ifdef HAVE_CONFIG_H
-#include <config.h>
+#if HAVE_CONFIG_H
+# include <config.h>
 #endif
 
-#ifdef __GNUC__
-#define alloca __builtin_alloca
+#if __GNUC__
+# define alloca __builtin_alloca
 #else
-#ifdef HAVE_ALLOCA_H
-#include <alloca.h>
-#else
-#ifdef _AIX
+# if HAVE_ALLOCA_H
+#  include <alloca.h>
+# else
+#  ifdef _AIX
  #pragma alloca
-#else
+#  else
 char *alloca ();
-#endif
-#endif
+#  endif
+# endif
 #endif
 
 #include <stdio.h>
 #include <sys/types.h>
 #include <sys/stat.h>
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
+#if HAVE_UNISTD_H
+# include <unistd.h>
 #endif
 
-#ifdef STAT_MACROS_BROKEN
-#undef S_ISDIR
-#endif /* STAT_MACROS_BROKEN.  */
+#if STAT_MACROS_BROKEN
+# undef S_ISDIR
+#endif
 
 #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 <stdlib.h>
+#if STDC_HEADERS
+# include <stdlib.h>
 #endif
 
-#ifdef HAVE_ERRNO_H
-#include <errno.h>
+#if HAVE_ERRNO_H
+# include <errno.h>
 #endif
 
-#ifndef STDC_HEADERS
+#ifndef errno
 extern int errno;
 #endif
 
-#if defined(STDC_HEADERS) || defined(HAVE_STRING_H)
-#include <string.h>
-#ifndef index
-#define index strchr
-#endif
+#if HAVE_STRING_H
+# include <string.h>
 #else
-#include <strings.h>
+# include <strings.h>
+# ifndef strchr
+#  define strchr index
+# endif
 #endif
 
 #ifdef __MSDOS__
@@ -78,7 +77,7 @@ typedef int gid_t;
 #endif
 
 #include "makepath.h"
-#include "safe-stat.h"
+
 void error ();
 
 /* Ensure that the directory ARGPATH exists.
@@ -99,7 +98,7 @@ void error ();
    Return 0 if ARGPATH exists as a directory with the proper
    ownership and permissions when done, otherwise 1.  */
 
-#if defined (__GNUC__) || (defined (__STDC__) && __STDC__)
+#if __STDC__
 int
 make_path (const char *argpath,
           int mode,
@@ -131,7 +130,7 @@ make_path (argpath, mode, parent_mode, owner, group, preserve_existing,
   dirpath = (char *) alloca (strlen (argpath) + 1);
   strcpy (dirpath, argpath);
 
-  if (SAFE_STAT (dirpath, &stats))
+  if (stat (dirpath, &stats))
     {
       char *slash;
       int tmp_mode;            /* Initial perms for leading dirs.  */
@@ -162,10 +161,10 @@ make_path (argpath, mode, parent_mode, owner, group, preserve_existing,
       slash = dirpath;
       while (*slash == '/')
        slash++;
-      while ((slash = index (slash, '/')))
+      while ((slash = strchr (slash, '/')))
        {
          *slash = '\0';
-         if (SAFE_STAT (dirpath, &stats))
+         if (stat (dirpath, &stats))
            {
              if (mkdir (dirpath, tmp_mode))
                {
@@ -219,7 +218,7 @@ make_path (argpath, mode, parent_mode, owner, group, preserve_existing,
       /* 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))
+      if (stat (dirpath, &stats) && mkdir (dirpath, mode))
        {
          error (0, errno, "cannot create directory `%s'", dirpath);
          umask (oldmask);