Also the chdir() function is not declared in <unistd.h>, but in <direct.h>, on MSVC 9. This fixes the problem.
2011-09-23 Bruno Haible <[email protected]> New module 'chdir'. * modules/chdir: New file. * lib/unistd.in.h: Include <io.h>, <direct.h> also for chdir. (chdir): New declaration. * m4/unistd_h.m4 (gl_UNISTD_H): Test whether chdir is declared. (gl_UNISTD_H_DEFAULTS): Initialize GNULIB_CHDIR. * modules/unistd (Makefile.am): Substitute GNULIB_CHDIR. * tests/test-unistd-c++.cc: Check signature of chdir. * doc/posix-functions/chdir.texi: Mention problem on native Windows. * modules/chdir-long (Depends-on): Add chdir. * modules/fchdir (Depends-on): Likewise. * modules/rename (Depends-on): Likewise. * modules/savewd (Depends-on): Likewise. ================================ modules/chdir ================================ Description: chdir() function: switch to another current directory Files: Depends-on: unistd configure.ac: gl_UNISTD_MODULE_INDICATOR([chdir]) Makefile.am: Include: <unistd.h> License: LGPLv2+ Maintainer: Bruno Haible =============================================================================== --- doc/posix-functions/chdir.texi.orig Fri Sep 23 12:28:28 2011 +++ doc/posix-functions/chdir.texi Fri Sep 23 12:03:02 2011 @@ -8,6 +8,10 @@ Portability problems fixed by Gnulib: @itemize +@item +This function is declared in different header files (namely, @code{<io.h>} or +@code{<direct.h>}) on some platforms: +mingw, MSVC 9. @end itemize Portability problems not fixed by Gnulib: --- lib/unistd.in.h.orig Fri Sep 23 12:28:28 2011 +++ lib/unistd.in.h Fri Sep 23 12:15:07 2011 @@ -83,9 +83,10 @@ # include <stdlib.h> #endif -/* Native Windows platforms declare getcwd, rmdir in +/* Native Windows platforms declare chdir, getcwd, rmdir in <io.h> and/or <direct.h>, not in <unistd.h>. */ -#if ((@GNULIB_GETCWD@ || @GNULIB_RMDIR@ || defined GNULIB_POSIXCHECK) \ +#if ((@GNULIB_CHDIR@ || @GNULIB_GETCWD@ || @GNULIB_RMDIR@ \ + || defined GNULIB_POSIXCHECK) \ && ((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__)) # include <io.h> /* mingw32, mingw64 */ # include <direct.h> /* mingw64, MSVC 9 */ @@ -232,6 +233,18 @@ _GL_WARN_ON_USE (access, "the access function is a security risk - " #endif +#if @GNULIB_CHDIR@ +_GL_CXXALIAS_SYS (chdir, int, (const char *file) _GL_ARG_NONNULL ((1))); +_GL_CXXALIASWARN (chdir); +#elif defined GNULIB_POSIXCHECK +# undef chdir +# if HAVE_RAW_DECL_CHDIR +_GL_WARN_ON_USE (chown, "chdir is not always in <unistd.h> - " + "use gnulib module chdir for portability"); +# endif +#endif + + #if @GNULIB_CHOWN@ /* Change the owner of FILE to UID (if UID is not -1) and the group of FILE to GID (if GID is not -1). Follow symbolic links. --- m4/unistd_h.m4.orig Fri Sep 23 12:28:28 2011 +++ m4/unistd_h.m4 Fri Sep 23 12:15:49 2011 @@ -1,4 +1,4 @@ -# unistd_h.m4 serial 59 +# unistd_h.m4 serial 60 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, @@ -39,7 +39,7 @@ # include <io.h> # endif #endif - ]], [chown dup2 dup3 environ euidaccess faccessat fchdir fchownat + ]], [chdir chown dup2 dup3 environ euidaccess faccessat fchdir fchownat fdatasync fsync ftruncate getcwd getdomainname getdtablesize getgroups gethostname getlogin getlogin_r getpagesize getusershell setusershell endusershell group_member lchown link linkat lseek pipe pipe2 pread pwrite @@ -58,6 +58,7 @@ AC_DEFUN([gl_UNISTD_H_DEFAULTS], [ + GNULIB_CHDIR=0; AC_SUBST([GNULIB_CHDIR]) GNULIB_CHOWN=0; AC_SUBST([GNULIB_CHOWN]) GNULIB_CLOSE=0; AC_SUBST([GNULIB_CLOSE]) GNULIB_DUP2=0; AC_SUBST([GNULIB_DUP2]) --- modules/chdir-long.orig Fri Sep 23 12:28:28 2011 +++ modules/chdir-long Fri Sep 23 12:20:02 2011 @@ -10,6 +10,7 @@ Depends-on: unistd pathmax +chdir atexit [test $gl_cv_have_arbitrary_file_name_length_limit = yes] fchdir [test $gl_cv_have_arbitrary_file_name_length_limit = yes] fcntl-h [test $gl_cv_have_arbitrary_file_name_length_limit = yes] --- modules/fchdir.orig Fri Sep 23 12:28:28 2011 +++ modules/fchdir Fri Sep 23 12:21:33 2011 @@ -7,6 +7,7 @@ Depends-on: unistd +chdir [test $HAVE_FCHDIR = 0] close [test $HAVE_FCHDIR = 0] dirent [test $HAVE_FCHDIR = 0] dirfd [test $HAVE_FCHDIR = 0] --- modules/rename.orig Fri Sep 23 12:28:28 2011 +++ modules/rename Fri Sep 23 12:20:35 2011 @@ -8,6 +8,7 @@ Depends-on: stdio canonicalize-lgpl [test $REPLACE_RENAME = 1] +chdir [test $REPLACE_RENAME = 1] dirname-lgpl [test $REPLACE_RENAME = 1] lstat [test $REPLACE_RENAME = 1] rmdir [test $REPLACE_RENAME = 1] --- modules/savewd.orig Fri Sep 23 12:28:28 2011 +++ modules/savewd Fri Sep 23 12:20:50 2011 @@ -7,6 +7,7 @@ m4/savewd.m4 Depends-on: +chdir dosname errno fchdir --- modules/unistd.orig Fri Sep 23 12:28:28 2011 +++ modules/unistd Fri Sep 23 12:23:10 2011 @@ -30,6 +30,7 @@ -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \ -e 's|@''NEXT_UNISTD_H''@|$(NEXT_UNISTD_H)|g' \ + -e 's/@''GNULIB_CHDIR''@/$(GNULIB_CHDIR)/g' \ -e 's/@''GNULIB_CHOWN''@/$(GNULIB_CHOWN)/g' \ -e 's/@''GNULIB_CLOSE''@/$(GNULIB_CLOSE)/g' \ -e 's/@''GNULIB_DUP2''@/$(GNULIB_DUP2)/g' \ --- tests/test-unistd-c++.cc.orig Fri Sep 23 12:28:28 2011 +++ tests/test-unistd-c++.cc Fri Sep 23 12:17:40 2011 @@ -24,6 +24,10 @@ #include "signature.h" +#if GNULIB_TEST_CHDIR +SIGNATURE_CHECK (GNULIB_NAMESPACE::chdir, int, (const char *)); +#endif + #if GNULIB_TEST_CHOWN SIGNATURE_CHECK (GNULIB_NAMESPACE::chown, int, (const char *, uid_t, gid_t)); #endif -- In memoriam Ghazala Khan <http://en.wikipedia.org/wiki/Ghazala_Khan>
