Import upstream version 1.28
[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-2014 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 <unistd.h>
29 #include <stdbool.h>
30
31 #ifndef _GL_INLINE_HEADER_BEGIN
32  #error "Please include config.h first."
33 #endif
34 _GL_INLINE_HEADER_BEGIN
35
36 #if !HAVE_OPENAT
37
38 int openat_permissive (int fd, char const *file, int flags, mode_t mode,
39                        int *cwd_errno);
40 bool openat_needs_fchdir (void);
41
42 #else
43
44 # define openat_permissive(Fd, File, Flags, Mode, Cwd_errno) \
45     openat (Fd, File, Flags, Mode)
46 # define openat_needs_fchdir() false
47
48 #endif
49
50 _Noreturn void openat_restore_fail (int);
51 _Noreturn void openat_save_fail (int);
52
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).  */
56
57 #if GNULIB_FCHOWNAT
58
59 # ifndef FCHOWNAT_INLINE
60 #  define FCHOWNAT_INLINE _GL_INLINE
61 # endif
62
63 FCHOWNAT_INLINE int
64 chownat (int fd, char const *file, uid_t owner, gid_t group)
65 {
66   return fchownat (fd, file, owner, group, 0);
67 }
68
69 FCHOWNAT_INLINE int
70 lchownat (int fd, char const *file, uid_t owner, gid_t group)
71 {
72   return fchownat (fd, file, owner, group, AT_SYMLINK_NOFOLLOW);
73 }
74
75 #endif
76
77 #if GNULIB_FCHMODAT
78
79 # ifndef FCHMODAT_INLINE
80 #  define FCHMODAT_INLINE _GL_INLINE
81 # endif
82
83 FCHMODAT_INLINE int
84 chmodat (int fd, char const *file, mode_t mode)
85 {
86   return fchmodat (fd, file, mode, 0);
87 }
88
89 FCHMODAT_INLINE int
90 lchmodat (int fd, char const *file, mode_t mode)
91 {
92   return fchmodat (fd, file, mode, AT_SYMLINK_NOFOLLOW);
93 }
94
95 #endif
96
97 #if GNULIB_STATAT
98
99 # ifndef STATAT_INLINE
100 #  define STATAT_INLINE _GL_INLINE
101 # endif
102
103 STATAT_INLINE int
104 statat (int fd, char const *name, struct stat *st)
105 {
106   return fstatat (fd, name, st, 0);
107 }
108
109 STATAT_INLINE int
110 lstatat (int fd, char const *name, struct stat *st)
111 {
112   return fstatat (fd, name, st, AT_SYMLINK_NOFOLLOW);
113 }
114
115 #endif
116
117 /* For now, there are no wrappers named laccessat or leuidaccessat,
118    since gnulib doesn't support faccessat(,AT_SYMLINK_NOFOLLOW) and
119    since access rights on symlinks are of limited utility.  Likewise,
120    wrappers are not provided for accessat or euidaccessat, so as to
121    avoid dragging in -lgen on some platforms.  */
122
123 _GL_INLINE_HEADER_END
124
125 #endif /* _GL_HEADER_OPENAT */