[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
unistd.h on MSVC
From: |
Bruno Haible |
Subject: |
unistd.h on MSVC |
Date: |
Sun, 11 Sep 2011 21:49:17 +0200 |
User-agent: |
KMail/1.13.6 (Linux/2.6.37.6-0.5-desktop; KDE/4.6.0; x86_64; ; ) |
MSVC also does not have <unistd.h>. While the gnulib generated <unistd.h>
works around that, there are a number of configure tests which fail,
merely because they contain an unconditional #include <unistd.h>.
In some cases, the fix is to write
#if HAVE_UNISTD_H
# include <unistd.h>
#endif
instead; often <direct.h> or <io.h> has to be included instead of <unistd.h>.
There are more unconditional uses of <unistd.h> in m4/*.m4, but they will
not distort the configure test results. Therefore I am leaving them alone.
Please review this patch more carefully than the other ones.
2011-09-11 Bruno Haible <address@hidden>
unistd et al.: Don't assume <unistd.h> exists.
* m4/chdir-long.m4 (gl_FUNC_CHDIR_LONG): Don't include <unistd.h> if it
does not exist.
* m4/environ.m4 (gl_ENVIRON): Don't include <unistd.h> if it does not
exist. But include <stdlib.h>.
* m4/fcntl-o.m4 (gl_FCNTL_O_FLAGS): If <unistd.h> does not exist,
include <io.h> and <stdlib.h> instead. Don't test symbolink links if
symlink() does not exist.
* m4/fflush.m4 (gl_FUNC_FFLUSH_STDIN): If <unistd.h> does not exist,
include <io.h> instead.
* m4/free.m4 (gl_FUNC_FREE): Assume free(NULL) works on native Windows.
* m4/getcwd.m4 (gl_FUNC_GETCWD_NULL): If <unistd.h> does not exist,
include <direct.h> 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 <unistd.h> does not exist, include
<io.h> 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 <unistd.h> does not exist, include
<direct.h> instead.
* m4/unistd_h.m4 (gl_UNISTD_H): If <unistd.h> does not exist, bypass
it when looking for function declarations.
* m4/unlink.m4 (gl_FUNC_UNLINK): If <unistd.h> does not exist, include
<direct.h> and <io.h> instead.
* doc/posix-headers/unistd.texi: More details about MSVC problem.
--- doc/posix-headers/unistd.texi.orig Sun Sep 11 21:30:03 2011
+++ doc/posix-headers/unistd.texi Sun Sep 11 18:26:01 2011
@@ -8,7 +8,8 @@
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.
--- m4/chdir-long.m4.orig Sun Sep 11 21:30:03 2011
+++ m4/chdir-long.m4 Sun Sep 11 18:26:01 2011
@@ -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 @@
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 <unistd.h>
+ [
+#if HAVE_UNISTD_H
+# include <unistd.h>
+#endif
#include <limits.h>
#if defined PATH_MAX || defined MAXPATHLEN
have_arbitrary_file_name_length_limit
--- m4/environ.m4.orig Sun Sep 11 21:30:04 2011
+++ m4/environ.m4 Sun Sep 11 18:26:01 2011
@@ -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_REQUIRE([gl_UNISTD_H_DEFAULTS])
dnl Persuade glibc <unistd.h> to declare environ.
AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
- gt_CHECK_VAR_DECL([#include <unistd.h>], environ)
+
+ AC_CHECK_HEADERS_ONCE([unistd.h])
+ gt_CHECK_VAR_DECL(
+ [#if HAVE_UNISTD_H
+ #include <unistd.h>
+ #endif
+ /* mingw, BeOS, Haiku declare environ in <stdlib.h>, not in <unistd.h>.
*/
+ #include <stdlib.h>
+ ],
+ [environ])
if test $gt_cv_var_environ_declaration != yes; then
HAVE_DECL_ENVIRON=0
fi
--- m4/fcntl-o.m4.orig Sun Sep 11 21:30:04 2011
+++ m4/fcntl-o.m4 Sun Sep 11 18:26:01 2011
@@ -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 @@
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 <sys/types.h>
#include <sys/stat.h>
- #include <unistd.h>
+ #if HAVE_UNISTD_H
+ # include <unistd.h>
+ #else /* on Windows with MSVC */
+ # include <io.h>
+ # include <stdlib.h>
+ # defined sleep(n) _sleep ((n) * 1000)
+ #endif
#include <fcntl.h>
#ifndef O_NOATIME
#define O_NOATIME 0
@@ -38,6 +47,7 @@
]],
[[
int result = !constants;
+ #if HAVE_SYMLINK
{
static char const sym[] = "conftest.sym";
if (symlink (".", sym) != 0)
@@ -53,6 +63,7 @@
}
unlink (sym);
}
+ #endif
{
static char const file[] = "confdefs.h";
int fd = open (file, O_RDONLY | O_NOATIME);
--- m4/fflush.m4.orig Sun Sep 11 21:30:04 2011
+++ m4/fflush.m4 Sun Sep 11 18:26:01 2011
@@ -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 @@
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 <stdio.h>
-#include <unistd.h>
+#if HAVE_UNISTD_H
+# include <unistd.h>
+#else /* on Windows with MSVC */
+# include <io.h>
+#endif
]], [[FILE *f = fopen ("conftest.txt", "r");
char buffer[10];
int fd;
--- m4/free.m4.orig Sun Sep 11 21:30:04 2011
+++ m4/free.m4 Sun Sep 11 18:26:01 2011
@@ -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(
- address@hidden:@include <unistd.h>]],
- address@hidden:@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(
+ address@hidden:@include <unistd.h>]],
+ address@hidden:@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],
--- m4/getcwd-abort-bug.m4.orig Sun Sep 11 21:30:04 2011
+++ m4/getcwd-abort-bug.m4 Sun Sep 11 18:26:01 2011
@@ -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_LANG_SOURCE(
[[
#include <stdlib.h>
-#include <unistd.h>
+#if HAVE_UNISTD_H
+# include <unistd.h>
+#else /* on Windows with MSVC */
+# include <direct.h>
+#endif
#include <limits.h>
#include <string.h>
#include <sys/stat.h>
--- m4/getcwd-path-max.m4.orig Sun Sep 11 21:30:04 2011
+++ m4/getcwd-path-max.m4 Sun Sep 11 18:26:01 2011
@@ -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_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 @@
[[
#include <errno.h>
#include <stdlib.h>
-#include <unistd.h>
+#if HAVE_UNISTD_H
+# include <unistd.h>
+#else
+# include <direct.h>
+#endif
#include <string.h>
#include <limits.h>
#include <sys/stat.h>
--- m4/getcwd.m4.orig Sun Sep 11 21:30:04 2011
+++ m4/getcwd.m4 Sun Sep 11 18:26:01 2011
@@ -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 <unistd.h>
+# if HAVE_UNISTD_H
+# include <unistd.h>
+# else /* on Windows with MSVC */
+# include <direct.h>
+# endif
# ifndef getcwd
char *getcwd ();
# endif
--- m4/lseek.m4.orig Sun Sep 11 21:30:04 2011
+++ m4/lseek.m4 Sun Sep 11 18:26:01 2011
@@ -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_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 <sys/types.h> /* for off_t */
#include <stdio.h> /* for SEEK_CUR */
-#include <unistd.h>]], [[
+#if HAVE_UNISTD_H
+# include <unistd.h>
+#else /* on Windows with MSVC */
+# include <io.h>
+#endif
+]], [[
/* Exit with success only if stdin is seekable. */
return lseek (0, (off_t)0, SEEK_CUR) < 0;
]])],
--- m4/rename.m4.orig Sun Sep 11 21:30:04 2011
+++ m4/rename.m4 Sun Sep 11 18:26:01 2011
@@ -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 @@
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 <stdio.h>
-# include <stdlib.h>
-# include <unistd.h>
- ]],
- [[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 <stdio.h>
+# include <stdlib.h>
+# include <unistd.h>
+ ]],
+ [[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],
--- m4/rmdir.m4.orig Sun Sep 11 21:30:04 2011
+++ m4/rmdir.m4 Sun Sep 11 18:26:01 2011
@@ -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_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_LANG_PROGRAM(
[[#include <stdio.h>
#include <errno.h>
- #include <unistd.h>
+ #if HAVE_UNISTD_H
+ # include <unistd.h>
+ #else /* on Windows with MSVC */
+ # include <direct.h>
+ #endif
]], [[int result = 0;
if (!rmdir ("conftest.file/"))
result |= 1;
--- m4/unistd_h.m4.orig Sun Sep 11 21:30:04 2011
+++ m4/unistd_h.m4 Sun Sep 11 18:26:01 2011
@@ -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 @@
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 <unistd.h>
+ gl_WARN_ON_USE_PREPARE([[
+#if HAVE_UNISTD_H
+# include <unistd.h>
+#endif
/* Some systems declare various items in the wrong headers. */
#if !(defined __GLIBC__ && !defined __UCLIBC__)
# include <fcntl.h>
--- m4/unlink.m4.orig Sun Sep 11 21:30:04 2011
+++ m4/unlink.m4 Sun Sep 11 18:26:01 2011
@@ -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_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 @@
fi
AC_RUN_IFELSE(
[AC_LANG_PROGRAM(
- [[#include <unistd.h>
+ [[#if HAVE_UNISTD_H
+ # include <unistd.h>
+ #else /* on Windows with MSVC */
+ # include <io.h>
+ #endif
#include <errno.h>
]],
[[int result = 0;
@@ -70,7 +75,12 @@
AC_RUN_IFELSE(
[AC_LANG_SOURCE([[
#include <stdlib.h>
- #include <unistd.h>
+ #if HAVE_UNISTD_H
+ # include <unistd.h>
+ #else /* on Windows with MSVC */
+ # include <direct.h>
+ # include <io.h>
+ #endif
int main ()
{
int result = 0;
--
In memoriam Georgi Markov <http://en.wikipedia.org/wiki/Georgi_Markov>
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- unistd.h on MSVC,
Bruno Haible <=