From 912da04e8be8f7b78ea66c0fba08b2ceb292b8b0 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sun, 11 Sep 2011 21:44:32 +0200 Subject: [PATCH] unistd et al.: Don't assume exists. * m4/chdir-long.m4 (gl_FUNC_CHDIR_LONG): Don't include if it does not exist. * m4/environ.m4 (gl_ENVIRON): Don't include if it does not exist. But include . * m4/fcntl-o.m4 (gl_FCNTL_O_FLAGS): If does not exist, include and instead. Don't test symbolink links if symlink() does not exist. * m4/fflush.m4 (gl_FUNC_FFLUSH_STDIN): If does not exist, include instead. * m4/free.m4 (gl_FUNC_FREE): Assume free(NULL) works on native Windows. * m4/getcwd.m4 (gl_FUNC_GETCWD_NULL): If does not exist, include instead. * m4/getcwd-abort-bug.m4 (gl_FUNC_GETCWD_ABORT_BUG): Likewise. * m4/getcwd-path-max.m4 (gl_FUNC_GETCWD_PATH_MAX): Likewise. * m4/lseek.m4 (gl_FUNC_LSEEK): If does not exist, include instead. * m4/rename.m4 (gl_FUNC_RENAME): Assume rename() manages hard links correctly if the system does not have hard links. * m4/rmdir.m4 (gl_FUNC_RMDIR): If does not exist, include instead. * m4/unistd_h.m4 (gl_UNISTD_H): If does not exist, bypass it when looking for function declarations. * m4/unlink.m4 (gl_FUNC_UNLINK): If does not exist, include and instead. * doc/posix-headers/unistd.texi: More details about MSVC problem. --- ChangeLog | 29 +++++++++++++++++++ doc/posix-headers/unistd.texi | 3 +- m4/chdir-long.m4 | 8 ++++-- m4/environ.m4 | 13 +++++++-- m4/fcntl-o.m4 | 15 ++++++++-- m4/fflush.m4 | 9 ++++-- m4/free.m4 | 26 ++++++++++------- m4/getcwd-abort-bug.m4 | 9 ++++-- m4/getcwd-path-max.m4 | 9 ++++-- m4/getcwd.m4 | 9 ++++-- m4/lseek.m4 | 10 +++++-- m4/rename.m4 | 65 +++++++++++++++++++++++-------------------- m4/rmdir.m4 | 9 ++++-- m4/unistd_h.m4 | 7 +++-- m4/unlink.m4 | 16 +++++++++-- 15 files changed, 173 insertions(+), 64 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4c88f6fd3..7a8168fd6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,34 @@ 2011-09-11 Bruno Haible + unistd et al.: Don't assume exists. + * m4/chdir-long.m4 (gl_FUNC_CHDIR_LONG): Don't include if it + does not exist. + * m4/environ.m4 (gl_ENVIRON): Don't include if it does not + exist. But include . + * m4/fcntl-o.m4 (gl_FCNTL_O_FLAGS): If does not exist, + include and instead. Don't test symbolink links if + symlink() does not exist. + * m4/fflush.m4 (gl_FUNC_FFLUSH_STDIN): If does not exist, + include instead. + * m4/free.m4 (gl_FUNC_FREE): Assume free(NULL) works on native Windows. + * m4/getcwd.m4 (gl_FUNC_GETCWD_NULL): If does not exist, + include instead. + * m4/getcwd-abort-bug.m4 (gl_FUNC_GETCWD_ABORT_BUG): Likewise. + * m4/getcwd-path-max.m4 (gl_FUNC_GETCWD_PATH_MAX): Likewise. + * m4/lseek.m4 (gl_FUNC_LSEEK): If does not exist, include + instead. + * m4/rename.m4 (gl_FUNC_RENAME): Assume rename() manages hard links + correctly if the system does not have hard links. + * m4/rmdir.m4 (gl_FUNC_RMDIR): If does not exist, include + instead. + * m4/unistd_h.m4 (gl_UNISTD_H): If does not exist, bypass + it when looking for function declarations. + * m4/unlink.m4 (gl_FUNC_UNLINK): If does not exist, include + and instead. + * doc/posix-headers/unistd.texi: More details about MSVC problem. + +2011-09-11 Bruno Haible + strcase: Support for MSVC. * modules/strcase (Status, Notice): Remove obsoletion mark. * doc/posix-functions/strcasecmp.texi: Mention MSVC problem. diff --git a/doc/posix-headers/unistd.texi b/doc/posix-headers/unistd.texi index 41e743aa0..7beb4c25e 100644 --- a/doc/posix-headers/unistd.texi +++ b/doc/posix-headers/unistd.texi @@ -8,7 +8,8 @@ Gnulib module: unistd Portability problems fixed by Gnulib: @itemize @item -This header file is missing on some platforms: msvc. +This header file is missing on some platforms: +MSVC 9. @item The SEEK_* macros are not defined in this file on some platforms: mingw. diff --git a/m4/chdir-long.m4 b/m4/chdir-long.m4 index 9a343ac98..fdba1914d 100644 --- a/m4/chdir-long.m4 +++ b/m4/chdir-long.m4 @@ -1,4 +1,4 @@ -#serial 12 +#serial 13 # Use Gnulib's robust chdir function. # It can handle arbitrarily long directory names, which means @@ -15,10 +15,14 @@ dnl with or without modifications, as long as this notice is preserved. AC_DEFUN([gl_FUNC_CHDIR_LONG], [ + AC_CHECK_HEADERS_ONCE([unistd.h]) AC_CACHE_CHECK([whether this system has an arbitrary file name length limit], gl_cv_have_arbitrary_file_name_length_limit, [AC_EGREP_CPP([have_arbitrary_file_name_length_limit], - [#include + [ +#if HAVE_UNISTD_H +# include +#endif #include #if defined PATH_MAX || defined MAXPATHLEN have_arbitrary_file_name_length_limit diff --git a/m4/environ.m4 b/m4/environ.m4 index 7457ad139..6c7982f9b 100644 --- a/m4/environ.m4 +++ b/m4/environ.m4 @@ -1,4 +1,4 @@ -# environ.m4 serial 5 +# environ.m4 serial 6 dnl Copyright (C) 2001-2004, 2006-2011 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,7 +9,16 @@ AC_DEFUN_ONCE([gl_ENVIRON], AC_REQUIRE([gl_UNISTD_H_DEFAULTS]) dnl Persuade glibc to declare environ. AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS]) - gt_CHECK_VAR_DECL([#include ], environ) + + AC_CHECK_HEADERS_ONCE([unistd.h]) + gt_CHECK_VAR_DECL( + [#if HAVE_UNISTD_H + #include + #endif + /* mingw, BeOS, Haiku declare environ in , not in . */ + #include + ], + [environ]) if test $gt_cv_var_environ_declaration != yes; then HAVE_DECL_ENVIRON=0 fi diff --git a/m4/fcntl-o.m4 b/m4/fcntl-o.m4 index 88db07ec7..bee6edc11 100644 --- a/m4/fcntl-o.m4 +++ b/m4/fcntl-o.m4 @@ -1,4 +1,4 @@ -# fcntl-o.m4 serial 3 +# fcntl-o.m4 serial 4 dnl Copyright (C) 2006, 2009-2011 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -17,12 +17,21 @@ AC_DEFUN([gl_FCNTL_O_FLAGS], m4_ifdef([AC_USE_SYSTEM_EXTENSIONS], [AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])], [AC_REQUIRE([AC_GNU_SOURCE])]) + + AC_CHECK_HEADERS_ONCE([unistd.h]) + AC_CHECK_FUNCS_ONCE([symlink]) AC_CACHE_CHECK([for working fcntl.h], [gl_cv_header_working_fcntl_h], [AC_RUN_IFELSE( [AC_LANG_PROGRAM( [[#include #include - #include + #if HAVE_UNISTD_H + # include + #else /* on Windows with MSVC */ + # include + # include + # defined sleep(n) _sleep ((n) * 1000) + #endif #include #ifndef O_NOATIME #define O_NOATIME 0 @@ -38,6 +47,7 @@ AC_DEFUN([gl_FCNTL_O_FLAGS], ]], [[ int result = !constants; + #if HAVE_SYMLINK { static char const sym[] = "conftest.sym"; if (symlink (".", sym) != 0) @@ -53,6 +63,7 @@ AC_DEFUN([gl_FCNTL_O_FLAGS], } unlink (sym); } + #endif { static char const file[] = "confdefs.h"; int fd = open (file, O_RDONLY | O_NOATIME); diff --git a/m4/fflush.m4 b/m4/fflush.m4 index a91ee0bea..f74a1f842 100644 --- a/m4/fflush.m4 +++ b/m4/fflush.m4 @@ -1,4 +1,4 @@ -# fflush.m4 serial 12 +# fflush.m4 serial 13 # Copyright (C) 2007-2011 Free Software Foundation, Inc. # This file is free software; the Free Software Foundation @@ -24,13 +24,18 @@ dnl Sets gl_cv_func_fflush_stdin. AC_DEFUN([gl_FUNC_FFLUSH_STDIN], [ + AC_CHECK_HEADERS_ONCE([unistd.h]) AC_CACHE_CHECK([whether fflush works on input streams], [gl_cv_func_fflush_stdin], [echo hello world > conftest.txt AC_RUN_IFELSE([AC_LANG_PROGRAM( [[ #include -#include +#if HAVE_UNISTD_H +# include +#else /* on Windows with MSVC */ +# include +#endif ]], [[FILE *f = fopen ("conftest.txt", "r"); char buffer[10]; int fd; diff --git a/m4/free.m4 b/m4/free.m4 index 24bbbb184..76bca667f 100644 --- a/m4/free.m4 +++ b/m4/free.m4 @@ -16,18 +16,24 @@ AC_DEFUN([gl_FUNC_FREE], [ + AC_REQUIRE([AC_CANONICAL_HOST]) AC_CACHE_CHECK([whether free (NULL) is known to work], [gl_cv_func_free], - [AC_COMPILE_IFELSE( - [AC_LANG_PROGRAM( - [[@%:@include ]], - [[@%:@if _POSIX_VERSION < 199009L && \ - (defined unix || defined _unix || defined _unix_ \ - || defined __unix || defined __unix__) - @%:@error "'free (NULL)' is not known to work" - @%:@endif]])], - [gl_cv_func_free=yes], - [gl_cv_func_free=no])]) + [case "$host_os" in + mingw*) gl_cv_func_free=yes ;; + *) + AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM( + [[@%:@include ]], + [[@%:@if _POSIX_VERSION < 199009L && \ + (defined unix || defined _unix || defined _unix_ \ + || defined __unix || defined __unix__) + @%:@error "'free (NULL)' is not known to work" + @%:@endif]])], + [gl_cv_func_free=yes], + [gl_cv_func_free=no]) + esac + ]) if test $gl_cv_func_free = no; then AC_DEFINE([free], [rpl_free], diff --git a/m4/getcwd-abort-bug.m4 b/m4/getcwd-abort-bug.m4 index fd6820dc6..0d3f34f84 100644 --- a/m4/getcwd-abort-bug.m4 +++ b/m4/getcwd-abort-bug.m4 @@ -1,4 +1,4 @@ -# serial 4 +# serial 5 # Determine whether getcwd aborts when the length of the working directory # name is unusually large. Any length between 4k and 16k trigger the bug # when using glibc-2.4.90-9 or older. @@ -14,6 +14,7 @@ AC_DEFUN([gl_FUNC_GETCWD_ABORT_BUG], [ AC_CHECK_DECLS_ONCE([getcwd]) + AC_CHECK_HEADERS_ONCE([unistd.h]) AC_CHECK_FUNCS([getpagesize]) AC_CACHE_CHECK([whether getcwd aborts when 4k < cwd_length < 16k], gl_cv_func_getcwd_abort_bug, @@ -26,7 +27,11 @@ AC_DEFUN([gl_FUNC_GETCWD_ABORT_BUG], [AC_LANG_SOURCE( [[ #include -#include +#if HAVE_UNISTD_H +# include +#else /* on Windows with MSVC */ +# include +#endif #include #include #include diff --git a/m4/getcwd-path-max.m4 b/m4/getcwd-path-max.m4 index 475ae96d1..65ee49103 100644 --- a/m4/getcwd-path-max.m4 +++ b/m4/getcwd-path-max.m4 @@ -1,4 +1,4 @@ -# serial 16 +# serial 17 # Check for several getcwd bugs with long file names. # If so, arrange to compile the wrapper function. @@ -17,6 +17,7 @@ AC_DEFUN([gl_FUNC_GETCWD_PATH_MAX], [ AC_CHECK_DECLS_ONCE([getcwd]) AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS]) + AC_CHECK_HEADERS_ONCE([unistd.h]) AC_CACHE_CHECK([whether getcwd handles long file names properly], gl_cv_func_getcwd_path_max, [# Arrange for deletion of the temporary directory this test creates. @@ -27,7 +28,11 @@ AC_DEFUN([gl_FUNC_GETCWD_PATH_MAX], [[ #include #include -#include +#if HAVE_UNISTD_H +# include +#else +# include +#endif #include #include #include diff --git a/m4/getcwd.m4 b/m4/getcwd.m4 index d3bbe597b..f828cf340 100644 --- a/m4/getcwd.m4 +++ b/m4/getcwd.m4 @@ -6,15 +6,20 @@ # with or without modifications, as long as this notice is preserved. # Written by Paul Eggert. -# serial 8 +# serial 9 AC_DEFUN([gl_FUNC_GETCWD_NULL], [ AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles + AC_CHECK_HEADERS_ONCE([unistd.h]) AC_CACHE_CHECK([whether getcwd (NULL, 0) allocates memory for result], [gl_cv_func_getcwd_null], [AC_RUN_IFELSE([AC_LANG_PROGRAM([[ -# include +# if HAVE_UNISTD_H +# include +# else /* on Windows with MSVC */ +# include +# endif # ifndef getcwd char *getcwd (); # endif diff --git a/m4/lseek.m4 b/m4/lseek.m4 index b45488445..73c40698c 100644 --- a/m4/lseek.m4 +++ b/m4/lseek.m4 @@ -1,4 +1,4 @@ -# lseek.m4 serial 7 +# lseek.m4 serial 8 dnl Copyright (C) 2007, 2009-2011 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -8,12 +8,18 @@ AC_DEFUN([gl_FUNC_LSEEK], [ AC_REQUIRE([gl_UNISTD_H_DEFAULTS]) AC_REQUIRE([AC_PROG_CC]) + AC_CHECK_HEADERS_ONCE([unistd.h]) AC_CACHE_CHECK([whether lseek detects pipes], [gl_cv_func_lseek_pipe], [if test $cross_compiling = no; then AC_LINK_IFELSE([AC_LANG_PROGRAM([[ #include /* for off_t */ #include /* for SEEK_CUR */ -#include ]], [[ +#if HAVE_UNISTD_H +# include +#else /* on Windows with MSVC */ +# include +#endif +]], [[ /* Exit with success only if stdin is seekable. */ return lseek (0, (off_t)0, SEEK_CUR) < 0; ]])], diff --git a/m4/rename.m4 b/m4/rename.m4 index c938b0d00..af8d584e9 100644 --- a/m4/rename.m4 +++ b/m4/rename.m4 @@ -1,4 +1,4 @@ -# serial 24 +# serial 25 # Copyright (C) 2001, 2003, 2005-2006, 2009-2011 Free Software Foundation, Inc. # This file is free software; the Free Software Foundation @@ -110,37 +110,42 @@ AC_DEFUN([gl_FUNC_RENAME], dnl NetBSD 1.6 and cygwin 1.5.x mistakenly reduce hard link count dnl on rename("h1","h2"). dnl This bug requires stat'ting targets prior to attempting rename. + AC_CHECK_FUNCS_ONCE([link]) AC_CACHE_CHECK([whether rename manages hard links correctly], [gl_cv_func_rename_link_works], - [rm -rf conftest.f conftest.f1 - if touch conftest.f && ln conftest.f conftest.f1 && - set x `ls -i conftest.f conftest.f1` && test "$2" = "$4"; then - AC_RUN_IFELSE( - [AC_LANG_PROGRAM([[ -# include -# include -# include - ]], - [[int result = 0; - if (rename ("conftest.f", "conftest.f1")) - result |= 1; - if (unlink ("conftest.f1")) - result |= 2; - if (rename ("conftest.f", "conftest.f")) - result |= 4; - if (rename ("conftest.f1", "conftest.f1") == 0) - result |= 8; - return result; - ]])], - [gl_cv_func_rename_link_works=yes], - [gl_cv_func_rename_link_works=no], - dnl When crosscompiling, assume rename is broken. - [gl_cv_func_rename_link_works="guessing no"]) - else - gl_cv_func_rename_link_works="guessing no" - fi - rm -rf conftest.f conftest.f1 - ]) + [if test $ac_cv_func_link = yes; then + rm -rf conftest.f conftest.f1 + if touch conftest.f && ln conftest.f conftest.f1 && + set x `ls -i conftest.f conftest.f1` && test "$2" = "$4"; then + AC_RUN_IFELSE( + [AC_LANG_PROGRAM([[ +# include +# include +# include + ]], + [[int result = 0; + if (rename ("conftest.f", "conftest.f1")) + result |= 1; + if (unlink ("conftest.f1")) + result |= 2; + if (rename ("conftest.f", "conftest.f")) + result |= 4; + if (rename ("conftest.f1", "conftest.f1") == 0) + result |= 8; + return result; + ]])], + [gl_cv_func_rename_link_works=yes], + [gl_cv_func_rename_link_works=no], + dnl When crosscompiling, assume rename is broken. + [gl_cv_func_rename_link_works="guessing no"]) + else + gl_cv_func_rename_link_works="guessing no" + fi + rm -rf conftest.f conftest.f1 + else + gl_cv_func_rename_link_works=yes + fi + ]) if test "x$gl_cv_func_rename_link_works" != xyes; then REPLACE_RENAME=1 AC_DEFINE([RENAME_HARD_LINK_BUG], [1], diff --git a/m4/rmdir.m4 b/m4/rmdir.m4 index 5284c7ef0..0b1a65cc9 100644 --- a/m4/rmdir.m4 +++ b/m4/rmdir.m4 @@ -1,4 +1,4 @@ -# rmdir.m4 serial 11 +# rmdir.m4 serial 12 dnl Copyright (C) 2002, 2005, 2009-2011 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -8,6 +8,7 @@ AC_DEFUN([gl_FUNC_RMDIR], [ AC_REQUIRE([gl_UNISTD_H_DEFAULTS]) dnl Detect cygwin 1.5.x bug. + AC_CHECK_HEADERS_ONCE([unistd.h]) AC_CACHE_CHECK([whether rmdir works], [gl_cv_func_rmdir_works], [mkdir conftest.dir touch conftest.file @@ -15,7 +16,11 @@ AC_DEFUN([gl_FUNC_RMDIR], [AC_LANG_PROGRAM( [[#include #include - #include + #if HAVE_UNISTD_H + # include + #else /* on Windows with MSVC */ + # include + #endif ]], [[int result = 0; if (!rmdir ("conftest.file/")) result |= 1; diff --git a/m4/unistd_h.m4 b/m4/unistd_h.m4 index 6483b815d..33897ae92 100644 --- a/m4/unistd_h.m4 +++ b/m4/unistd_h.m4 @@ -1,4 +1,4 @@ -# unistd_h.m4 serial 57 +# unistd_h.m4 serial 58 dnl Copyright (C) 2006-2011 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -26,7 +26,10 @@ AC_DEFUN([gl_UNISTD_H], dnl Check for declarations of anything we want to poison if the dnl corresponding gnulib module is not in use. - gl_WARN_ON_USE_PREPARE([[#include + gl_WARN_ON_USE_PREPARE([[ +#if HAVE_UNISTD_H +# include +#endif /* Some systems declare various items in the wrong headers. */ #if !(defined __GLIBC__ && !defined __UCLIBC__) # include diff --git a/m4/unlink.m4 b/m4/unlink.m4 index 49cd3bb80..d6865a9e7 100644 --- a/m4/unlink.m4 +++ b/m4/unlink.m4 @@ -1,4 +1,4 @@ -# unlink.m4 serial 8 +# unlink.m4 serial 9 dnl Copyright (C) 2009-2011 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -8,6 +8,7 @@ AC_DEFUN([gl_FUNC_UNLINK], [ AC_REQUIRE([gl_UNISTD_H_DEFAULTS]) AC_REQUIRE([AC_CANONICAL_HOST]) + AC_CHECK_HEADERS_ONCE([unistd.h]) dnl Detect FreeBSD 7.2, AIX 7.1, Solaris 9 bug. AC_CACHE_CHECK([whether unlink honors trailing slashes], [gl_cv_func_unlink_honors_slashes], @@ -18,7 +19,11 @@ AC_DEFUN([gl_FUNC_UNLINK], fi AC_RUN_IFELSE( [AC_LANG_PROGRAM( - [[#include + [[#if HAVE_UNISTD_H + # include + #else /* on Windows with MSVC */ + # include + #endif #include ]], [[int result = 0; @@ -70,7 +75,12 @@ AC_DEFUN([gl_FUNC_UNLINK], AC_RUN_IFELSE( [AC_LANG_SOURCE([[ #include - #include + #if HAVE_UNISTD_H + # include + #else /* on Windows with MSVC */ + # include + # include + #endif int main () { int result = 0; -- 2.11.0