summaryrefslogtreecommitdiff
path: root/lib/fchdir.c
Commit message (Collapse)AuthorAgeFilesLines
* version-etc: new yearPaul Eggert2014-12-311-1/+1
| | | | | | * doc/gnulib.texi: * lib/version-etc.c (COPYRIGHT_YEAR): Update copyright date. * all files: Run 'make update-copyright'.
* assure: new modulePaul Eggert2014-12-201-3/+3
| | | | | | | | | | | | | | | This works better than 'assert' when compiling with -DNDEBUG, as it avoids some compiler diagnostics in that case. Reported by Norihiro Tanaka in: http://lists.gnu.org/archive/html/bug-gnulib/2014-12/msg00215.html * MODULES.html.sh (func_all_modules): Add 'assure'. * lib/assure.h, modules/assure: New files. * lib/chdir-long.c, lib/cycle-check.c, lib/fchdir.c, lib/fts.c: * lib/poll.c, lib/savewd.c, lib/utimens.c, lib/xstrtol.c: Prefer 'assure' to 'assert'. * modules/chdir-long, modules/cycle-check, modules/fchdir: * modules/poll, modules/savewd, modules/utimens, modules/xstrtol: Depend on 'assure'.
* maint: update copyrightEric Blake2014-01-011-1/+1
| | | | | | I ran 'make update-copyright'. Signed-off-by: Eric Blake <eblake@redhat.com>
* maint: update all copyright year number rangesEric Blake2013-01-011-1/+1
| | | | | | Run "make update-copyright". Compare to commit 1602f0a from last year. Signed-off-by: Eric Blake <eblake@redhat.com>
* maint: update all copyright year number rangesJim Meyering2012-01-011-1/+1
| | | | Run "make update-copyright".
* New module 'fstat'.Bruno Haible2011-09-251-14/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * lib/sys_stat.in.h (fstat): Declare only if GNULIB_FSTAT is set. * lib/fstat.c: New file, based on a piece of lib/fchdir.c. * lib/fchdir.c (rpl_fstat): Remove function. * m4/fstat.m4: New file. * m4/fchdir.m4 (gl_FUNC_FCHDIR): Don't set REPLACE_FSTAT. * m4/sys_stat_h.m4 (gl_HEADER_SYS_STAT_H): Test whether fstat is declared. (gl_SYS_STAT_H_DEFAULTS): Initialize GNULIB_FSTAT. * modules/sys_stat (Makefile.am): Substitute GNULIB_FSTAT. * modules/fstat: New file. * modules/sys_stat-tests (Depends-on): Remove fstat-tests. * tests/test-sys_stat-c++.cc (fstat): Check only if GNULIB_TEST_FSTAT is set. * doc/posix-functions/fstat.texi: Mention the new module and the problem on MSVC. * NEWS: Mention the change. * modules/acl (Depends-on): Add fstat. * modules/chdir-safer (Depends-on): Likewise. * modules/chown (Depends-on): Likewise. * modules/copy-file (Depends-on): Likewise. * modules/fchdir (Depends-on): Likewise. * modules/fdopendir (Depends-on): Likewise. * modules/fopen (Depends-on): Likewise. * modules/fts (Depends-on): Likewise. * modules/getcwd (Depends-on): Likewise. * modules/isapipe (Depends-on): Likewise. * modules/linkat (Depends-on): Likewise. * modules/lseek (Depends-on): Likewise. * modules/mkdir-p (Depends-on): Likewise. * modules/open (Depends-on): Likewise. * modules/openat (Depends-on): Likewise. * modules/read-file (Depends-on): Likewise. * modules/renameat (Depends-on): Likewise. * modules/utimens (Depends-on): Likewise.
* New module 'dup'.Bruno Haible2011-09-241-13/+0
| | | | | | | | | | | | | | | | | | | | | | | | * lib/unistd.in.h (dup): Declare only if the 'dup' module is in use. Allow replacement. * lib/dup.c: New file. * lib/fchdir.c (rpl_dup): Remove function. * m4/dup.m4: New file. * m4/fchdir.m4 (gl_FUNC_FCHDIR): Don't set REPLACE_DUP here. * m4/unistd_h.m4 (gl_UNISTD_H): Test whether 'dup' is declared. (gl_UNISTD_H_DEFAULTS): Initialize GNULIB_DUP. * modules/unistd (Makefile.am): Substitute GNULIB_DUP. * modules/dup: New file. * tests/test-unistd-c++.cc: Check the signature of 'dup' only if the 'dup' module is in use. * modules/fdopendir (Depends-on): Add dup. * modules/fdutimensat-tests (Depends-on): Likewise. * modules/fts (Depends-on): Likewise. * modules/futimens-tests (Depends-on): Likewise. * modules/posix_spawnp-tests (Depends-on): Likewise. * modules/unistd-safer-tests (Depends-on): Likewise. * modules/utimens-tests (Depends-on): Likewise. * doc/posix-functions/dup.texi: Mention the new module and the problem on MSVC.
* New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.Bruno Haible2011-09-131-36/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * lib/dirent.in.h (struct dirent): New type. (DT_UNKNOWN, DT_FIFO, DT_CHR, DT_DIR, DT_BLK, DT_REG, DT_LNK, DT_SOCK, DT_WHT): New macros. (DIR): New type. (opendir, closedir): Declare only if the module 'opendir' is enabled. (readdir, rewinddir): New declarations. * lib/dirent-private.h: New file. * lib/opendir.c: New file. * lib/readdir.c: New file. * lib/rewinddir.c: New file. * lib/closedir.c: New file. * lib/fchdir.c (rpl_closedir, rpl_opendir): Remove functions. * m4/opendir.m4: New file. * m4/readdir.m4: New file. * m4/rewinddir.m4: New file. * m4/closedir.m4: New file. * m4/fchdir.m4 (gl_FUNC_FCHDIR): Don't set REPLACE_OPENDIR, REPLACE_CLOSEDIR here. * m4/dirent_h.m4 (gl_DIRENT_H): Also check whether closedir, opendir, readdir, rewinddir are declared. (gl_DIRENT_H_DEFAULTS): Initialize GNULIB_OPENDIR, GNULIB_READDIR, GNULIB_REWINDDIR, GNULIB_CLOSEDIR, HAVE_OPENDIR, HAVE_READDIR, HAVE_REWINDDIR, HAVE_CLOSEDIR. * modules/dirent (Makefile.am): Substitute GNULIB_OPENDIR, GNULIB_READDIR, GNULIB_REWINDDIR, GNULIB_CLOSEDIR, HAVE_OPENDIR, HAVE_READDIR, HAVE_REWINDDIR, HAVE_CLOSEDIR. * modules/opendir: New file. * modules/readdir: New file. * modules/rewinddir: New file. * modules/closedir: New file. * doc/posix-functions/opendir.texi: Mention the 'opendir' module. * doc/posix-functions/readdir.texi: Mention the 'readdir' module. * doc/posix-functions/rewinddir.texi: Mention the 'rewinddir' module. * doc/posix-functions/closedir.texi: Mention the 'closedir' module. * NEWS: Mention the 'fchdir' change.
* fchdir: avoid extra chdir and fix testEric Blake2011-04-271-35/+19
| | | | | | | | | | | | | | | | | | On Linux, with a forced ac_cv_func_fchdir=no, the test failed because dup2 was not replaced, all because the shell variable ac_cv_func_dup2 had not been set yet. Meanwhile, computing the canonical pathname of a directory on mingw was rather expensive -- multiple chdir()! -- but nothing cared whether the name was canonical, just that it was absolute. * modules/fchdir (Depends-on): Add dosname, filenamecat-lgpl, getcwd-lgpl. * lib/fchdir.c (get_name): Any absolute name will do; it does not have to be canonical. * m4/dup2.m4 (gl_REPLACE_DUP2): Ensure dup2 is replaced. Signed-off-by: Eric Blake <eblake@redhat.com>
* maint: update almost all copyright ranges to include 2011Jim Meyering2011-01-011-1/+1
| | | | Run the new "make update-copyright" rule.
* update nearly all FSF copyright year lists to include 2010Jim Meyering2010-01-011-1/+1
| | | | | Use the same procedure as for 2009, outlined in http://thread.gmane.org/gmane.comp.lib.gnulib.bugs/20081
* fcntl: use to simplify other modulesEric Blake2009-12-161-4/+1
| | | | | | | | | | | | | | | | | | | | | Let fcntl do the work, instead of copying code into other modules. * modules/cloexec (Depends-on): Add fcntl. * modules/fchdir (Depends-on): Likewise. * modules/fd-safer-flag (Depends-on): Likewise. * modules/unistd-safer (Depends-on): Likewise. * modules/dup3 (configure.ac): Set module indicator. * m4/fchdir.m4 (gl_FUNC_FCHDIR): Replace fcntl if fchdir is missing. * lib/fchdir.c (_gl_register_dup): Fix comment. * lib/cloexec.c (dup_cloexec): Simplify, by relying on fcntl. * lib/dup-safer.c (dup_safer): Likewise. * lib/dup-safer-flag.c (dup_safer_flag): Likewise. * lib/dup3.c (dup3): Likewise. * tests/test-fchdir.c (main): Enhance test. Fixes a dup_cloexec bug reported by Ondřej Vašík. Signed-off-by: Eric Blake <ebb9@byu.net>
* fchdir: Optimize away rpl_fstat when possible.Bruno Haible2009-12-091-3/+4
|
* fchdir: Update comment.Bruno Haible2009-12-091-2/+2
|
* fchdir: avoid memory leak on re-registration.Eric Blake2009-12-081-3/+6
| | | | | | | | | Some code paths (such as dup3) could overwrite one registered directory fd with another, and must not leak the old name. * lib/fchdir.c (ensure_dirs_slot): Avoid memory leak. Signed-off-by: Eric Blake <ebb9@byu.net>
* fchdir: fix logic bugsEric Blake2009-12-081-4/+3
| | | | | | | | | | | | | Configuring with ac_cv_func_fchdir=no on a system that has fchdir and where open handles directories, just to test out the replacement capabilities, uncovered an m4 test bug and a link failure on rpl_fstat. * m4/fchdir.m4 (gl_FUNC_FCHDIR): Fix logic bug. * tests/test-fchdir.c (main): Enhance test. * lib/fchdir.c (rpl_fstat): Always provide if fchdir replacement is in use. Signed-off-by: Eric Blake <ebb9@byu.net>
* fchdir: avoid infinite recursion in mingwEric Blake2009-10-141-0/+1
| | | | | | | | | rpl_fstat, needed only on mingw when using fchdir, should not call itself. * lib/fchdir.c (rpl_fstat): Call system fstat, rather than recursing. Signed-off-by: Eric Blake <ebb9@byu.net>
* fchdir: avoid compiler warningEric Blake2009-10-021-0/+1
| | | | | | | | | Using fchdir without canonicalize-lgpl gave a warning. * lib/fchdir.c (canonicalize_file_name) [!HAVE_CANONICALIZE_FILE_NAME]: Avoid compiler warning on mingw. Signed-off-by: Eric Blake <ebb9@byu.net>
* maint: cleanup whitespace in recent commitsEric Blake2009-10-021-11/+11
| | | | | | | * lib/fchdir.c (get_name): Remove tabs. Reported by Jim Meyering. Signed-off-by: Eric Blake <ebb9@byu.net>
* rename, fchdir: don't ignore chdir failureEric Blake2009-10-021-1/+2
| | | | | | | | | | | | | | | | | Although we just checked that chdir(cwd) worked, there is a race where it could disappear while we are temporarily away. If that happens, forcefully give up rather than proceeding in the wrong directory. * lib/fchdir.c (get_name): Abort on unexpected chdir failure. * lib/rename.c (rpl_rename) [W32]: Likewise. (rpl_rename) [RENAME_DEST_EXISTS_BUG]: Avoid one case of losing an empty destination directory if source cannot be renamed, although there is still possibility for failure. * doc/posix-functions/rename.texi (rename): Document the race. Reported by Jim Meyering. Signed-off-by: Eric Blake <ebb9@byu.net>
* fchdir: another mingw fixEric Blake2009-09-231-1/+41
| | | | | | | | | | | | | | | | canonicalize_file_name does not understand drive letters or backslash. The only reason openat required it was to make fchdir get the canonical name of a directory. But we can do the same trick with chdir and getcwd. With this fix, fchdir(open("..",O_RDONLY)) finally does the right thing on mingw. * modules/fchdir (Depends-on): Drop canonicalize-lgpl. * lib/fchdir.c (get_name): New helper method; skips canonicalize on mingw (where it has not yet been ported), and make it optional elsewhere. (_gl_register_fd): Use it. Signed-off-by: Eric Blake <ebb9@byu.net>
* canonicalize-lgpl: adjust clients to use correct headerEric Blake2009-09-191-2/+0
| | | | | | | | | | * m4/canonicalize.m4 (gl_FUNC_CANONICALIZE_FILENAME_MODE) (gl_CANONICALIZE_LGPL): Use correct shell quoting. * modules/relocatable-prog-wrapper (Files): Drop canonicalize.h. * lib/fchdir.c (includes): Use <stdlib.h>, not "canonicalize.h". * lib/progreloc.c (includes): Likewise. Signed-off-by: Eric Blake <ebb9@byu.net>
* fdopendir: optimize on mingwEric Blake2009-09-021-12/+21
| | | | | | | | | | * lib/unistd.in.h (_gl_directory_name): New prototype. * lib/fchdir.c (_gl_directory_name): Implement it. (fchdir): Use it to simplify implementation. * lib/fdopendir.c (fdopendir) [REPLACE_FCHDIR]: Use metadata from fchdir, when available, to avoid calling [f]chdir(). Signed-off-by: Eric Blake <ebb9@byu.net>
* fchdir: simplify error handling, and support dup3Eric Blake2009-09-021-100/+77
| | | | | | | | | | | | | | | | | | | | | | * modules/fchdir (Depends-on): Use strdup-posix, not strdup. Add stdbool, malloc-posix, realloc-posix. * lib/fchdir.c (struct dir_info_t): Delete saved_errno. (ensure_dirs_slot): Return false on allocation failure. (rpl_dup2): Delete. (_gl_register_dup): New function. (_gl_unregister_fd, rpl_opendir, rpl_dup): Update callers. (_gl_register_fd): Close fd on allocation failure. * lib/fcntl.in.h (_gl_register_fd): Update signature. * lib/unistd.in.h (_gl_register_dup) [FCHDIR_REPLACEMENT]: New prototype. (rpl_dup2_fchdir): Delete prototype. * lib/open.c (open): Update caller. * lib/dup2.c (dup2): Track fchdir metadata. * lib/dup3.c (dup3): Likewise. * m4/dup2.m4 (gl_REPLACE_DUP2): New macro. * m4/fchdir.m4 (gl_FUNC_FCHDIR): Use it. Signed-off-by: Eric Blake <ebb9@byu.net>
* fchdir: fix off-by-one bug in previous patchEric Blake2009-09-011-3/+2
| | | | | | | * lib/fchdir.c (rpl_fstat): Use correct bounds. (_gl_unregister_fd): Delete useless if. Signed-off-by: Eric Blake <ebb9@byu.net>
* fchdir: port to mingwEric Blake2009-08-311-23/+40
| | | | | | | | | | | | | | | | | | * m4/fchdir.m4 (gl_FUNC_FCHDIR): Check for mingw bug. * lib/open.c (open) [FCHDIR_REPLACEMENT]: If directories can't be opened, then use a substitute. * lib/sys_stat.in.h (fstat) [REPLACE_OPEN_DIRECTORY]: Declare replacement. * lib/fchdir.c (fstat) [REPLACE_OPEN_DIRECTORY]: Implement it. (_gl_register_fd): No need to check stat if open already filters all directories. (fchdir): Fix error condition to match POSIX. * modules/fchdir (Depends-on): Add sys_stat. * doc/posix-functions/open.texi (open): Document the limitation. * modules/fchdir-tests: New file. * tests/test-fchdir.c: Likewise. Signed-off-by: Eric Blake <ebb9@byu.net>
* dup2: fix more mingw problemsEric Blake2009-07-211-8/+9
| | | | | | | | | | | | * lib/dup2.c (rpl_dup2) [_WIN32]: Avoid hanging when duplicating fd to itself. * doc/posix-functions/dup2.texi (dup2): Document the bug. * lib/unistd.in.h (dup2) [REPLACE_FCHDIR]: Avoid name collision. * lib/fchdir.c (dup2): Manage preprocessor macros correctly. (rpl_dup2_fchdir): Rename from rpl_dup2, and let dup2 module take care of mingw bugs. Signed-off-by: Eric Blake <ebb9@byu.net>
* dup2: work around mingw and cygwin 1.5 bugEric Blake2009-07-211-1/+6
| | | | | | | | | | | | | | | | * m4/dup2.m4 (gl_FUNC_DUP2): Detect mingw bug. * m4/unistd_h.m4 (gl_UNISTD_H_DEFAULTS): Add witness. * modules/unistd (Makefile.am): Substitute it. * lib/unistd.in.h (dup2): Declare the replacement. * lib/dup2.c (dup2) [REPLACE_DUP2]: Implement it. * doc/posix-functions/dup2.texi (dup2): Document the bugs. * lib/fchdir.c (rpl_dup2): Don't collide with mingw replacement. * modules/execute (Depends-on): Add dup2. * modules/fseterr (Depends-on): Likewise. * modules/pipe (Depends-on): Likewise. * modules/posix_spawn-internal (Depends-on): Likewise. Signed-off-by: Eric Blake <ebb9@byu.net>
* Move the dirfd() declaration to <dirent.h>.Bruno Haible2008-10-191-2/+1
|
* New module 'close'.Paolo Bonzini2008-10-101-13/+0
|
* Merge the two replacements for open() into a single one.Paolo Bonzini2008-10-091-34/+1
|
* Reduce code duplication.Paolo Bonzini2008-10-091-34/+37
|
* Use rpl_ prefix for functions, so as to avoid endless recursions in weird cases.Bruno Haible2007-10-151-6/+6
|
* Change copyright notice from GPLv2+ to GPLv3+.Bruno Haible2007-10-071-5/+4
|
* New module 'open'.Bruno Haible2007-10-071-0/+4
|
* Move more declarations into <unistd.h>.Bruno Haible2007-02-191-1/+3
|
* * doc/gnulib-tool.texi (Initial import): Update to match currentPaul Eggert2007-01-261-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | behavior with strdup module. * lib/.cppi-disable: Remove strcase.h, strdup.h, strndup.h, strnlen.h. * lib/memmem.h: Remove; all uses removed. This is now done by <string.h>. * lib/mempcpy.h: Likewise. * lib/memrchr.h: Likewise. * lib/stpcpy.h: Likewise. * lib/stpncpy.h: Likewise. * lib/strcase.h: Likewise. * lib/strchrnul.h: Likewise. * lib/strdup.h: Likewise. * lib/strndup.h: Likewise. * lib/strnlen.h: Likewise. * lib/strpbrk.h: Likewise. * lib/strsep.h: Likewise. * lib/strstr.h: Likewise. * lib/strtok_r.h: Likewise. * lib/string_.h: New file. * lib/argp-namefrob.h: Don't include no-longer-existent include files. Rely on <string.h> instead. * lib/canon-host.c: Likewise. * lib/chdir-long.c: Likewise. * lib/concatpath.c: Likewise. * lib/exclude.c: Likewise. * lib/fchdir.c: Likewise. * lib/getaddrinfo.c: Likewise. * lib/getcwd.c: Likewise. * lib/getsubopt.c: Likewise. * lib/glob.c: Likewise. * lib/hard-locale.c: Likewise. * lib/iconvme.c: Likewise. * lib/javacomp.c: Likewise. * lib/mempcpy.c: Likewise. * lib/memrchr.c: Likewise. * lib/regex_internal.h: Likewise. * lib/stpncpy.c: Likewise. * lib/strcasecmp.c: Likewise. * lib/strchrnul.c: Likewise. * lib/strdup.c: Likewise. * lib/striconv.c: Likewise. * lib/striconveh.c: Likewise. * lib/striconveha.c: Likewise. * lib/strncasecmp.c: Likewise. * lib/strndup.c: Likewise. * lib/strnlen.c: Likewise. * lib/strsep.c: Likewise. * lib/strstr.c: Likewise. * lib/strtok_r.c: Likewise. * lib/userspec.c: Likewise. * lib/w32spawn.h: Likewise. * lib/xstrndup.c: Likewise. * lib/mountlist.c (strstr): Remove decl. * m4/string_h.m4: New file. * m4/memmem.m4 (gl_FUNC_MEMMEM): Set HAVE_DECL_MEMMEM if necessary. * m4/mempcpy.m4 (gl_FUNC_MEMPCPY): Set HAVE_MEMPCPY if necessary. * m4/memrchr.m4 (gl_FUNC_MEMRCHR): Set HAVE_MEMRCHR * m4/stpcpy.m4 (gl_FUNC_STPCPY): Set HAVE_STPCPY if necessary. * m4/stpncpy.m4 (gl_PREREQ_STPNCPY): Set HAVE_STPNCPY if necessary. * m4/strcase.m4 (gl_FUNC_STRCASECMP): Set REPLACE_STRCASECMP if necessary. (gl_FUNC_STRNCASECMP): Set HAVE_DECL_STRNCASECMP if necessary. * m4/strchrnul.m4 (gl_FUNC_STRCHRNUL): Set HAVE_STRCHRNUL if necessary. * m4/strdup.m4 (gl_FUNC_STRDUP): Set HAVE_DECL_STRDUP if necessary. * m4/strndup.m4 (gl_FUNC_STRNDUP): Set HAVE_DECL_STRNLEN and HAVE_DECL_STRDUP if necessary. (gl_PREREQ_STRNLEN): Don't bother to check for strnlen decl, since gl_FUNC_STRNDUP does that now. * m4/strnlen.m4 (gl_FUNC_STRNLEN): Set HAVE_DECL_STRNLEN if necessary. Check for decl here... (gl_PREREQ_STRNLEN): ... not here. * m4/strpbrk.m4 (gl_FUNC_STRPBRK): Set HAVE_STRPBRK if necessary. * m4/strsep.m4 (gl_FUNC_STRSEP): Set HAVE_STRSEP if necessary. * m4/strstr.m4 (gl_FUNC_STRSTR): Set REPLACE_STRSTR if necessary. * m4/strtok_r.m4 (gl_FUNC_STRTOK_R): Set HAVE_DECL_STRTOK_R if necessary. * modules/string: New file. * modules/memmem (Files): Remove special-purpose include file. (Depends-on): Add string. (Include): Include <string.h>, not the removed file. * modules/mempcpy: Likewise. * modules/memrchr: Likewise. * modules/stpcpy: Likewise. * modules/stpncpy: Likewise. * modules/strcase: Likewise. * modules/strchrnul: Likewise. * modules/strdup: Likewise. * modules/strndup: Likewise. * modules/strnlen: Likewise. * modules/strpbrk: Likewise. * modules/strsep: Likewise. * modules/strstr: Likewise. * modules/strtok_r: Likewise. * tests/test-dirname.c: Don't include "stdup.h", since <string.h> now suffices. * tests/test-memmem.c: Don't include "memmem.h", since <string.h> now suffices.
* New module 'fchdir'.Bruno Haible2007-01-141-0/+277