annotate lib/openat-priv.h @ 7151:43e3888c56c4

Update from coreutils. * lib/__fpending.h: Add copyright notice. * lib/fprintftime.h: Likewise. * lib/savedir.c: Use (C) in copyright notice. * lib/savedir.h: Likewise. 2006-08-15 Jim Meyering <jim@meyering.net> * lib/at-func.c: New file, with the logic of all emulated at-functions. * lib/openat-priv.h: Include <errno.h> and define ENOSYS, in support of the EXPECTED_ERRNO macro. * lib/openat.c (fstatat, unlinkat, fchownat): Remove function definitions. Instead, define the appropriate symbols and include "at-func.c". * lib/mkdirat.c (mkdirat): Likewise. * lib/fchmodat.c (fchmodat): Likewise. (ENOSYS): Remove definition. * lib/openat.c: Don't include <errno.h>, now that "openat-priv.h" does it. Don't include "unistd--.h" -- it wasn't ever used. 2006-01-17 Jim Meyering <jim@meyering.net> Rewrite fts.c not to change the current working directory, by using openat, fstatat, fdopendir, etc.. * lib/fts.c [! _LIBC]: Include "openat.h" and "unistd--.h". (HAVE_OPENAT_SUPPORT): Define. [_LIBC] (fchdir): Don't undef or define; no longer used. (FCHDIR): Define in terms of cwd_advance_fd rather than fchdir. Now, this `function' always succeeds, and consumes its file descriptor parameter -- so callers must not close such FDs. Update callers. (diropen_fd, opendirat, cwd_advance_fd): New functions. (diropen): Add parameter, SP. Adjust all callers. Implement using diropen_fd, rather than open. (fts_open): Initialize new member, fts_cwd_fd. Remove fts_rft-setting code. (fts_close): Close fts_cwd_fd, if necessary. (__opendir2): Define in terms of opendir or opendirat, depending on whether the FST_NOCHDIR flag is set. (fts_build): Since fts_safe_changedir consumes its FD, and since this code must do `closedir(dirp)', dup the dirfd(dirp) argument, and close the dup'd file descriptor upon failure. (fts_stat): Use fstatat(...AT_SYMLINK_NOFOLLOW) in place of lstat. (fts_safe_changedir): Tweak semantics to reflect that this function now calls cwd_advance_fd and hence consumes its FD argument. * lib/fts_.h [struct FTS] (fts_cwd_fd): New member. [struct FTS] (fts_rft): Remove now-unused member. [struct FTS] (fts_cycle.state): Improve comment. * lib/openat.c (openat_needs_fchdir): New function. * lib/openat.h (openat_needs_fchdir): Declare it. 2006-08-15 Jim Meyering <jim@meyering.net> * m4/openat.m4 (gl_FUNC_OPENAT): Add at-func.c via AC_LIBSOURCES. 2006-01-17 Jim Meyering <jim@meyering.net> * m4/fts.m4 (gl_FUNC_FTS_CORE): Depend on gl_FUNC_OPENAT. 2006-01-11 Jim Meyering <jim@meyering.net> * m4/openat.m4 (gl_FUNC_OPENAT): Require and compile fchmodat.c. Check for the lchmod function.
author Paul Eggert <eggert@cs.ucla.edu>
date Thu, 17 Aug 2006 20:34:21 +0000
parents 6b31c8787689
children 0f8d70c02f29
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6527
6b31c8787689 Sync from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
1 /* macros used by openat-like functions
6b31c8787689 Sync from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
2 Copyright (C) 2005 Free Software Foundation, Inc.
6b31c8787689 Sync from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
3
6b31c8787689 Sync from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
4 This program is free software; you can redistribute it and/or modify
6b31c8787689 Sync from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
5 it under the terms of the GNU General Public License as published by
6b31c8787689 Sync from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
6 the Free Software Foundation; either version 2, or (at your option)
6b31c8787689 Sync from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
7 any later version.
6b31c8787689 Sync from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
8
6b31c8787689 Sync from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
6b31c8787689 Sync from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
6b31c8787689 Sync from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6b31c8787689 Sync from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
12 GNU General Public License for more details.
6b31c8787689 Sync from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
13
6b31c8787689 Sync from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
14 You should have received a copy of the GNU General Public License
6b31c8787689 Sync from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
15 along with this program; if not, write to the Free Software Foundation,
6b31c8787689 Sync from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
16 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
6b31c8787689 Sync from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
17
6b31c8787689 Sync from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
18 /* written by Jim Meyering */
6b31c8787689 Sync from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
19
6b31c8787689 Sync from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
20 #include <stdio.h>
6b31c8787689 Sync from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
21 #include <string.h>
7151
43e3888c56c4 Update from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 6527
diff changeset
22 #include <errno.h>
6527
6b31c8787689 Sync from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
23 #include "alloca.h"
6b31c8787689 Sync from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
24 #include "intprops.h"
6b31c8787689 Sync from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
25
6b31c8787689 Sync from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
26 /* Set PROC_FD_FILENAME to the expansion of "/proc/self/fd/%d/%s" in
6b31c8787689 Sync from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
27 alloca'd memory, using FD and FILE, respectively for %d and %s. */
6b31c8787689 Sync from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
28 #define BUILD_PROC_NAME(Proc_fd_filename, Fd, File) \
6b31c8787689 Sync from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
29 do \
6b31c8787689 Sync from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
30 { \
6b31c8787689 Sync from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
31 size_t filelen = strlen (File); \
6b31c8787689 Sync from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
32 static const char procfd[] = "/proc/self/fd/%d/%s"; \
6b31c8787689 Sync from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
33 /* Buffer for the file name we are going to use. It consists of \
6b31c8787689 Sync from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
34 - the string /proc/self/fd/ \
6b31c8787689 Sync from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
35 - the file descriptor number \
6b31c8787689 Sync from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
36 - the file name provided. \
6b31c8787689 Sync from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
37 The final NUL is included in the sizeof. \
6b31c8787689 Sync from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
38 Subtract 4 to account for %d and %s. */ \
6b31c8787689 Sync from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
39 size_t buflen = sizeof (procfd) - 4 + INT_STRLEN_BOUND (Fd) + filelen; \
6b31c8787689 Sync from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
40 (Proc_fd_filename) = alloca (buflen); \
6b31c8787689 Sync from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
41 snprintf ((Proc_fd_filename), buflen, procfd, (Fd), (File)); \
6b31c8787689 Sync from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
42 } \
6b31c8787689 Sync from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
43 while (0)
6b31c8787689 Sync from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
44
7151
43e3888c56c4 Update from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 6527
diff changeset
45 /* Some systems don't have ENOSYS. */
43e3888c56c4 Update from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 6527
diff changeset
46 #ifndef ENOSYS
43e3888c56c4 Update from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 6527
diff changeset
47 # ifdef ENOTSUP
43e3888c56c4 Update from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 6527
diff changeset
48 # define ENOSYS ENOTSUP
43e3888c56c4 Update from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 6527
diff changeset
49 # else
43e3888c56c4 Update from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 6527
diff changeset
50 /* Some systems don't have ENOTSUP either. */
43e3888c56c4 Update from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 6527
diff changeset
51 # define ENOSYS EINVAL
43e3888c56c4 Update from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 6527
diff changeset
52 # endif
43e3888c56c4 Update from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 6527
diff changeset
53 #endif
43e3888c56c4 Update from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 6527
diff changeset
54
6527
6b31c8787689 Sync from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
55 /* Trying to access a BUILD_PROC_NAME file will fail on systems without
6b31c8787689 Sync from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
56 /proc support, and even on systems *with* ProcFS support. Return
6b31c8787689 Sync from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
57 nonzero if the failure may be legitimate, e.g., because /proc is not
6b31c8787689 Sync from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
58 readable, or the particular .../fd/N directory is not present. */
6b31c8787689 Sync from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
59 #define EXPECTED_ERRNO(Errno) \
6b31c8787689 Sync from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
60 ((Errno) == ENOTDIR || (Errno) == ENOENT \
6b31c8787689 Sync from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
61 || (Errno) == EPERM || (Errno) == EACCES \
6b31c8787689 Sync from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
62 || (Errno) == ENOSYS /* Solaris 8 */ \
6b31c8787689 Sync from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
63 || (Errno) == EOPNOTSUPP /* FreeBSD */)