Mercurial > hg > octave-shane > gnulib-hg
annotate lib/openat.h @ 15582:c5fde8111cd7
Revert last commit.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Wed, 07 Sep 2011 23:52:31 +0200 |
parents | 95adf5bf155d |
children | fb7a82c2a615 |
rev | line source |
---|---|
5588
14b330875e48
* modules/chdir-long, modules/openat: New files.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff
changeset
|
1 /* provide a replacement openat function |
14079
97fc9a21a8fb
maint: update almost all copyright ranges to include 2011
Jim Meyering <meyering@redhat.com>
parents:
13765
diff
changeset
|
2 Copyright (C) 2004-2006, 2008-2011 Free Software Foundation, Inc. |
5588
14b330875e48
* modules/chdir-long, modules/openat: New files.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff
changeset
|
3 |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
7677
diff
changeset
|
4 This program is free software: you can redistribute it and/or modify |
5588
14b330875e48
* modules/chdir-long, modules/openat: New files.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff
changeset
|
5 it under the terms of the GNU General Public License as published by |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
7677
diff
changeset
|
6 the Free Software Foundation; either version 3 of the License, or |
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
7677
diff
changeset
|
7 (at your option) any later version. |
5588
14b330875e48
* modules/chdir-long, modules/openat: New files.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff
changeset
|
8 |
14b330875e48
* modules/chdir-long, modules/openat: New files.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff
changeset
|
9 This program is distributed in the hope that it will be useful, |
14b330875e48
* modules/chdir-long, modules/openat: New files.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff
changeset
|
10 but WITHOUT ANY WARRANTY; without even the implied warranty of |
14b330875e48
* modules/chdir-long, modules/openat: New files.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff
changeset
|
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14b330875e48
* modules/chdir-long, modules/openat: New files.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff
changeset
|
12 GNU General Public License for more details. |
14b330875e48
* modules/chdir-long, modules/openat: New files.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff
changeset
|
13 |
14b330875e48
* modules/chdir-long, modules/openat: New files.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff
changeset
|
14 You should have received a copy of the GNU General Public License |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
7677
diff
changeset
|
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
5588
14b330875e48
* modules/chdir-long, modules/openat: New files.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff
changeset
|
16 |
14b330875e48
* modules/chdir-long, modules/openat: New files.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff
changeset
|
17 /* written by Jim Meyering */ |
14b330875e48
* modules/chdir-long, modules/openat: New files.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff
changeset
|
18 |
11937 | 19 #ifndef _GL_HEADER_OPENAT |
20 #define _GL_HEADER_OPENAT | |
21 | |
15582 | 22 #include <fcntl.h> |
5588
14b330875e48
* modules/chdir-long, modules/openat: New files.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff
changeset
|
23 |
5609
84f75cbb306a
* modules/chdir-long (Depends-on): Remove mempcpy.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5588
diff
changeset
|
24 #include <sys/types.h> |
84f75cbb306a
* modules/chdir-long (Depends-on): Remove mempcpy.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5588
diff
changeset
|
25 #include <sys/stat.h> |
84f75cbb306a
* modules/chdir-long (Depends-on): Remove mempcpy.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5588
diff
changeset
|
26 #include <dirent.h> |
84f75cbb306a
* modules/chdir-long (Depends-on): Remove mempcpy.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5588
diff
changeset
|
27 #include <unistd.h> |
6527 | 28 #include <stdbool.h> |
6272
3baa574549ae
* modules/openat (Files): Add lib/openat-die.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5955
diff
changeset
|
29 |
11942
d1047ae4b8d5
openat: declare in POSIX headers
Eric Blake <ebb9@byu.net>
parents:
11937
diff
changeset
|
30 #if !HAVE_OPENAT |
6647
ca74ccfe8d1b
* getcwd.c (AT_FDCWD): Work around a bug in Solaris 9 and 10, where
Paul Eggert <eggert@cs.ucla.edu>
parents:
6527
diff
changeset
|
31 |
6527 | 32 int openat_permissive (int fd, char const *file, int flags, mode_t mode, |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11969
diff
changeset
|
33 int *cwd_errno); |
7151 | 34 bool openat_needs_fchdir (void); |
6527 | 35 |
36 #else | |
37 | |
38 # define openat_permissive(Fd, File, Flags, Mode, Cwd_errno) \ | |
39 openat (Fd, File, Flags, Mode) | |
7151 | 40 # define openat_needs_fchdir() false |
6527 | 41 |
42 #endif | |
43 | |
15412
7f0f3e1ac6fd
stdnoreturn, stdnoreturn-tests: remove modules
Paul Eggert <eggert@cs.ucla.edu>
parents:
15404
diff
changeset
|
44 _Noreturn void openat_restore_fail (int); |
7f0f3e1ac6fd
stdnoreturn, stdnoreturn-tests: remove modules
Paul Eggert <eggert@cs.ucla.edu>
parents:
15404
diff
changeset
|
45 _Noreturn void openat_save_fail (int); |
7151 | 46 |
47 /* Using these function names makes application code | |
48 slightly more readable than it would be with | |
49 fchownat (..., 0) or fchownat (..., AT_SYMLINK_NOFOLLOW). */ | |
50 static inline int | |
51 chownat (int fd, char const *file, uid_t owner, gid_t group) | |
52 { | |
53 return fchownat (fd, file, owner, group, 0); | |
54 } | |
55 | |
56 static inline int | |
57 lchownat (int fd, char const *file, uid_t owner, gid_t group) | |
58 { | |
59 return fchownat (fd, file, owner, group, AT_SYMLINK_NOFOLLOW); | |
60 } | |
61 | |
62 static inline int | |
63 chmodat (int fd, char const *file, mode_t mode) | |
64 { | |
65 return fchmodat (fd, file, mode, 0); | |
66 } | |
67 | |
68 static inline int | |
69 lchmodat (int fd, char const *file, mode_t mode) | |
70 { | |
71 return fchmodat (fd, file, mode, AT_SYMLINK_NOFOLLOW); | |
72 } | |
11937 | 73 |
11969
25d12bf7e5bf
openat: provide more convenience names
Eric Blake <ebb9@byu.net>
parents:
11942
diff
changeset
|
74 static inline int |
25d12bf7e5bf
openat: provide more convenience names
Eric Blake <ebb9@byu.net>
parents:
11942
diff
changeset
|
75 statat (int fd, char const *name, struct stat *st) |
25d12bf7e5bf
openat: provide more convenience names
Eric Blake <ebb9@byu.net>
parents:
11942
diff
changeset
|
76 { |
25d12bf7e5bf
openat: provide more convenience names
Eric Blake <ebb9@byu.net>
parents:
11942
diff
changeset
|
77 return fstatat (fd, name, st, 0); |
25d12bf7e5bf
openat: provide more convenience names
Eric Blake <ebb9@byu.net>
parents:
11942
diff
changeset
|
78 } |
25d12bf7e5bf
openat: provide more convenience names
Eric Blake <ebb9@byu.net>
parents:
11942
diff
changeset
|
79 |
25d12bf7e5bf
openat: provide more convenience names
Eric Blake <ebb9@byu.net>
parents:
11942
diff
changeset
|
80 static inline int |
25d12bf7e5bf
openat: provide more convenience names
Eric Blake <ebb9@byu.net>
parents:
11942
diff
changeset
|
81 lstatat (int fd, char const *name, struct stat *st) |
25d12bf7e5bf
openat: provide more convenience names
Eric Blake <ebb9@byu.net>
parents:
11942
diff
changeset
|
82 { |
25d12bf7e5bf
openat: provide more convenience names
Eric Blake <ebb9@byu.net>
parents:
11942
diff
changeset
|
83 return fstatat (fd, name, st, AT_SYMLINK_NOFOLLOW); |
25d12bf7e5bf
openat: provide more convenience names
Eric Blake <ebb9@byu.net>
parents:
11942
diff
changeset
|
84 } |
25d12bf7e5bf
openat: provide more convenience names
Eric Blake <ebb9@byu.net>
parents:
11942
diff
changeset
|
85 |
25d12bf7e5bf
openat: provide more convenience names
Eric Blake <ebb9@byu.net>
parents:
11942
diff
changeset
|
86 /* For now, there are no wrappers named laccessat or leuidaccessat, |
25d12bf7e5bf
openat: provide more convenience names
Eric Blake <ebb9@byu.net>
parents:
11942
diff
changeset
|
87 since gnulib doesn't support faccessat(,AT_SYMLINK_NOFOLLOW) and |
13765
9ef7abcf9136
faccessat: remove unused wrappers
Eric Blake <eblake@redhat.com>
parents:
12559
diff
changeset
|
88 since access rights on symlinks are of limited utility. Likewise, |
9ef7abcf9136
faccessat: remove unused wrappers
Eric Blake <eblake@redhat.com>
parents:
12559
diff
changeset
|
89 wrappers are not provided for accessat or euidaccessat, so as to |
9ef7abcf9136
faccessat: remove unused wrappers
Eric Blake <eblake@redhat.com>
parents:
12559
diff
changeset
|
90 avoid dragging in -lgen on some platforms. */ |
11969
25d12bf7e5bf
openat: provide more convenience names
Eric Blake <ebb9@byu.net>
parents:
11942
diff
changeset
|
91 |
11937 | 92 #endif /* _GL_HEADER_OPENAT */ |