Fix compilation errors related to rpl_mkdir on mingw.
authorBruno Haible <bruno@clisp.org>
Mon, 21 Apr 2008 21:57:39 +0000 (23:57 +0200)
committerBruno Haible <bruno@clisp.org>
Mon, 21 Apr 2008 21:57:39 +0000 (23:57 +0200)
ChangeLog
lib/mkdir.c
lib/sys_stat.in.h
m4/mkdir-slash.m4
m4/sys_stat_h.m4
modules/sys_stat

index e7d624b473217ae960e34133b98e0a0725ec23ed..cbbf085a4fdfcbbf41e4241900aa94e7f5116e81 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+2008-04-20  Bruno Haible  <bruno@clisp.org>
+
+       * lib/mkdir.c (mkdir): Undefine after the includes, not right after
+       config.h. Provide _mkdir based fallback for mingw.
+       * lib/sys_stat.in.h (mkdir): Define through an 'extern' declaration
+       if REPLACE_MKDIR is 1. Otherwise, test for mingw directly.
+       * m4/mkdir-slash.m4 (gl_FUNC_MKDIR_TRAILING_SLASH): Require
+       gl_SYS_STAT_H_DEFAULTS. When doing the replacement, set REPLACE_MKDIR
+       rather than defining mkdir in config.h.
+       * m4/sys_stat_h.m4 (gl_SYS_STAT_MODULE_INDICATOR): New macro.
+       (gl_SYS_STAT_H_DEFAULTS): New macro.
+       (gl_HEADER_SYS_STAT_H): Require it. Don't set HAVE_DECL_MKDIR and
+       HAVE_IO_H any more.
+       * modules/sys_stat (Makefile.am): Substitute REPLACE_MKDIR instead of
+       HAVE_DECL_MKDIR and HAVE_IO_H.
+
 2008-04-20  Bruno Haible  <bruno@clisp.org>
 
        * lib/isapipe.c: Port to native Windows platforms.
index 602da417f48eb860c71930ca18d0b89f48876d65..8073dc8da402da6e21d7bc59a1e732fefdd782ac 100644 (file)
@@ -1,7 +1,7 @@
 /* On some systems, mkdir ("foo/", 0700) fails because of the trailing
    slash.  On those systems, this wrapper removes the trailing slash.
 
-   Copyright (C) 2001, 2003, 2006 Free Software Foundation, Inc.
+   Copyright (C) 2001, 2003, 2006, 2008 Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
 
 #include <config.h>
 
-/* Disable the definition of mkdir to rpl_mkdir (from config.h) in this
-   file.  Otherwise, we'd get conflicting prototypes for rpl_mkdir on
-   most systems.  */
-#undef mkdir
-
+/* Specification.  */
 #include <sys/types.h>
 #include <sys/stat.h>
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include "dirname.h"
 #include "xalloc.h"
 
+/* Disable the definition of mkdir to rpl_mkdir (from the <sys/stat.h>
+   substitute) in this file.  Otherwise, we'd get an endless recursion.  */
+#undef mkdir
+
+/* 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 io.h.  */
+#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+# define mkdir(name,mode) _mkdir (name)
+#endif
+
 /* This function is required at least for NetBSD 1.5.2.  */
 
 int
index 2e411cd3c6b33e1463ff3d659f82213a905986dc..34ff96253ece8011b1c80c24e55da1b523bae62f 100644 (file)
@@ -1,5 +1,5 @@
 /* Provide a more complete sys/stat header file.
-   Copyright (C) 2006, 2007 Free Software Foundation, Inc.
+   Copyright (C) 2006-2008 Free Software Foundation, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
 #ifndef _GL_SYS_STAT_H
 #define _GL_SYS_STAT_H
 
+/* Before doing "#define mkdir rpl_mkdir" below, we need to include all
+   headers that may declare mkdir().  */
+#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+# include <io.h>
+#endif
+
 #ifndef S_IFMT
 # define S_IFMT 0170000
 #endif
 # define lstat stat
 #endif
 
+#if @REPLACE_MKDIR@
+# undef mkdir
+# define mkdir rpl_mkdir
+extern int mkdir (char const *name, mode_t mode);
+#else
 /* 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 io.h.  */
-#if ! @HAVE_DECL_MKDIR@ && @HAVE_IO_H@
-# include <io.h>
+   alias mkdir), only in the nonstandard <io.h>, which is included above.  */
+# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
 
 static inline int
 rpl_mkdir (char const *name, mode_t mode)
@@ -273,7 +283,8 @@ rpl_mkdir (char const *name, mode_t mode)
   return _mkdir (name);
 }
 
-# define mkdir rpl_mkdir
+#  define mkdir rpl_mkdir
+# endif
 #endif
 
 #endif /* _GL_SYS_STAT_H */
index 3c25d2af9a936fc1fdcf0c1f28b8ad198db1e38c..f3d8e8a576634933493481d34dffeb4700471c0a 100644 (file)
@@ -1,6 +1,6 @@
-#serial 5
+#serial 6
 
-# Copyright (C) 2001, 2003, 2004, 2006 Free Software Foundation, Inc.
+# Copyright (C) 2001, 2003, 2004, 2006, 2008 Free Software Foundation, Inc.
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
 # with or without modifications, as long as this notice is preserved.
@@ -10,6 +10,7 @@
 # trailing slashes.
 AC_DEFUN([gl_FUNC_MKDIR_TRAILING_SLASH],
 [dnl
+  AC_REQUIRE([gl_SYS_STAT_H_DEFAULTS])
   AC_CHECK_HEADERS_ONCE(unistd.h)
   AC_CACHE_CHECK([whether mkdir fails due to a trailing slash],
     gl_cv_func_mkdir_trailing_slash_bug,
@@ -37,9 +38,8 @@ AC_DEFUN([gl_FUNC_MKDIR_TRAILING_SLASH],
   )
 
   if test $gl_cv_func_mkdir_trailing_slash_bug = yes; then
+    REPLACE_MKDIR=1
     AC_LIBOBJ(mkdir)
-    AC_DEFINE(mkdir, rpl_mkdir,
-      [Define to rpl_mkdir if the replacement function should be used.])
     gl_PREREQ_MKDIR
   fi
 ])
index 8e66eb023e91fd9037d3073195fc392d30505e80..cfe80110c64665a4dc3d819669c687461cd314c3 100644 (file)
@@ -1,4 +1,4 @@
-# sys_stat_h.m4 serial 7   -*- Autoconf -*-
+# sys_stat_h.m4 serial 8   -*- Autoconf -*-
 dnl Copyright (C) 2006-2008 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -9,6 +9,8 @@ dnl Test whether <sys/stat.h> contains lstat and mkdir or must be substituted.
 
 AC_DEFUN([gl_HEADER_SYS_STAT_H],
 [
+  AC_REQUIRE([gl_SYS_STAT_H_DEFAULTS])
+
   dnl Check for lstat.  Systems that lack it (mingw) also lack symlinks, so
   dnl stat is a good replacement.
   AC_CHECK_FUNCS_ONCE([lstat])
@@ -19,24 +21,7 @@ AC_DEFUN([gl_HEADER_SYS_STAT_H],
   fi
   AC_SUBST([HAVE_LSTAT])
 
-  dnl Check for mkdir.  Mingw has _mkdir(name) in the nonstandard <io.h>
-  dnl instead.
-  AC_CHECK_DECLS([mkdir],
-    [],
-    [AC_CHECK_HEADERS([io.h])],
-    [#include <sys/stat.h>])
-  if test $ac_cv_have_decl_mkdir = yes; then
-    HAVE_DECL_MKDIR=1
-  else
-    HAVE_DECL_MKDIR=0
-  fi
-  AC_SUBST([HAVE_DECL_MKDIR])
-  if test "$ac_cv_header_io_h" = yes; then
-    HAVE_IO_H=1
-  else
-    HAVE_IO_H=0
-  fi
-  AC_SUBST([HAVE_IO_H])
+  dnl For the mkdir substitute.
   AC_REQUIRE([AC_C_INLINE])
 
   dnl Check for broken stat macros.
@@ -55,3 +40,16 @@ AC_DEFUN([gl_HEADER_SYS_STAT_H],
      #include <sys/stat.h>])
 
 ]) # gl_HEADER_SYS_STAT_H
+
+AC_DEFUN([gl_SYS_STAT_MODULE_INDICATOR],
+[
+  dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
+  AC_REQUIRE([gl_SYS_STAT_H_DEFAULTS])
+  GNULIB_[]m4_translit([$1],[abcdefghijklmnopqrstuvwxyz./-],[ABCDEFGHIJKLMNOPQRSTUVWXYZ___])=1
+])
+
+AC_DEFUN([gl_SYS_STAT_H_DEFAULTS],
+[
+  dnl Assume proper GNU behavior unless another module says otherwise.
+  REPLACE_MKDIR=0; AC_SUBST([REPLACE_MKDIR])
+])
index 364c71b39a6abaa6c0eff892e866739c9e355e9a..bb3510fe400fd7d3497f5156c1cce859da207d25 100644 (file)
@@ -23,9 +23,8 @@ sys/stat.h: sys_stat.in.h
        { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
          sed -e 's/@''INCLUDE_NEXT''@/$(INCLUDE_NEXT)/g' \
              -e 's|@''NEXT_SYS_STAT_H''@|$(NEXT_SYS_STAT_H)|g' \
-             -e 's|@''HAVE_IO_H''@|$(HAVE_IO_H)|g' \
              -e 's|@''HAVE_LSTAT''@|$(HAVE_LSTAT)|g' \
-             -e 's|@''HAVE_DECL_MKDIR''@|$(HAVE_DECL_MKDIR)|g' \
+             -e 's|@''REPLACE_MKDIR''@|$(REPLACE_MKDIR)|g' \
              < $(srcdir)/sys_stat.in.h; \
        } > $@-t
        mv $@-t $@