]> code.delx.au - gnu-emacs/commitdiff
* config.h.in: Add #undefs for HAVE_MKDIR and HAVE_RMDIR, for
authorJim Blandy <jimb@redhat.com>
Tue, 3 Aug 1993 07:02:38 +0000 (07:02 +0000)
committerJim Blandy <jimb@redhat.com>
Tue, 3 Aug 1993 07:02:38 +0000 (07:02 +0000)
configure to edit.
* sysdep.c [not HAVE_MKDIR] (mkdir): New function, taken from tar,
for use on systems lacking the mkdir function.
[not HAVE_RMDIR] (rmdir): New function, taken from tar, for use on
systems lacking the rmdir function.

src/config.in
src/sysdep.c

index 7b19feef5a9eced4b311093d549295b945c8e8b9..dafb759749a1844ded987d476dfa8fa450459925 100644 (file)
@@ -113,8 +113,9 @@ and this notice must be preserved on all copies.  */
 #undef HAVE_XRMSETDATABASE
 #undef HAVE_XSCREENRESOURCESTRING
 
+#undef HAVE_MKDIR
+#undef HAVE_RMDIR
 #undef HAVE_RANDOM
-
 #undef HAVE_BCOPY
 
 #undef HAVE_AIX_SMT_EXP
index 3cc0a8cf8019dec472a666e26fcb413e9eef61da..d765fa79ec24535a41bc4e5b9ba953a0a67d6f58 100644 (file)
@@ -3091,6 +3091,118 @@ readdirver (dirp)
 #endif /* VMS */
 
 #endif /* NONSYSTEM_DIR_LIBRARY */
+
+\f
+/* mkdir and rmdir functions, for systems which don't have them.  */
+
+#ifndef HAVE_MKDIR
+/*
+ * Written by Robert Rother, Mariah Corporation, August 1985.
+ *
+ * If you want it, it's yours.  All I ask in return is that if you
+ * figure out how to do this in a Bourne Shell script you send me
+ * a copy.
+ *                                     sdcsvax!rmr or rmr@uscd
+ *
+ * Severely hacked over by John Gilmore to make a 4.2BSD compatible
+ * subroutine. 11Mar86; hoptoad!gnu
+ *
+ * Modified by rmtodd@uokmax 6-28-87 -- when making an already existing dir,
+ * subroutine didn't return EEXIST.  It does now.
+ */
+
+/*
+ * Make a directory.
+ */
+int
+mkdir (dpath, dmode)
+     char *dpath;
+     int dmode;
+{
+  int cpid, status;
+  struct stat statbuf;
+
+  if (stat (dpath, &statbuf) == 0)
+    {
+      errno = EEXIST;          /* Stat worked, so it already exists */
+      return -1;
+    }
+
+  /* If stat fails for a reason other than non-existence, return error */
+  if (errno != ENOENT)
+    return -1;
+
+  switch (cpid = fork ())
+    {
+
+    case -1:                   /* Error in fork() */
+      return (-1);             /* Errno is set already */
+
+    case 0:                    /* Child process */
+      /*
+                * Cheap hack to set mode of new directory.  Since this
+                * child process is going away anyway, we zap its umask.
+                * FIXME, this won't suffice to set SUID, SGID, etc. on this
+                * directory.  Does anybody care?
+                */
+      status = umask (0);      /* Get current umask */
+      status = umask (status | (0777 & ~dmode));       /* Set for mkdir */
+      execl ("/bin/mkdir", "mkdir", dpath, (char *) 0);
+      _exit (-1);              /* Can't exec /bin/mkdir */
+
+    default:                   /* Parent process */
+      while (cpid != wait (&status));  /* Wait for kid to finish */
+    }
+
+  if (WIFSIGNALED (status) || WEXITSTATUS (status) != 0)
+    {
+      errno = EIO;             /* We don't know why, but */
+      return -1;               /* /bin/mkdir failed */
+    }
+
+  return 0;
+}
+#endif /* not HAVE_MKDIR */
+
+#ifndef HAVE_RMDIR
+int
+rmdir (dpath)
+     char *dpath;
+{
+  int cpid, status;
+  struct stat statbuf;
+
+  if (stat (dpath, &statbuf) != 0)
+    {
+      /* Stat just set errno.  We don't have to */
+      return -1;
+    }
+
+  switch (cpid = fork ())
+    {
+
+    case -1:                   /* Error in fork() */
+      return (-1);             /* Errno is set already */
+
+    case 0:                    /* Child process */
+      execl ("/bin/rmdir", "rmdir", dpath, (char *) 0);
+      _exit (-1);              /* Can't exec /bin/mkdir */
+
+    default:                   /* Parent process */
+      while (cpid != wait (&status));  /* Wait for kid to finish */
+    }
+
+  if (WIFSIGNALED (status) || WEXITSTATUS (status) != 0)
+    {
+      errno = EIO;             /* We don't know why, but */
+      return -1;               /* /bin/mkdir failed */
+    }
+
+  return 0;
+}
+#endif /* !HAVE_RMDIR */
+
+
 \f
 /* Functions for VMS */
 #ifdef VMS