+#ifndef S_ISGID
+# define S_ISGID 02000
+#endif
+#ifndef S_ISVTX
+# define S_ISVTX 01000
+#endif
+#ifndef S_IRUSR
+# define S_IRUSR 0200
+#endif
+#ifndef S_IWUSR
+# define S_IWUSR 0200
+#endif
+#ifndef S_IXUSR
+# define S_IXUSR 0100
+#endif
+
+#ifndef S_IRWXU
+# define S_IRWXU (S_IRUSR | S_IWUSR | S_IXUSR)
+#endif
+
+#define WX_USR (S_IWUSR | S_IXUSR)
+
+/* Include this before libintl.h so we get our definition of PARAMS. */
+#include "makepath.h"
+
+#include "gettext.h"
+#define _(msgid) gettext (msgid)
+
+#include "save-cwd.h"
+#include "dirname.h"
+#include "error.h"
+#include "quote.h"
+
+#define CLEANUP_CWD \
+ do \
+ { \
+ /* We're done operating on basename_dir. \
+ Restore working directory. */ \
+ if (do_chdir) \
+ { \
+ int _fail = restore_cwd (&cwd, NULL, NULL); \
+ free_cwd (&cwd); \
+ if (_fail) \
+ return 1; \
+ } \
+ } \
+ while (0)
+
+#define CLEANUP \
+ do \
+ { \
+ umask (oldmask); \
+ CLEANUP_CWD; \
+ } \
+ while (0)
+
+/* Attempt to create directory DIR (aka DIRPATH) with the specified MODE.
+ If CREATED_DIR_P is non-NULL, set *CREATED_DIR_P to non-zero if this
+ function creates DIR and to zero otherwise. Give a diagnostic and
+ return non-zero if DIR cannot be created or cannot be determined to
+ exist already. Use DIRPATH in any diagnostic, not DIR.
+ Note that if DIR already exists, this function returns zero
+ (indicating success) and sets *CREATED_DIR_P to zero. */
+
+int
+make_dir (const char *dir, const char *dirpath, mode_t mode, int *created_dir_p)
+{
+ int fail = 0;
+ int created_dir;
+
+ created_dir = (mkdir (dir, mode) == 0);