Hi, On mingw, I get these compilation warnings and errors:
mkdir.c: In function `rpl_mkdir': mkdir.c:56: warning: implicit declaration of function `mkdir' mkdir-p.c: In function `make_dir_parents': mkdir-p.c:131: error: too many arguments to function `rpl_mkdir' make[3]: *** [mkdir-p.o] Error 1 mkdirat: In file included from mkdirat.c:42: at-func.c: In function `mkdirat': at-func.c:38: error: too many arguments to function `rpl_mkdir' at-func.c:38: error: too many arguments to function `rpl_mkdir' at-func.c:45: error: too many arguments to function `rpl_mkdir' at-func.c:45: error: too many arguments to function `rpl_mkdir' at-func.c:73: error: too many arguments to function `rpl_mkdir' at-func.c:73: error: too many arguments to function `rpl_mkdir' make[3]: *** [mkdirat.o] Error 1 tempname: tempname.c: In function `gen_tempname': tempname.c:277: error: too many arguments to function `rpl_mkdir' make[3]: *** [tempname.o] Error 1 Recall that the declaration of mkdir in <io.h> on mingw has 1 argument, whereas the POSIX replacement must have 2 arguments. The trouble comes because gnulib has two different replacements for mkdir, one in module 'sys_stat' for mingw and one in module 'mkdir'. The latter puts a '#define mkdir rpl_mkdir' into <config.h> (because its test program doesn't compile, due to the different argument counts). Later, when <fcntl.h>, <dirent.h>, or <unistd.h> is included, it includes <io.h> and thus declares rpl_mkdir (not mkdir!) to have 1 argument. Additionally, in the config I got (mingw cross from cygwin), HAVE_DECL_MKDIR is 1, which disables the rpl_mkdir definition in sys_stat.in.h. A bug here too, because the comment says that mkdir is defined depending on compilation flags - but we _always_ need this rpl_mkdir on mingw. It will be more maintainable here to use a hardcoded test for mingw, rather than to test whether mkdir is declared. OK to commit this fix (assuming it passes my tests tomorrow)? 2008-04-20 Bruno Haible <[EMAIL PROTECTED]> * 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. *** lib/mkdir.c.orig 2008-04-20 15:29:30.000000000 +0200 --- lib/mkdir.c 2008-04-20 15:24:38.000000000 +0200 *************** *** 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. 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 --- 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, 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 *************** *** 20,32 **** #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 ! #include <sys/types.h> #include <sys/stat.h> #include <stdio.h> #include <stdlib.h> #include <string.h> --- 20,29 ---- #include <config.h> ! /* Specification. */ #include <sys/types.h> #include <sys/stat.h> + #include <stdio.h> #include <stdlib.h> #include <string.h> *************** *** 34,39 **** --- 31,47 ---- #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 *** lib/sys_stat.in.h.orig 2008-04-20 15:29:30.000000000 +0200 --- lib/sys_stat.in.h 2008-04-20 15:27:34.000000000 +0200 *************** *** 1,5 **** /* Provide a more complete sys/stat header file. ! Copyright (C) 2006, 2007 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 --- 1,5 ---- /* Provide a more complete sys/stat header file. ! 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 *************** *** 261,271 **** # define lstat stat #endif /* 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> static inline int rpl_mkdir (char const *name, mode_t mode) --- 261,276 ---- # 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 (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ ! # include <io.h> static inline int rpl_mkdir (char const *name, mode_t mode) *************** *** 273,279 **** return _mkdir (name); } ! # define mkdir rpl_mkdir #endif #endif /* _GL_SYS_STAT_H */ --- 278,285 ---- return _mkdir (name); } ! # define mkdir rpl_mkdir ! # endif #endif #endif /* _GL_SYS_STAT_H */ *** m4/mkdir-slash.m4.orig 2008-04-20 15:29:30.000000000 +0200 --- m4/mkdir-slash.m4 2008-04-20 15:18:30.000000000 +0200 *************** *** 1,6 **** ! #serial 5 ! # Copyright (C) 2001, 2003, 2004, 2006 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. --- 1,6 ---- ! #serial 6 ! # 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,15 **** --- 10,16 ---- # 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,45 **** ) if test $gl_cv_func_mkdir_trailing_slash_bug = yes; then AC_LIBOBJ(mkdir) - AC_DEFINE(mkdir, rpl_mkdir, - [Define to rpl_mkdir if the replacement function should be used.]) gl_PREREQ_MKDIR fi ]) --- 38,45 ---- ) if test $gl_cv_func_mkdir_trailing_slash_bug = yes; then + REPLACE_MKDIR=1 AC_LIBOBJ(mkdir) gl_PREREQ_MKDIR fi ]) *** m4/sys_stat_h.m4.orig 2008-04-20 15:29:30.000000000 +0200 --- m4/sys_stat_h.m4 2008-04-20 15:26:03.000000000 +0200 *************** *** 1,4 **** ! # sys_stat_h.m4 serial 7 -*- 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, --- 1,4 ---- ! # 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,14 **** --- 9,16 ---- 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,42 **** 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]) AC_REQUIRE([AC_C_INLINE]) dnl Check for broken stat macros. --- 21,27 ---- fi AC_SUBST([HAVE_LSTAT]) ! dnl For the mkdir substitute. AC_REQUIRE([AC_C_INLINE]) dnl Check for broken stat macros. *************** *** 55,57 **** --- 40,55 ---- #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]) + ]) *** modules/sys_stat.orig 2008-04-20 15:29:30.000000000 +0200 --- modules/sys_stat 2008-04-20 15:19:18.000000000 +0200 *************** *** 23,31 **** { 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' \ < $(srcdir)/sys_stat.in.h; \ } > [EMAIL PROTECTED] mv [EMAIL PROTECTED] $@ --- 23,30 ---- { 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_LSTAT''@|$(HAVE_LSTAT)|g' \ ! -e 's|@''REPLACE_MKDIR''@|$(REPLACE_MKDIR)|g' \ < $(srcdir)/sys_stat.in.h; \ } > [EMAIL PROTECTED] mv [EMAIL PROTECTED] $@