From 0d22381b8090eefaf8a5f0c5b9e196ea40b12231 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Fri, 23 Sep 2011 12:32:41 +0200 Subject: [PATCH] New module 'chdir'. * modules/chdir: New file. * lib/unistd.in.h: Include , 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. --- ChangeLog | 14 ++++++++++++++ doc/posix-functions/chdir.texi | 4 ++++ lib/unistd.in.h | 17 +++++++++++++++-- m4/unistd_h.m4 | 5 +++-- modules/chdir | 21 +++++++++++++++++++++ modules/chdir-long | 1 + modules/fchdir | 1 + modules/rename | 1 + modules/savewd | 1 + modules/unistd | 1 + tests/test-unistd-c++.cc | 4 ++++ 11 files changed, 66 insertions(+), 4 deletions(-) create mode 100644 modules/chdir diff --git a/ChangeLog b/ChangeLog index 0afd8339c..f95f27584 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,19 @@ 2011-09-23 Bruno Haible + New module 'chdir'. + * modules/chdir: New file. + * lib/unistd.in.h: Include , 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. + rmdir: Support for mingw, MSVC 9. * lib/unistd.in.h: Include and also for rmdir. * doc/posix-functions/getcwd.texi: Mention problem on native Windows. diff --git a/doc/posix-functions/chdir.texi b/doc/posix-functions/chdir.texi index 2a507ac5b..d3b3c3f0f 100644 --- a/doc/posix-functions/chdir.texi +++ b/doc/posix-functions/chdir.texi @@ -8,6 +8,10 @@ Gnulib module: --- Portability problems fixed by Gnulib: @itemize +@item +This function is declared in different header files (namely, @code{} or +@code{}) on some platforms: +mingw, MSVC 9. @end itemize Portability problems not fixed by Gnulib: diff --git a/lib/unistd.in.h b/lib/unistd.in.h index 6b7b377ea..bb514dbff 100644 --- a/lib/unistd.in.h +++ b/lib/unistd.in.h @@ -83,9 +83,10 @@ # include #endif -/* Native Windows platforms declare getcwd, rmdir in +/* Native Windows platforms declare chdir, getcwd, rmdir in and/or , not in . */ -#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 /* mingw32, mingw64 */ # include /* 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 - " + "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. diff --git a/m4/unistd_h.m4 b/m4/unistd_h.m4 index 720e0fd03..79ae9e966 100644 --- a/m4/unistd_h.m4 +++ b/m4/unistd_h.m4 @@ -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 @@ AC_DEFUN([gl_UNISTD_H], # include # 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_MODULE_INDICATOR], 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]) diff --git a/modules/chdir b/modules/chdir new file mode 100644 index 000000000..b827339ec --- /dev/null +++ b/modules/chdir @@ -0,0 +1,21 @@ +Description: +chdir() function: switch to another current directory + +Files: + +Depends-on: +unistd + +configure.ac: +gl_UNISTD_MODULE_INDICATOR([chdir]) + +Makefile.am: + +Include: + + +License: +LGPLv2+ + +Maintainer: +Bruno Haible diff --git a/modules/chdir-long b/modules/chdir-long index 7f54760ee..74d9c33f7 100644 --- a/modules/chdir-long +++ b/modules/chdir-long @@ -10,6 +10,7 @@ m4/pathmax.m4 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] diff --git a/modules/fchdir b/modules/fchdir index 7b7cb043b..80b2bb826 100644 --- a/modules/fchdir +++ b/modules/fchdir @@ -7,6 +7,7 @@ m4/fchdir.m4 Depends-on: unistd +chdir [test $HAVE_FCHDIR = 0] close [test $HAVE_FCHDIR = 0] dirent [test $HAVE_FCHDIR = 0] dirfd [test $HAVE_FCHDIR = 0] diff --git a/modules/rename b/modules/rename index 52ca382d3..582d63083 100644 --- a/modules/rename +++ b/modules/rename @@ -8,6 +8,7 @@ m4/rename.m4 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] diff --git a/modules/savewd b/modules/savewd index 1e95b4127..9a7b8c72c 100644 --- a/modules/savewd +++ b/modules/savewd @@ -7,6 +7,7 @@ lib/savewd.c m4/savewd.m4 Depends-on: +chdir dosname errno fchdir diff --git a/modules/unistd b/modules/unistd index 77ce7a823..3d3173450 100644 --- a/modules/unistd +++ b/modules/unistd @@ -30,6 +30,7 @@ unistd.h: unistd.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H -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' \ diff --git a/tests/test-unistd-c++.cc b/tests/test-unistd-c++.cc index fb7425bcb..b82b0e81d 100644 --- a/tests/test-unistd-c++.cc +++ b/tests/test-unistd-c++.cc @@ -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 -- 2.11.0