1 /* provide a replacement openat function
2 Copyright (C) 2004-2006, 2008-2011 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>
30 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8)
31 # define _GL_ATTRIBUTE_NORETURN __attribute__ ((__noreturn__))
33 # define _GL_ATTRIBUTE_NORETURN /* empty */
38 int openat_permissive (int fd, char const *file, int flags, mode_t mode,
40 bool openat_needs_fchdir (void);
44 # define openat_permissive(Fd, File, Flags, Mode, Cwd_errno) \
45 openat (Fd, File, Flags, Mode)
46 # define openat_needs_fchdir() false
50 void openat_restore_fail (int) _GL_ATTRIBUTE_NORETURN;
51 void openat_save_fail (int) _GL_ATTRIBUTE_NORETURN;
53 /* Using these function names makes application code
54 slightly more readable than it would be with
55 fchownat (..., 0) or fchownat (..., AT_SYMLINK_NOFOLLOW). */
57 chownat (int fd, char const *file, uid_t owner, gid_t group)
59 return fchownat (fd, file, owner, group, 0);
63 lchownat (int fd, char const *file, uid_t owner, gid_t group)
65 return fchownat (fd, file, owner, group, AT_SYMLINK_NOFOLLOW);
69 chmodat (int fd, char const *file, mode_t mode)
71 return fchmodat (fd, file, mode, 0);
75 lchmodat (int fd, char const *file, mode_t mode)
77 return fchmodat (fd, file, mode, AT_SYMLINK_NOFOLLOW);
81 statat (int fd, char const *name, struct stat *st)
83 return fstatat (fd, name, st, 0);
87 lstatat (int fd, char const *name, struct stat *st)
89 return fstatat (fd, name, st, AT_SYMLINK_NOFOLLOW);
92 /* For now, there are no wrappers named laccessat or leuidaccessat,
93 since gnulib doesn't support faccessat(,AT_SYMLINK_NOFOLLOW) and
94 since access rights on symlinks are of limited utility. Likewise,
95 wrappers are not provided for accessat or euidaccessat, so as to
96 avoid dragging in -lgen on some platforms. */
98 #endif /* _GL_HEADER_OPENAT */