+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.
/* 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
/* 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)
return _mkdir (name);
}
-# define mkdir rpl_mkdir
+# define mkdir rpl_mkdir
+# endif
#endif
#endif /* _GL_SYS_STAT_H */
-#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.
# 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,
)
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
])
-# 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,
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])
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.
#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])
+])
{ 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 $@