Import upstream version 1.26
[debian/tar] / gnu / openat.h
1 /* -*- buffer-read-only: t -*- vi: set ro: */
2 /* DO NOT EDIT! GENERATED AUTOMATICALLY! */
3 /* provide a replacement openat function
4    Copyright (C) 2004-2006, 2008-2011 Free Software Foundation, Inc.
5
6    This program is free software: you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 3 of the License, or
9    (at your option) any later version.
10
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
18
19 /* written by Jim Meyering */
20
21 #ifndef _GL_HEADER_OPENAT
22 #define _GL_HEADER_OPENAT
23
24 #include <fcntl.h>
25
26 #include <sys/types.h>
27 #include <sys/stat.h>
28 #include <dirent.h>
29 #include <unistd.h>
30 #include <stdbool.h>
31
32 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8)
33 # define _GL_ATTRIBUTE_NORETURN __attribute__ ((__noreturn__))
34 #else
35 # define _GL_ATTRIBUTE_NORETURN /* empty */
36 #endif
37
38 #if !HAVE_OPENAT
39
40 int openat_permissive (int fd, char const *file, int flags, mode_t mode,
41                        int *cwd_errno);
42 bool openat_needs_fchdir (void);
43
44 #else
45
46 # define openat_permissive(Fd, File, Flags, Mode, Cwd_errno) \
47     openat (Fd, File, Flags, Mode)
48 # define openat_needs_fchdir() false
49
50 #endif
51
52 void openat_restore_fail (int) _GL_ATTRIBUTE_NORETURN;
53 void openat_save_fail (int) _GL_ATTRIBUTE_NORETURN;
54
55 /* Using these function names makes application code
56    slightly more readable than it would be with
57    fchownat (..., 0) or fchownat (..., AT_SYMLINK_NOFOLLOW).  */
58 static inline int
59 chownat (int fd, char const *file, uid_t owner, gid_t group)
60 {
61   return fchownat (fd, file, owner, group, 0);
62 }
63
64 static inline int
65 lchownat (int fd, char const *file, uid_t owner, gid_t group)
66 {
67   return fchownat (fd, file, owner, group, AT_SYMLINK_NOFOLLOW);
68 }
69
70 static inline int
71 chmodat (int fd, char const *file, mode_t mode)
72 {
73   return fchmodat (fd, file, mode, 0);
74 }
75
76 static inline int
77 lchmodat (int fd, char const *file, mode_t mode)
78 {
79   return fchmodat (fd, file, mode, AT_SYMLINK_NOFOLLOW);
80 }
81
82 static inline int
83 statat (int fd, char const *name, struct stat *st)
84 {
85   return fstatat (fd, name, st, 0);
86 }
87
88 static inline int
89 lstatat (int fd, char const *name, struct stat *st)
90 {
91   return fstatat (fd, name, st, AT_SYMLINK_NOFOLLOW);
92 }
93
94 /* For now, there are no wrappers named laccessat or leuidaccessat,
95    since gnulib doesn't support faccessat(,AT_SYMLINK_NOFOLLOW) and
96    since access rights on symlinks are of limited utility.  Likewise,
97    wrappers are not provided for accessat or euidaccessat, so as to
98    avoid dragging in -lgen on some platforms.  */
99
100 #endif /* _GL_HEADER_OPENAT */