From bfca3459b4916724328bc9779cbc4e5934417c09 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Mon, 21 Apr 2008 23:57:39 +0200 Subject: [PATCH] Fix compilation errors related to rpl_mkdir on mingw. --- ChangeLog | 16 ++++++++++++++++ lib/mkdir.c | 20 ++++++++++++++------ lib/sys_stat.in.h | 21 ++++++++++++++++----- m4/mkdir-slash.m4 | 8 ++++---- m4/sys_stat_h.m4 | 36 +++++++++++++++++------------------- modules/sys_stat | 3 +-- 6 files changed, 68 insertions(+), 36 deletions(-) diff --git a/ChangeLog b/ChangeLog index e7d624b473..cbbf085a4f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,19 @@ +2008-04-20 Bruno Haible + + * 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 * lib/isapipe.c: Port to native Windows platforms. diff --git a/lib/mkdir.c b/lib/mkdir.c index 602da417f4..8073dc8da4 100644 --- a/lib/mkdir.c +++ b/lib/mkdir.c @@ -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 @@ -20,13 +20,10 @@ #include -/* 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 #include + #include #include #include @@ -34,6 +31,17 @@ #include "dirname.h" #include "xalloc.h" +/* Disable the definition of mkdir to rpl_mkdir (from the + 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 diff --git a/lib/sys_stat.in.h b/lib/sys_stat.in.h index 2e411cd3c6..34ff96253e 100644 --- a/lib/sys_stat.in.h +++ b/lib/sys_stat.in.h @@ -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 @@ -29,6 +29,12 @@ #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 +#endif + #ifndef S_IFMT # define S_IFMT 0170000 #endif @@ -261,11 +267,15 @@ # 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 + alias mkdir), only in the nonstandard , 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 */ diff --git a/m4/mkdir-slash.m4 b/m4/mkdir-slash.m4 index 3c25d2af9a..f3d8e8a576 100644 --- a/m4/mkdir-slash.m4 +++ b/m4/mkdir-slash.m4 @@ -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 ]) diff --git a/m4/sys_stat_h.m4 b/m4/sys_stat_h.m4 index 8e66eb023e..cfe80110c6 100644 --- a/m4/sys_stat_h.m4 +++ b/m4/sys_stat_h.m4 @@ -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 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 - dnl instead. - AC_CHECK_DECLS([mkdir], - [], - [AC_CHECK_HEADERS([io.h])], - [#include ]) - 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 ]) ]) # 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]) +]) diff --git a/modules/sys_stat b/modules/sys_stat index 364c71b39a..bb3510fe40 100644 --- a/modules/sys_stat +++ b/modules/sys_stat @@ -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 $@ -- 2.30.2