[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
new module fchdir
From: |
Bruno Haible |
Subject: |
new module fchdir |
Date: |
Tue, 2 Jan 2007 22:14:09 +0100 |
User-agent: |
KMail/1.9.1 |
Hi,
Following Jim's and Paul's ideas for portability of the coreutils to
BeOS, Woe32 and DJGPP, which all lack an fchdir(), here is a first working
fchdir module.
The module installs wrappers around open(), close(), opendir(), closedir(),
dup(), dup2(). Quite heavy; especially the relation to the *-safer modules
is tricky. Also the 'dup-safer', 'getcwd', 'unistd' modules are affected.
The many changes to backupfile.c...utime.c are mere optimizations.
With these changes, coreutils-6.7 passes "make check" on Linux and MacOS X,
except for an ENAMETOOLONG error in misc/pwd-long (to be expected) on Linux
and an rm/deep-1 failure on MacOS X. And on BeOS, it builds as reasonably as
my previous, more intrusive patch in September 2006.
I put the module under LGPL, so that fts-lgpl can use it. This implies that it
relies on 'canonicalize-lgpl', not 'canonicalize'.
Opinions?
If you want to test this with coreutils, you need to add fchdir to the
module list, use --avoid=canonicalize-lgpl, and drop the fchdir-stub.c.
2006-12-30 Bruno Haible <address@hidden>
* modules/fchdir: New file.
* modules/unistd (Files): Add lib/unistd_.h.
(Makefile.am): Generate unistd.h from unistd_.h.
* lib/fchdir.c: New file.
* lib/dirent_.h: New file.
* lib/unistd_.h: New file.
* lib/fcntl_.h (open) [FCHDIR_REPLACEMENT]: New replacement.
* m4/fchdir.m4: New file.
* m4/unistd_h.m4 (gl_PREREQ_UNISTD): New macro.
(gl_HEADER_UNISTD): Invoke it.
* lib/dup-safer.c (dup_safer) [FCHDIR_REPLACEMENT]: Use the dup
function.
* lib/backupfile.c (opendir, closedir): Undefine.
* lib/chown.c (open, close): Undefine.
* lib/clean-temp.c (open, close): Undefine.
* lib/copy-file.c (open, close): Undefine.
* lib/execute.c (open, close): Undefine.
* lib/fsusage.c (open, close): Undefine.
* lib/gc-gnulib.c (open, close): Undefine.
* lib/getcwd.c (opendir, closedir): Undefine.
* lib/glob.c (opendir, closedir): Undefine.
* lib/javacomp.c (open, close): Undefine.
* lib/mountlist.c (open, close, opendir, closedir): Undefine.
* lib/openat-proc.c (open, close): Undefine.
* lib/pagealign_alloc.c (open, close): Undefine.
* lib/pipe.c (open, close): Undefine.
* lib/progreloc.c (open, close): Undefine.
* lib/savedir.c (opendir, closedir): Undefine.
* lib/utime.c (open, close): Undefine.
diff -r -c3 --unidirectional-new-file --exclude='*.bak'
gnulib-20061223/modules/fchdir gnulib-20061223/modules/fchdir
*** gnulib-20061223/modules/fchdir 1970-01-01 01:00:00.000000000 +0100
--- gnulib-20061223/modules/fchdir 2006-12-30 01:18:23.000000000 +0100
***************
*** 0 ****
--- 1,41 ----
+ Description:
+ fchdir() function: change current directory, given an open file descriptor.
+
+ Files:
+ lib/fchdir.c
+ lib/dirent_.h
+ m4/fchdir.m4
+
+ Depends-on:
+ fcntl
+ unistd
+ canonicalize-lgpl
+ dirfd
+ strdup
+
+ configure.ac:
+ gl_FUNC_FCHDIR
+
+ Makefile.am:
+ BUILT_SOURCES += $(DIRENT_H) $(UNISTD_H2)
+
+ # We need the following in order to create <dirent.h> when the system
+ # doesn't have one that works with the given compiler.
+ dirent.h: dirent_.h
+ rm -f address@hidden $@
+ { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
+ sed -e 's|@''ABSOLUTE_DIRENT_H''@|$(ABSOLUTE_DIRENT_H)|g' \
+ < $(srcdir)/dirent_.h; \
+ } > address@hidden
+ mv address@hidden $@
+ MOSTLYCLEANFILES += dirent.h dirent.h-t
+
+ Include:
+ #include <unistd.h>
+
+ License:
+ LGPL
+
+ Maintainer:
+ Bruno Haible
+
*** gnulib-20061223/modules/unistd.bak 2006-10-07 21:30:46.000000000 +0200
--- gnulib-20061223/modules/unistd 2006-12-30 22:07:45.000000000 +0100
***************
*** 3,8 ****
--- 3,9 ----
Files:
m4/unistd_h.m4
+ lib/unistd_.h
Depends-on:
***************
*** 14,24 ****
# We need the following in order to create an empty placeholder for
# <unistd.h> when the system doesn't have one.
! unistd.h:
{ echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
! echo '/* Empty placeholder for address@hidden */'; \
! } > $@
! MOSTLYCLEANFILES += unistd.h
Include:
#include <unistd.h>
--- 15,28 ----
# We need the following in order to create an empty placeholder for
# <unistd.h> when the system doesn't have one.
! unistd.h: unistd_.h
! rm -f address@hidden $@
{ echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
! sed -e 's|@''ABSOLUTE_UNISTD_H''@|$(ABSOLUTE_UNISTD_H)|g' \
! < $(srcdir)/unistd_.h; \
! } > address@hidden
! mv address@hidden $@
! MOSTLYCLEANFILES += unistd.h unistd.h-t
Include:
#include <unistd.h>
diff -r -c3 --unidirectional-new-file --exclude='*.bak'
gnulib-20061223/lib/fchdir.c gnulib-20061223/lib/fchdir.c
*** gnulib-20061223/lib/fchdir.c 1970-01-01 01:00:00.000000000 +0100
--- gnulib-20061223/lib/fchdir.c 2006-12-30 21:32:47.000000000 +0100
***************
*** 0 ****
--- 1,276 ----
+ /* fchdir replacement.
+ Copyright (C) 2006 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software Foundation,
+ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
+
+ #include <config.h>
+
+ #include <errno.h>
+ #include <fcntl.h>
+ #include <stdarg.h>
+ #include <stdlib.h>
+ #include <unistd.h>
+ #include <sys/types.h>
+ #include <sys/stat.h>
+ #include <dirent.h>
+
+ #include "canonicalize.h"
+ #include "dirfd.h"
+ #include "strdup.h"
+
+ /* This replacement assumes that a directory is not renamed while opened
+ through a file descriptor. */
+
+ /* Array of file descriptors opened. If it points to a directory, it stores
info about
+ this directory; otherwise it stores an errno value of ENOTDIR. */
+ typedef struct
+ {
+ char *name; /* Absolute name of the directory, or NULL. */
+ int saved_errno; /* If name == NULL: The error code describing the failure
reason. */
+ } dir_info_t;
+ static dir_info_t *dirs;
+ static size_t dirs_allocated;
+
+ /* Try to ensure dirs has enough room for a slot at index fd. */
+ static void
+ ensure_dirs_slot (size_t fd)
+ {
+ if (fd >= dirs_allocated)
+ {
+ size_t new_allocated;
+ dir_info_t *new_dirs;
+ size_t i;
+
+ new_allocated = 2 * dirs_allocated + 1;
+ if (new_allocated <= fd)
+ new_allocated = fd + 1;
+ new_dirs =
+ (dirs != NULL
+ ? (dir_info_t *) realloc (dirs, new_allocated * sizeof (dir_info_t))
+ : (dir_info_t *) malloc (new_allocated * sizeof (dir_info_t)));
+ if (new_dirs != NULL)
+ {
+ for (i = dirs_allocated; i < new_allocated; i++)
+ {
+ new_dirs[i].name = NULL;
+ new_dirs[i].saved_errno = ENOTDIR;
+ }
+ dirs = new_dirs;
+ dirs_allocated = new_allocated;
+ }
+ }
+ }
+
+ /* Override open() and close(), to keep track of the open file descriptors.
*/
+
+ int
+ close (int fd)
+ #undef close
+ {
+ int retval = close (fd);
+
+ if (retval >= 0 && fd >= 0 && fd < dirs_allocated)
+ {
+ if (dirs[fd].name != NULL)
+ free (dirs[fd].name);
+ dirs[fd].name = NULL;
+ dirs[fd].saved_errno = ENOTDIR;
+ }
+ return retval;
+ }
+
+ int
+ open (const char *filename, int flags, ...)
+ #undef open
+ {
+ mode_t mode;
+ int fd;
+ struct stat statbuf;
+
+ mode = 0;
+ if (flags & O_CREAT)
+ {
+ va_list arg;
+ va_start (arg, flags);
+
+ /* If mode_t is narrower than int, use the promoted type (int),
+ not mode_t. Use sizeof to guess whether mode_t is narrower;
+ we don't know of any practical counterexamples. */
+ mode = (sizeof (mode_t) < sizeof (int)
+ ? va_arg (arg, int)
+ : va_arg (arg, mode_t));
+
+ va_end (arg);
+ }
+ fd = open (filename, flags, mode);
+ if (fd >= 0)
+ {
+ ensure_dirs_slot (fd);
+ if (fd < dirs_allocated
+ && fstat (fd, &statbuf) >= 0 && S_ISDIR (statbuf.st_mode))
+ {
+ dirs[fd].name = canonicalize_file_name (filename);
+ if (dirs[fd].name == NULL)
+ dirs[fd].saved_errno = errno;
+ }
+ }
+ return fd;
+ }
+
+ /* Override opendir() and closedir(), to keep track of the open file
+ descriptors. Needed because there is a function dirfd(). */
+
+ int
+ closedir (DIR *dp)
+ #undef closedir
+ {
+ int fd = dirfd (dp);
+ int retval = closedir (dp);
+
+ if (retval >= 0 && fd >= 0 && fd < dirs_allocated)
+ {
+ if (dirs[fd].name != NULL)
+ free (dirs[fd].name);
+ dirs[fd].name = NULL;
+ dirs[fd].saved_errno = ENOTDIR;
+ }
+ return retval;
+ }
+
+ DIR *
+ opendir (const char *filename)
+ #undef opendir
+ {
+ DIR *dp;
+
+ dp = opendir (filename);
+ if (dp != NULL)
+ {
+ int fd = dirfd (dp);
+ if (fd >= 0)
+ {
+ ensure_dirs_slot (fd);
+ if (fd < dirs_allocated)
+ {
+ dirs[fd].name = canonicalize_file_name (filename);
+ if (dirs[fd].name == NULL)
+ dirs[fd].saved_errno = errno;
+ }
+ }
+ }
+ return dp;
+ }
+
+ /* Override dup() and dup2(), to keep track of open file descriptors. */
+
+ int
+ dup (int oldfd)
+ #undef dup
+ {
+ int newfd = dup (oldfd);
+
+ if (oldfd >= 0 && newfd >= 0)
+ {
+ ensure_dirs_slot (newfd);
+ if (newfd < dirs_allocated)
+ {
+ if (oldfd < dirs_allocated)
+ {
+ if (dirs[oldfd].name != NULL)
+ {
+ dirs[newfd].name = strdup (dirs[oldfd].name);
+ if (dirs[newfd].name == NULL)
+ dirs[newfd].saved_errno = ENOMEM;
+ }
+ else
+ {
+ dirs[newfd].name = NULL;
+ dirs[newfd].saved_errno = dirs[oldfd].saved_errno;
+ }
+ }
+ else
+ {
+ dirs[newfd].name = NULL;
+ dirs[newfd].saved_errno = ENOMEM;
+ }
+ }
+ }
+ return newfd;
+ }
+
+ int
+ dup2 (int oldfd, int newfd)
+ #undef dup2
+ {
+ int retval = dup2 (oldfd, newfd);
+
+ if (retval >= 0 && oldfd >= 0 && newfd >= 0 && newfd != oldfd)
+ {
+ ensure_dirs_slot (newfd);
+ if (newfd < dirs_allocated)
+ {
+ if (oldfd < dirs_allocated)
+ {
+ if (dirs[oldfd].name != NULL)
+ {
+ dirs[newfd].name = strdup (dirs[oldfd].name);
+ if (dirs[newfd].name == NULL)
+ dirs[newfd].saved_errno = ENOMEM;
+ }
+ else
+ {
+ dirs[newfd].name = NULL;
+ dirs[newfd].saved_errno = dirs[oldfd].saved_errno;
+ }
+ }
+ else
+ {
+ dirs[newfd].name = NULL;
+ dirs[newfd].saved_errno = ENOMEM;
+ }
+ }
+ }
+ return retval;
+ }
+
+ /* Implement fchdir() in terms of chdir(). */
+
+ int
+ fchdir (int fd)
+ {
+ if (fd >= 0)
+ {
+ if (fd < dirs_allocated)
+ {
+ if (dirs[fd].name != NULL)
+ return chdir (dirs[fd].name);
+ else
+ {
+ errno = dirs[fd].saved_errno;
+ return -1;
+ }
+ }
+ else
+ {
+ errno = ENOMEM;
+ return -1;
+ }
+ }
+ else
+ {
+ errno = EBADF;
+ return -1;
+ }
+ }
diff -r -c3 --unidirectional-new-file --exclude='*.bak'
gnulib-20061223/lib/dirent_.h gnulib-20061223/lib/dirent_.h
*** gnulib-20061223/lib/dirent_.h 1970-01-01 01:00:00.000000000 +0100
--- gnulib-20061223/lib/dirent_.h 2006-12-30 21:28:31.000000000 +0100
***************
*** 0 ****
--- 1,42 ----
+ /* Wrapper around <dirent.h>.
+ Copyright (C) 2006 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software Foundation,
+ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
+
+ #ifndef _GL_DIRENT_H
+ #define _GL_DIRENT_H
+
+ #include @ABSOLUTE_DIRENT_H@
+
+
+ /* Declare overridden functions. */
+
+ #ifdef __cplusplus
+ extern "C" {
+ #endif
+
+ #ifdef FCHDIR_REPLACEMENT
+ # define opendir rpl_opendir
+ extern DIR * opendir (const char *);
+ # define closedir rpl_closedir
+ extern int closedir (DIR *);
+ #endif
+
+ #ifdef __cplusplus
+ }
+ #endif
+
+
+ #endif /* _GL_DIRENT_H */
diff -r -c3 --unidirectional-new-file --exclude='*.bak'
gnulib-20061223/lib/unistd_.h gnulib-20061223/lib/unistd_.h
*** gnulib-20061223/lib/unistd_.h 1970-01-01 01:00:00.000000000 +0100
--- gnulib-20061223/lib/unistd_.h 2006-12-30 01:21:44.000000000 +0100
***************
*** 0 ****
--- 1,52 ----
+ /* Substitute for and wrapper around <unistd.h>.
+ Copyright (C) 2006 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software Foundation,
+ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
+
+ #ifndef _GL_UNISTD_H
+ #define _GL_UNISTD_H
+
+ #if HAVE_UNISTD_H
+ # include @ABSOLUTE_UNISTD_H@
+ #endif
+
+
+ /* Declare overridden functions. */
+
+ #ifdef __cplusplus
+ extern "C" {
+ #endif
+
+ #ifdef FCHDIR_REPLACEMENT
+
+ /* Change the process' current working directory to the directory on which
+ the given file descriptor is open. */
+ extern int fchdir (int /*fd*/);
+
+ # define close rpl_close
+ extern int close (int);
+ # define dup rpl_dup
+ extern int dup (int);
+ # define dup2 rpl_dup2
+ extern int dup2 (int, int);
+
+ #endif
+
+ #ifdef __cplusplus
+ }
+ #endif
+
+
+ #endif /* _GL_UNISTD_H */
diff -r -c3 --unidirectional-new-file --exclude='*.bak'
gnulib-20061223/lib/fcntl_.h gnulib-20061223/lib/fcntl_.h
*** gnulib-20061223/lib/fcntl_.h 2006-10-07 01:01:48.000000000 +0200
--- gnulib-20061223/lib/fcntl_.h 2006-12-30 00:41:41.000000000 +0100
***************
*** 26,31 ****
--- 26,50 ----
#include <unistd.h>
#include @ABSOLUTE_FCNTL_H@
+
+ /* Declare overridden functions. */
+
+ #ifdef __cplusplus
+ extern "C" {
+ #endif
+
+ #ifdef FCHDIR_REPLACEMENT
+ # define open rpl_open
+ extern int open (const char *, int, ...);
+ #endif
+
+ #ifdef __cplusplus
+ }
+ #endif
+
+
+ /* Fix up the O_* macros. */
+
#if !defined O_DIRECT && defined O_DIRECTIO
/* Tru64 spells it `O_DIRECTIO'. */
# define O_DIRECT O_DIRECTIO
diff -r -c3 --unidirectional-new-file --exclude='*.bak'
gnulib-20061223/m4/fchdir.m4 gnulib-20061223/m4/fchdir.m4
*** gnulib-20061223/m4/fchdir.m4 1970-01-01 01:00:00.000000000 +0100
--- gnulib-20061223/m4/fchdir.m4 2006-12-30 01:17:48.000000000 +0100
***************
*** 0 ****
--- 1,29 ----
+ # fchdir.m4 serial 1
+ dnl Copyright (C) 2006 Free Software Foundation, Inc.
+ dnl This file is free software; the Free Software Foundation
+ dnl gives unlimited permission to copy and/or distribute it,
+ dnl with or without modifications, as long as this notice is preserved.
+
+ AC_DEFUN([gl_FUNC_FCHDIR],
+ [
+ AC_CHECK_FUNCS_ONCE([fchdir])
+ if test $ac_cv_func_fchdir = no; then
+ AC_LIBOBJ([fchdir])
+ gl_PREREQ_FCHDIR
+ AC_DEFINE([FCHDIR_REPLACEMENT], 1,
+ [Define if gnulib's fchdir() replacement is used.])
+ gl_ABSOLUTE_HEADER([dirent.h])
+ ABSOLUTE_DIRENT_H=\"$gl_cv_absolute_dirent_h\"
+ DIRENT_H='dirent.h'
+ UNISTD_H2='unistd.h'
+ else
+ DIRENT_H=
+ UNISTD_H2=
+ fi
+ AC_SUBST([ABSOLUTE_DIRENT_H])
+ AC_SUBST([DIRENT_H])
+ AC_SUBST([UNISTD_H2])
+ ])
+
+ # Prerequisites of lib/fchdir.c.
+ AC_DEFUN([gl_PREREQ_FCHDIR], [:])
diff -r -c3 --unidirectional-new-file --exclude='*.bak'
gnulib-20061223/m4/unistd_h.m4 gnulib-20061223/m4/unistd_h.m4
*** gnulib-20061223/m4/unistd_h.m4 2006-03-08 02:45:53.000000000 +0100
--- gnulib-20061223/m4/unistd_h.m4 2006-12-30 01:29:15.000000000 +0100
***************
*** 1,4 ****
! # unistd_h.m4 serial 2
dnl Copyright (C) 2006 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
--- 1,4 ----
! # unistd_h.m4 serial 3
dnl Copyright (C) 2006 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,18 ****
AC_DEFUN([gl_HEADER_UNISTD],
[
- dnl Prerequisites of lib/unistd.h.
AC_CHECK_HEADERS([unistd.h], [
UNISTD_H=''
], [
UNISTD_H='unistd.h'
])
AC_SUBST(UNISTD_H)
])
--- 8,32 ----
AC_DEFUN([gl_HEADER_UNISTD],
[
AC_CHECK_HEADERS([unistd.h], [
UNISTD_H=''
], [
UNISTD_H='unistd.h'
])
AC_SUBST(UNISTD_H)
+ dnl This module decides to build unistd.h if it is missing.
+ dnl The fchdir module decides to build unistd.h if fchdir() is missing.
+ dnl Therefore check for the prerequisites of lib/unistd.h always.
+ gl_PREREQ_UNISTD
+ ])
+
+ dnl Prerequisites of lib/unistd.h.
+ AC_DEFUN([gl_PREREQ_UNISTD],
+ [
+ AC_CHECK_HEADERS_ONCE([unistd.h])
+ if test $ac_cv_header_unistd_h = yes; then
+ gl_ABSOLUTE_HEADER([unistd.h])
+ ABSOLUTE_UNISTD_H=\"$gl_cv_absolute_unistd_h\"
+ fi
+ AC_SUBST([ABSOLUTE_UNISTD_H])
])
diff -r -c3 --unidirectional-new-file --exclude='*.bak'
gnulib-20061223/lib/dup-safer.c gnulib-20061223/lib/dup-safer.c
*** gnulib-20061223/lib/dup-safer.c 2006-09-19 00:51:16.000000000 +0200
--- gnulib-20061223/lib/dup-safer.c 2006-12-30 01:59:46.000000000 +0100
***************
*** 35,41 ****
int
dup_safer (int fd)
{
! #ifdef F_DUPFD
return fcntl (fd, F_DUPFD, STDERR_FILENO + 1);
#else
/* fd_safer calls us back, but eventually the recursion unwinds and
--- 35,41 ----
int
dup_safer (int fd)
{
! #if defined F_DUPFD && !defined FCHDIR_REPLACEMENT
return fcntl (fd, F_DUPFD, STDERR_FILENO + 1);
#else
/* fd_safer calls us back, but eventually the recursion unwinds and
diff -r -c3 --unidirectional-new-file --exclude='*.bak'
gnulib-20061223/lib/backupfile.c gnulib-20061223/lib/backupfile.c
*** gnulib-20061223/lib/backupfile.c 2006-09-19 00:51:15.000000000 +0200
--- gnulib-20061223/lib/backupfile.c 2006-12-30 01:59:45.000000000 +0100
***************
*** 82,87 ****
--- 82,92 ----
of `digit' even when the host does not conform to POSIX. */
#define ISDIGIT(c) ((unsigned int) (c) - '0' <= 9)
+ /* The results of opendir() in this file are not used with dirfd and fchdir,
+ therefore save some unnecessary work in fchdir.c. */
+ #undef opendir
+ #undef closedir
+
/* The extension added to file names to produce a simple (as opposed
to numbered) backup file name. */
char const *simple_backup_suffix = "~";
diff -r -c3 --unidirectional-new-file --exclude='*.bak'
gnulib-20061223/lib/chown.c gnulib-20061223/lib/chown.c
*** gnulib-20061223/lib/chown.c 2006-11-07 01:19:05.000000000 +0100
--- gnulib-20061223/lib/chown.c 2006-12-30 16:16:25.000000000 +0100
***************
*** 33,38 ****
--- 33,43 ----
#include <fcntl.h>
#include <errno.h>
+ /* The results of open() in this file are not used with fchdir,
+ therefore save some unnecessary work in fchdir.c. */
+ #undef open
+ #undef close
+
/* Provide a more-closely POSIX-conforming version of chown on
systems with one or both of the following problems:
- chown doesn't treat an ID of -1 as meaning
diff -r -c3 --unidirectional-new-file --exclude='*.bak'
gnulib-20061223/lib/clean-temp.c gnulib-20061223/lib/clean-temp.c
*** gnulib-20061223/lib/clean-temp.c 2006-11-04 02:35:33.000000000 +0100
--- gnulib-20061223/lib/clean-temp.c 2006-12-30 16:27:19.000000000 +0100
***************
*** 67,72 ****
--- 67,79 ----
# define uintptr_t unsigned long
#endif
+ #if !GNULIB_FCNTL_SAFER
+ /* The results of open() in this file are not used with fchdir,
+ therefore save some unnecessary work in fchdir.c. */
+ # undef open
+ # undef close
+ #endif
+
/* The use of 'volatile' in the types below (and ISO C 99 section 5.1.2.3.(5))
ensure that while constructing or modifying the data structures, the field
diff -r -c3 --unidirectional-new-file --exclude='*.bak'
gnulib-20061223/lib/copy-file.c gnulib-20061223/lib/copy-file.c
*** gnulib-20061223/lib/copy-file.c 2006-12-22 02:53:09.000000000 +0100
--- gnulib-20061223/lib/copy-file.c 2006-12-30 16:17:36.000000000 +0100
***************
*** 46,51 ****
--- 46,57 ----
#define _(str) gettext (str)
+ /* The results of open() in this file are not used with fchdir,
+ therefore save some unnecessary work in fchdir.c. */
+ #undef open
+ #undef close
+
+
void
copy_file_preserving (const char *src_filename, const char *dest_filename)
{
diff -r -c3 --unidirectional-new-file --exclude='*.bak'
gnulib-20061223/lib/execute.c gnulib-20061223/lib/execute.c
*** gnulib-20061223/lib/execute.c 2006-09-19 00:51:16.000000000 +0200
--- gnulib-20061223/lib/execute.c 2006-12-30 16:18:40.000000000 +0100
***************
*** 70,75 ****
--- 70,80 ----
# define STDERR_FILENO 2
#endif
+ /* The results of open() in this file are not used with fchdir,
+ therefore save some unnecessary work in fchdir.c. */
+ #undef open
+ #undef close
+
#ifdef EINTR
diff -r -c3 --unidirectional-new-file --exclude='*.bak'
gnulib-20061223/lib/fsusage.c gnulib-20061223/lib/fsusage.c
*** gnulib-20061223/lib/fsusage.c 2006-10-20 00:23:38.000000000 +0200
--- gnulib-20061223/lib/fsusage.c 2006-12-30 16:19:54.000000000 +0100
***************
*** 56,61 ****
--- 56,66 ----
# include "full-read.h"
#endif
+ /* The results of open() in this file are not used with fchdir,
+ therefore save some unnecessary work in fchdir.c. */
+ #undef open
+ #undef close
+
/* Many space usage primitives use all 1 bits to denote a value that is
not applicable or unknown. Propagate this information by returning
a uintmax_t value that is all 1 bits if X is all 1 bits, even if X
diff -r -c3 --unidirectional-new-file --exclude='*.bak'
gnulib-20061223/lib/gc-gnulib.c gnulib-20061223/lib/gc-gnulib.c
*** gnulib-20061223/lib/gc-gnulib.c 2006-11-07 01:19:05.000000000 +0100
--- gnulib-20061223/lib/gc-gnulib.c 2006-12-30 16:20:25.000000000 +0100
***************
*** 68,73 ****
--- 68,78 ----
# include "rijndael-api-fst.h"
#endif
+ /* The results of open() in this file are not used with fchdir,
+ therefore save some unnecessary work in fchdir.c. */
+ #undef open
+ #undef close
+
Gc_rc
gc_init (void)
{
diff -r -c3 --unidirectional-new-file --exclude='*.bak'
gnulib-20061223/lib/getcwd.c gnulib-20061223/lib/getcwd.c
*** gnulib-20061223/lib/getcwd.c 2006-09-19 00:51:16.000000000 +0200
--- gnulib-20061223/lib/getcwd.c 2006-12-30 01:59:46.000000000 +0100
***************
*** 97,102 ****
--- 97,107 ----
# define __opendir opendir
# define __readdir readdir
#endif
+
+ /* The results of opendir() in this file are not used with dirfd and fchdir,
+ therefore save some unnecessary recursion in fchdir.c. */
+ #undef opendir
+ #undef closedir
/* Get the name of the current working directory, and put it in SIZE
bytes of BUF. Returns NULL if the directory couldn't be determined or
diff -r -c3 --unidirectional-new-file --exclude='*.bak'
gnulib-20061223/lib/glob.c gnulib-20061223/lib/glob.c
*** gnulib-20061223/lib/glob.c 2006-11-07 01:19:06.000000000 +0100
--- gnulib-20061223/lib/glob.c 2006-12-30 02:11:23.000000000 +0100
***************
*** 162,167 ****
--- 162,172 ----
#endif /* !defined _LIBC || !defined GLOB_ONLY_P */
+ /* The results of opendir() in this file are not used with dirfd and fchdir,
+ therefore save some unnecessary work in fchdir.c. */
+ #undef opendir
+ #undef closedir
+
static int glob_in_dir (const char *pattern, const char *directory,
int flags, int (*errfunc) (const char *, int),
glob_t *pglob);
diff -r -c3 --unidirectional-new-file --exclude='*.bak'
gnulib-20061223/lib/javacomp.c gnulib-20061223/lib/javacomp.c
*** gnulib-20061223/lib/javacomp.c 2006-10-07 01:01:48.000000000 +0200
--- gnulib-20061223/lib/javacomp.c 2006-12-30 16:23:59.000000000 +0100
***************
*** 53,58 ****
--- 53,63 ----
#define _(str) gettext (str)
+ /* The results of open() in this file are not used with fchdir,
+ therefore save some unnecessary work in fchdir.c. */
+ #undef open
+ #undef close
+
/* Survey of Java compilers.
diff -r -c3 --unidirectional-new-file --exclude='*.bak'
gnulib-20061223/lib/mountlist.c gnulib-20061223/lib/mountlist.c
*** gnulib-20061223/lib/mountlist.c 2006-09-19 00:51:16.000000000 +0200
--- gnulib-20061223/lib/mountlist.c 2006-12-30 16:15:05.000000000 +0100
***************
*** 143,148 ****
--- 143,158 ----
# define SIZE_MAX ((size_t) -1)
#endif
+ /* The results of open() in this file are not used with fchdir,
+ therefore save some unnecessary work in fchdir.c. */
+ #undef open
+ #undef close
+
+ /* The results of opendir() in this file are not used with dirfd and fchdir,
+ therefore save some unnecessary work in fchdir.c. */
+ #undef opendir
+ #undef closedir
+
#ifndef ME_DUMMY
# define ME_DUMMY(Fs_name, Fs_type) \
(strcmp (Fs_type, "autofs") == 0 \
diff -r -c3 --unidirectional-new-file --exclude='*.bak'
gnulib-20061223/lib/openat-proc.c gnulib-20061223/lib/openat-proc.c
*** gnulib-20061223/lib/openat-proc.c 2006-09-30 02:37:48.000000000 +0200
--- gnulib-20061223/lib/openat-proc.c 2006-12-30 16:23:02.000000000 +0100
***************
*** 34,39 ****
--- 34,44 ----
#include "same-inode.h"
#include "xalloc.h"
+ /* The results of open() in this file are not used with fchdir,
+ therefore save some unnecessary work in fchdir.c. */
+ #undef open
+ #undef close
+
#define PROC_SELF_FD_FORMAT "/proc/self/fd/%d/%s"
#define PROC_SELF_FD_NAME_SIZE_BOUND(len) \
diff -r -c3 --unidirectional-new-file --exclude='*.bak'
gnulib-20061223/lib/pagealign_alloc.c gnulib-20061223/lib/pagealign_alloc.c
*** gnulib-20061223/lib/pagealign_alloc.c 2006-11-04 02:35:33.000000000
+0100
--- gnulib-20061223/lib/pagealign_alloc.c 2006-12-30 16:24:28.000000000
+0100
***************
*** 52,57 ****
--- 52,62 ----
# endif
#endif
+ /* The results of open() in this file are not used with fchdir,
+ therefore save some unnecessary work in fchdir.c. */
+ #undef open
+ #undef close
+
#if HAVE_MMAP || ! HAVE_POSIX_MEMALIGN
diff -r -c3 --unidirectional-new-file --exclude='*.bak'
gnulib-20061223/lib/pipe.c gnulib-20061223/lib/pipe.c
*** gnulib-20061223/lib/pipe.c 2006-09-19 00:51:16.000000000 +0200
--- gnulib-20061223/lib/pipe.c 2006-12-30 16:19:02.000000000 +0100
***************
*** 69,74 ****
--- 69,79 ----
# define STDERR_FILENO 2
#endif
+ /* The results of open() in this file are not used with fchdir,
+ therefore save some unnecessary work in fchdir.c. */
+ #undef open
+ #undef close
+
#ifdef EINTR
diff -r -c3 --unidirectional-new-file --exclude='*.bak'
gnulib-20061223/lib/progreloc.c gnulib-20061223/lib/progreloc.c
*** gnulib-20061223/lib/progreloc.c 2006-09-19 00:51:16.000000000 +0200
--- gnulib-20061223/lib/progreloc.c 2006-12-30 16:14:09.000000000 +0100
***************
*** 77,82 ****
--- 77,87 ----
# define FILE_SYSTEM_PREFIX_LEN(P) 0
#endif
+ /* The results of open() in this file are not used with fchdir,
+ therefore save some unnecessary work in fchdir.c. */
+ #undef open
+ #undef close
+
#undef set_program_name
diff -r -c3 --unidirectional-new-file --exclude='*.bak'
gnulib-20061223/lib/savedir.c gnulib-20061223/lib/savedir.c
*** gnulib-20061223/lib/savedir.c 2006-09-19 00:51:16.000000000 +0200
--- gnulib-20061223/lib/savedir.c 2006-12-30 01:59:46.000000000 +0100
***************
*** 43,48 ****
--- 43,53 ----
# define NAME_SIZE_DEFAULT 512
#endif
+ /* The results of opendir() in this file are not used with dirfd and fchdir,
+ therefore save some unnecessary work in fchdir.c. */
+ #undef opendir
+ #undef closedir
+
/* Return a freshly allocated string containing the file names
in directory DIRP, separated by '\0' characters;
the end is marked by two '\0' characters in a row.
diff -r -c3 --unidirectional-new-file --exclude='*.bak'
gnulib-20061223/lib/utime.c gnulib-20061223/lib/utime.c
*** gnulib-20061223/lib/utime.c 2006-09-19 00:51:16.000000000 +0200
--- gnulib-20061223/lib/utime.c 2006-12-30 16:12:10.000000000 +0100
***************
*** 47,52 ****
--- 47,57 ----
};
#endif
+ /* The results of open() in this file are not used with fchdir,
+ therefore save some unnecessary work in fchdir.c. */
+ #undef open
+ #undef close
+
/* Emulate utime (file, NULL) for systems (like 4.3BSD) that do not
interpret it to set the access and modification times of FILE to
the current time. Return 0 if successful, -1 if not. */
- new module fchdir,
Bruno Haible <=