Update Gnulib to the latest git version
[deliverable/binutils-gdb.git] / gnulib / import / openat.h
CommitLineData
6ec2e0f5 1/* provide a replacement openat function
c0c3707f 2 Copyright (C) 2004-2006, 2008-2019 Free Software Foundation, Inc.
6ec2e0f5
SDJ
3
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.
8
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.
13
14 You should have received a copy of the GNU General Public License
c0c3707f 15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
6ec2e0f5
SDJ
16
17/* written by Jim Meyering */
18
19#ifndef _GL_HEADER_OPENAT
20#define _GL_HEADER_OPENAT
21
22#include <fcntl.h>
23
24#include <sys/types.h>
25#include <sys/stat.h>
26#include <unistd.h>
27#include <stdbool.h>
28
29#ifndef _GL_INLINE_HEADER_BEGIN
30 #error "Please include config.h first."
31#endif
32_GL_INLINE_HEADER_BEGIN
33
34#if !HAVE_OPENAT
35
36int openat_permissive (int fd, char const *file, int flags, mode_t mode,
37 int *cwd_errno);
38bool openat_needs_fchdir (void);
39
40#else
41
42# define openat_permissive(Fd, File, Flags, Mode, Cwd_errno) \
43 openat (Fd, File, Flags, Mode)
44# define openat_needs_fchdir() false
45
46#endif
47
48_Noreturn void openat_restore_fail (int);
49_Noreturn void openat_save_fail (int);
50
51/* Using these function names makes application code
52 slightly more readable than it would be with
53 fchownat (..., 0) or fchownat (..., AT_SYMLINK_NOFOLLOW). */
54
55#if GNULIB_FCHOWNAT
56
57# ifndef FCHOWNAT_INLINE
58# define FCHOWNAT_INLINE _GL_INLINE
59# endif
60
61FCHOWNAT_INLINE int
62chownat (int fd, char const *file, uid_t owner, gid_t group)
63{
64 return fchownat (fd, file, owner, group, 0);
65}
66
67FCHOWNAT_INLINE int
68lchownat (int fd, char const *file, uid_t owner, gid_t group)
69{
70 return fchownat (fd, file, owner, group, AT_SYMLINK_NOFOLLOW);
71}
72
73#endif
74
75#if GNULIB_FCHMODAT
76
77# ifndef FCHMODAT_INLINE
78# define FCHMODAT_INLINE _GL_INLINE
79# endif
80
81FCHMODAT_INLINE int
82chmodat (int fd, char const *file, mode_t mode)
83{
84 return fchmodat (fd, file, mode, 0);
85}
86
87FCHMODAT_INLINE int
88lchmodat (int fd, char const *file, mode_t mode)
89{
90 return fchmodat (fd, file, mode, AT_SYMLINK_NOFOLLOW);
91}
92
93#endif
94
95#if GNULIB_STATAT
96
97# ifndef STATAT_INLINE
98# define STATAT_INLINE _GL_INLINE
99# endif
100
101STATAT_INLINE int
102statat (int fd, char const *name, struct stat *st)
103{
104 return fstatat (fd, name, st, 0);
105}
106
107STATAT_INLINE int
108lstatat (int fd, char const *name, struct stat *st)
109{
110 return fstatat (fd, name, st, AT_SYMLINK_NOFOLLOW);
111}
112
113#endif
114
115/* For now, there are no wrappers named laccessat or leuidaccessat,
116 since gnulib doesn't support faccessat(,AT_SYMLINK_NOFOLLOW) and
117 since access rights on symlinks are of limited utility. Likewise,
118 wrappers are not provided for accessat or euidaccessat, so as to
119 avoid dragging in -lgen on some platforms. */
120
121_GL_INLINE_HEADER_END
122
123#endif /* _GL_HEADER_OPENAT */
This page took 0.203117 seconds and 4 git commands to generate.