Mercurial > hg > octave-lojdl > gnulib-hg
changeset 9535:fdfe023323f5
getcwd.c: Use a more readable witness: HAVE_OPENAT_SUPPORT
* lib/getcwd.c: Define and use HAVE_OPENAT_SUPPORT, in place of AT_FDCWD.
author | Petr Salinger <Petr.Salinger@seznam.cz> |
---|---|
date | Mon, 17 Dec 2007 13:30:09 +0100 |
parents | 36c5c8024476 |
children | 6fb25141b290 |
files | ChangeLog lib/getcwd.c |
diffstat | 2 files changed, 17 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2007-12-17 Petr Salinger <Petr.Salinger@seznam.cz> + + getcwd.c: Use a more readable witness: HAVE_OPENAT_SUPPORT + * lib/getcwd.c: Define and use HAVE_OPENAT_SUPPORT, in place of AT_FDCWD. + 2007-12-17 Jim Meyering <meyering@redhat.com> Port to GNU/kFreeBSD - FreeBSD kernel + GNU libc,
--- a/lib/getcwd.c +++ b/lib/getcwd.c @@ -29,9 +29,12 @@ #include <fcntl.h> /* For AT_FDCWD on Solaris 9. */ -/* On a system without the openat function, undefine AT_FDCWD. */ -#if ! HAVE_OPENAT -# undef AT_FDCWD +/* If this host provides the openat function, then enable + code below to make getcwd more efficient and robust. */ +#ifdef HAVE_OPENAT +# define HAVE_OPENAT_SUPPORT 1 +#else +# define HAVE_OPENAT_SUPPORT 0 #endif #ifndef __set_errno @@ -127,7 +130,7 @@ DEEP_NESTING = 100 }; -#ifdef AT_FDCWD +#if HAVE_OPENAT_SUPPORT int fd = AT_FDCWD; bool fd_needs_closing = false; #else @@ -208,7 +211,7 @@ bool use_d_ino = true; /* Look at the parent directory. */ -#ifdef AT_FDCWD +#if HAVE_OPENAT_SUPPORT fd = openat (fd, "..", O_RDONLY); if (fd < 0) goto lose; @@ -235,7 +238,7 @@ mount_point = dotdev != thisdev; /* Search for the last directory. */ -#ifdef AT_FDCWD +#if HAVE_OPENAT_SUPPORT dirstream = fdopendir (fd); if (dirstream == NULL) goto lose; @@ -291,7 +294,7 @@ { int entry_status; -#ifdef AT_FDCWD +#if HAVE_OPENAT_SUPPORT entry_status = fstatat (fd, d->d_name, &st, AT_SYMLINK_NOFOLLOW); #else /* Compute size needed for this file name, or for the file @@ -387,7 +390,7 @@ if (dirp == &dir[allocated - 1]) *--dirp = '/'; -#ifndef AT_FDCWD +#if ! HAVE_OPENAT_SUPPORT if (dotlist != dots) free (dotlist); #endif @@ -413,7 +416,7 @@ int save = errno; if (dirstream) __closedir (dirstream); -#ifdef AT_FDCWD +#if HAVE_OPENAT_SUPPORT if (fd_needs_closing) close (fd); #else