1 /* provide a replacement openat function
2 Copyright (C) 2004-2006, 2008-2010 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17 /* written by Jim Meyering */
19 #ifndef _GL_HEADER_OPENAT
20 #define _GL_HEADER_OPENAT
24 #include <sys/types.h>
31 # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 8)
32 # define __attribute__(x) /* empty */
36 #ifndef ATTRIBUTE_NORETURN
37 # define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__))
42 int openat_permissive (int fd, char const *file, int flags, mode_t mode,
44 bool openat_needs_fchdir (void);
48 # define openat_permissive(Fd, File, Flags, Mode, Cwd_errno) \
49 openat (Fd, File, Flags, Mode)
50 # define openat_needs_fchdir() false
54 void openat_restore_fail (int) ATTRIBUTE_NORETURN;
55 void openat_save_fail (int) ATTRIBUTE_NORETURN;
57 /* Using these function names makes application code
58 slightly more readable than it would be with
59 fchownat (..., 0) or fchownat (..., AT_SYMLINK_NOFOLLOW). */
61 chownat (int fd, char const *file, uid_t owner, gid_t group)
63 return fchownat (fd, file, owner, group, 0);
67 lchownat (int fd, char const *file, uid_t owner, gid_t group)
69 return fchownat (fd, file, owner, group, AT_SYMLINK_NOFOLLOW);
73 chmodat (int fd, char const *file, mode_t mode)
75 return fchmodat (fd, file, mode, 0);
79 lchmodat (int fd, char const *file, mode_t mode)
81 return fchmodat (fd, file, mode, AT_SYMLINK_NOFOLLOW);
85 statat (int fd, char const *name, struct stat *st)
87 return fstatat (fd, name, st, 0);
91 lstatat (int fd, char const *name, struct stat *st)
93 return fstatat (fd, name, st, AT_SYMLINK_NOFOLLOW);
96 /* For now, there are no wrappers named laccessat or leuidaccessat,
97 since gnulib doesn't support faccessat(,AT_SYMLINK_NOFOLLOW) and
98 since access rights on symlinks are of limited utility. Likewise,
99 wrappers are not provided for accessat or euidaccessat, so as to
100 avoid dragging in -lgen on some platforms. */
102 #endif /* _GL_HEADER_OPENAT */