]> Savannah Git Hosting - gnulib.git/commitdiff
Make it possible to turn off the mkdir override on Windows.
authorBruno Haible <bruno@clisp.org>
Fri, 25 Dec 2020 17:39:47 +0000 (18:39 +0100)
committerBruno Haible <bruno@clisp.org>
Fri, 25 Dec 2020 17:39:47 +0000 (18:39 +0100)
* lib/sys_stat.in.h (mkdir): Conditionalize through GNULIB_MKDIR and
GNULIB_MDA_MKDIR. Also support GNULIB_POSIXCHECK.
* m4/sys_stat_h.m4 (gl_SYS_STAT_H_DEFAULTS): Initialize GNULIB_MKDIR,
GNULIB_MDA_MKDIR.
* modules/sys_stat (Makefile.am): Substitute GNULIB_MKDIR,
GNULIB_MDA_MKDIR.
* modules/mkdir (configure.ac): Invoke gl_SYS_STAT_MODULE_INDICATOR.
* doc/posix-functions/mkdir.texi: Mention also the 'sys_stat' module.

ChangeLog
doc/posix-functions/mkdir.texi
lib/sys_stat.in.h
m4/sys_stat_h.m4
modules/mkdir
modules/sys_stat

index 0322e099817b8882135b9803ca8b256aa977f7af..1b19c121e010881e904d4f3f46bd185c72de05e3 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
 2020-12-25  Bruno Haible  <bruno@clisp.org>
 
+       Make it possible to turn off the mkdir override on Windows.
+       * lib/sys_stat.in.h (mkdir): Conditionalize through GNULIB_MKDIR and
+       GNULIB_MDA_MKDIR. Also support GNULIB_POSIXCHECK.
+       * m4/sys_stat_h.m4 (gl_SYS_STAT_H_DEFAULTS): Initialize GNULIB_MKDIR,
+       GNULIB_MDA_MKDIR.
+       * modules/sys_stat (Makefile.am): Substitute GNULIB_MKDIR,
+       GNULIB_MDA_MKDIR.
+       * modules/mkdir (configure.ac): Invoke gl_SYS_STAT_MODULE_INDICATOR.
+       * doc/posix-functions/mkdir.texi: Mention also the 'sys_stat' module.
+
        Make it possible to turn off each of the Windows oldnames workarounds.
        * lib/fcntl.in.h (creat, open):  Conditionalize each of the Windows
        oldnames workarounds through a GNULIB_MDA_<func> symbol.
index 141d35d2898fe7c23d2bf83a0b5f7d1c7db25cea..1162947fac7c3a3cdfdabe91fc6be6422d7511e3 100644 (file)
@@ -4,21 +4,15 @@
 
 POSIX specification:@* @url{https://pubs.opengroup.org/onlinepubs/9699919799/functions/mkdir.html}
 
-Gnulib module: mkdir
+Gnulib module: sys_stat or mkdir
 
-Portability problems fixed by Gnulib:
+Portability problems fixed by either Gnulib module @code{sys_stat} or @code{mkdir}:
 @itemize
 @item
 This function is declared in different header files (namely, @code{<io.h>} or
 @code{<direct.h>}) on some platforms:
 mingw, MSVC 14.
 @item
-When the argument ends in a slash, the function call fails on some platforms.
-@item
-This function mistakenly succeeds on @samp{mkdir("d/./",mode)} on
-some platforms:
-Cygwin 1.5.x, mingw, MSVC 14.
-@item
 On Windows platforms (excluding Cygwin), this function is called @code{_mkdir}
 and takes only one argument.  The fix (without Gnulib) is to define a macro
 like this:
@@ -31,6 +25,16 @@ or
 @end smallexample
 @end itemize
 
+Portability problems fixed by Gnulib module @code{mkdir}:
+@itemize
+@item
+When the argument ends in a slash, the function call fails on some platforms.
+@item
+This function mistakenly succeeds on @samp{mkdir("d/./",mode)} on
+some platforms:
+Cygwin 1.5.x, mingw, MSVC 14.
+@end itemize
+
 Portability problems not fixed by Gnulib:
 @itemize
 @end itemize
index 4b4ec65a63a3a041a563e48eb71f2c61c249e9f5..faca52272a1ae095fe3831fed159e5de38fca0ef 100644 (file)
@@ -608,21 +608,20 @@ _GL_WARN_ON_USE (lstat, "lstat is unportable - "
 #endif
 
 
-#if @REPLACE_MKDIR@
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-#  undef mkdir
-#  define mkdir rpl_mkdir
-# endif
+#if @GNULIB_MKDIR@
+# if @REPLACE_MKDIR@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef mkdir
+#   define mkdir rpl_mkdir
+#  endif
 _GL_FUNCDECL_RPL (mkdir, int, (char const *name, mode_t mode)
-                              _GL_ARG_NONNULL ((1)));
+                               _GL_ARG_NONNULL ((1)));
 _GL_CXXALIAS_RPL (mkdir, int, (char const *name, mode_t mode));
-#else
+# elif defined _WIN32 && !defined __CYGWIN__
 /* mingw's _mkdir() function has 1 argument, but we pass 2 arguments.
    Additionally, it declares _mkdir (and depending on compile flags, an
    alias mkdir), only in the nonstandard includes <direct.h> and <io.h>,
    which are included above.  */
-# if defined _WIN32 && ! defined __CYGWIN__
-
 #  if !GNULIB_defined_rpl_mkdir
 static int
 rpl_mkdir (char const *name, mode_t mode)
@@ -631,16 +630,44 @@ rpl_mkdir (char const *name, mode_t mode)
 }
 #   define GNULIB_defined_rpl_mkdir 1
 #  endif
-
 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef mkdir
 #   define mkdir rpl_mkdir
 #  endif
 _GL_CXXALIAS_RPL (mkdir, int, (char const *name, mode_t mode));
 # else
 _GL_CXXALIAS_SYS (mkdir, int, (char const *name, mode_t mode));
 # endif
-#endif
 _GL_CXXALIASWARN (mkdir);
+#elif defined GNULIB_POSIXCHECK
+# undef mkdir
+# if HAVE_RAW_DECL_MKDIR
+_GL_WARN_ON_USE (mkdir, "mkdir does not always support two parameters - "
+                 "use gnulib module mkdir for portability");
+# endif
+#elif @GNULIB_MDA_MKDIR@
+/* On native Windows, map 'mkdir' to '_mkdir', so that -loldnames is not
+   required.  In C++ with GNULIB_NAMESPACE, avoid differences between
+   platforms by defining GNULIB_NAMESPACE::mkdir always.  */
+# if defined _WIN32 && !defined __CYGWIN__
+#  if !GNULIB_defined_rpl_mkdir
+static int
+rpl_mkdir (char const *name, mode_t mode)
+{
+  return _mkdir (name);
+}
+#   define GNULIB_defined_rpl_mkdir 1
+#  endif
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef mkdir
+#   define mkdir rpl_mkdir
+#  endif
+_GL_CXXALIAS_RPL (mkdir, int, (char const *name, mode_t mode));
+# else
+_GL_CXXALIAS_SYS (mkdir, int, (char const *name, mode_t mode));
+# endif
+_GL_CXXALIASWARN (mkdir);
+#endif
 
 
 #if @GNULIB_MKDIRAT@
index a1cb9887075572cf6227f419d62176706211064e..14b72db3f883a25fb1d8d415187c5ebc3a810974 100644 (file)
@@ -1,4 +1,4 @@
-# sys_stat_h.m4 serial 35   -*- Autoconf -*-
+# sys_stat_h.m4 serial 36   -*- Autoconf -*-
 dnl Copyright (C) 2006-2020 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -71,6 +71,7 @@ AC_DEFUN([gl_SYS_STAT_H_DEFAULTS],
   GNULIB_GETUMASK=0;    AC_SUBST([GNULIB_GETUMASK])
   GNULIB_LCHMOD=0;      AC_SUBST([GNULIB_LCHMOD])
   GNULIB_LSTAT=0;       AC_SUBST([GNULIB_LSTAT])
+  GNULIB_MKDIR=0;       AC_SUBST([GNULIB_MKDIR])
   GNULIB_MKDIRAT=0;     AC_SUBST([GNULIB_MKDIRAT])
   GNULIB_MKFIFO=0;      AC_SUBST([GNULIB_MKFIFO])
   GNULIB_MKFIFOAT=0;    AC_SUBST([GNULIB_MKFIFOAT])
@@ -81,6 +82,7 @@ AC_DEFUN([gl_SYS_STAT_H_DEFAULTS],
   GNULIB_OVERRIDES_STRUCT_STAT=0; AC_SUBST([GNULIB_OVERRIDES_STRUCT_STAT])
   dnl Support Microsoft deprecated alias function names by default.
   GNULIB_MDA_CHMOD=1;   AC_SUBST([GNULIB_MDA_CHMOD])
+  GNULIB_MDA_MKDIR=1;   AC_SUBST([GNULIB_MDA_MKDIR])
   GNULIB_MDA_UMASK=1;   AC_SUBST([GNULIB_MDA_UMASK])
   dnl Assume proper GNU behavior unless another module says otherwise.
   HAVE_FCHMODAT=1;      AC_SUBST([HAVE_FCHMODAT])
index 2f1850c61bc638251af04abd8a5e8995832aceb6..fb24458a9ae778a53075f2196232803fe21d56ec 100644 (file)
@@ -15,6 +15,7 @@ gl_FUNC_MKDIR
 if test $REPLACE_MKDIR = 1; then
   AC_LIBOBJ([mkdir])
 fi
+gl_SYS_STAT_MODULE_INDICATOR([mkdir])
 
 Makefile.am:
 
index 6bf6b2998d48dd218345f2c2ebb70d55d734745c..8a9adb5813f81e1330cd9106dd7700547d6bd654 100644 (file)
@@ -42,6 +42,7 @@ sys/stat.h: sys_stat.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNU
              -e 's/@''GNULIB_GETUMASK''@/$(GNULIB_GETUMASK)/g' \
              -e 's/@''GNULIB_LCHMOD''@/$(GNULIB_LCHMOD)/g' \
              -e 's/@''GNULIB_LSTAT''@/$(GNULIB_LSTAT)/g' \
+             -e 's/@''GNULIB_MKDIR''@/$(GNULIB_MKDIR)/g' \
              -e 's/@''GNULIB_MKDIRAT''@/$(GNULIB_MKDIRAT)/g' \
              -e 's/@''GNULIB_MKFIFO''@/$(GNULIB_MKFIFO)/g' \
              -e 's/@''GNULIB_MKFIFOAT''@/$(GNULIB_MKFIFOAT)/g' \
@@ -51,6 +52,7 @@ sys/stat.h: sys_stat.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNU
              -e 's/@''GNULIB_UTIMENSAT''@/$(GNULIB_UTIMENSAT)/g' \
              -e 's/@''GNULIB_OVERRIDES_STRUCT_STAT''@/$(GNULIB_OVERRIDES_STRUCT_STAT)/g' \
              -e 's/@''GNULIB_MDA_CHMOD''@/$(GNULIB_MDA_CHMOD)/g' \
+             -e 's/@''GNULIB_MDA_MKDIR''@/$(GNULIB_MDA_MKDIR)/g' \
              -e 's/@''GNULIB_MDA_UMASK''@/$(GNULIB_MDA_UMASK)/g' \
              -e 's|@''HAVE_FCHMODAT''@|$(HAVE_FCHMODAT)|g' \
              -e 's|@''HAVE_FSTATAT''@|$(HAVE_FSTATAT)|g' \