Mercurial > hg > octave-shane > gnulib-hg
annotate lib/openat.h @ 16201:8250f2777afc
maint: update all copyright year number ranges
Run "make update-copyright".
author | Jim Meyering <meyering@redhat.com> |
---|---|
date | Sun, 01 Jan 2012 10:04:58 +0100 |
parents | 1ae8bbf66d04 |
children | 66fafd5c6640 |
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 |
16201
8250f2777afc
maint: update all copyright year number ranges
Jim Meyering <meyering@redhat.com>
parents:
16030
diff
changeset
|
2 Copyright (C) 2004-2006, 2008-2012 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 <unistd.h> |
6527 | 27 #include <stdbool.h> |
6272
3baa574549ae
* modules/openat (Files): Add lib/openat-die.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5955
diff
changeset
|
28 |
11942
d1047ae4b8d5
openat: declare in POSIX headers
Eric Blake <ebb9@byu.net>
parents:
11937
diff
changeset
|
29 #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
|
30 |
6527 | 31 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
|
32 int *cwd_errno); |
7151 | 33 bool openat_needs_fchdir (void); |
6527 | 34 |
35 #else | |
36 | |
37 # define openat_permissive(Fd, File, Flags, Mode, Cwd_errno) \ | |
38 openat (Fd, File, Flags, Mode) | |
7151 | 39 # define openat_needs_fchdir() false |
6527 | 40 |
41 #endif | |
42 | |
15412
7f0f3e1ac6fd
stdnoreturn, stdnoreturn-tests: remove modules
Paul Eggert <eggert@cs.ucla.edu>
parents:
15404
diff
changeset
|
43 _Noreturn void openat_restore_fail (int); |
7f0f3e1ac6fd
stdnoreturn, stdnoreturn-tests: remove modules
Paul Eggert <eggert@cs.ucla.edu>
parents:
15404
diff
changeset
|
44 _Noreturn void openat_save_fail (int); |
7151 | 45 |
46 /* Using these function names makes application code | |
47 slightly more readable than it would be with | |
48 fchownat (..., 0) or fchownat (..., AT_SYMLINK_NOFOLLOW). */ | |
16012
fb7a82c2a615
New module 'fchownat', split off from module 'openat'.
Bruno Haible <bruno@clisp.org>
parents:
15582
diff
changeset
|
49 |
fb7a82c2a615
New module 'fchownat', split off from module 'openat'.
Bruno Haible <bruno@clisp.org>
parents:
15582
diff
changeset
|
50 #if GNULIB_FCHOWNAT |
fb7a82c2a615
New module 'fchownat', split off from module 'openat'.
Bruno Haible <bruno@clisp.org>
parents:
15582
diff
changeset
|
51 |
7151 | 52 static inline int |
53 chownat (int fd, char const *file, uid_t owner, gid_t group) | |
54 { | |
55 return fchownat (fd, file, owner, group, 0); | |
56 } | |
57 | |
58 static inline int | |
59 lchownat (int fd, char const *file, uid_t owner, gid_t group) | |
60 { | |
61 return fchownat (fd, file, owner, group, AT_SYMLINK_NOFOLLOW); | |
62 } | |
63 | |
16012
fb7a82c2a615
New module 'fchownat', split off from module 'openat'.
Bruno Haible <bruno@clisp.org>
parents:
15582
diff
changeset
|
64 #endif |
fb7a82c2a615
New module 'fchownat', split off from module 'openat'.
Bruno Haible <bruno@clisp.org>
parents:
15582
diff
changeset
|
65 |
16021
ab92e00caa02
New module 'fchmodat', split off from module 'openat'.
Bruno Haible <bruno@clisp.org>
parents:
16012
diff
changeset
|
66 #if GNULIB_FCHMODAT |
ab92e00caa02
New module 'fchmodat', split off from module 'openat'.
Bruno Haible <bruno@clisp.org>
parents:
16012
diff
changeset
|
67 |
7151 | 68 static inline int |
69 chmodat (int fd, char const *file, mode_t mode) | |
70 { | |
71 return fchmodat (fd, file, mode, 0); | |
72 } | |
73 | |
74 static inline int | |
75 lchmodat (int fd, char const *file, mode_t mode) | |
76 { | |
77 return fchmodat (fd, file, mode, AT_SYMLINK_NOFOLLOW); | |
78 } | |
11937 | 79 |
16021
ab92e00caa02
New module 'fchmodat', split off from module 'openat'.
Bruno Haible <bruno@clisp.org>
parents:
16012
diff
changeset
|
80 #endif |
ab92e00caa02
New module 'fchmodat', split off from module 'openat'.
Bruno Haible <bruno@clisp.org>
parents:
16012
diff
changeset
|
81 |
16023
dc33aa820898
New module 'fstatat', split off from module 'openat'.
Bruno Haible <bruno@clisp.org>
parents:
16021
diff
changeset
|
82 #if GNULIB_FSTATAT |
dc33aa820898
New module 'fstatat', split off from module 'openat'.
Bruno Haible <bruno@clisp.org>
parents:
16021
diff
changeset
|
83 |
11969
25d12bf7e5bf
openat: provide more convenience names
Eric Blake <ebb9@byu.net>
parents:
11942
diff
changeset
|
84 static inline int |
25d12bf7e5bf
openat: provide more convenience names
Eric Blake <ebb9@byu.net>
parents:
11942
diff
changeset
|
85 statat (int fd, char const *name, struct stat *st) |
25d12bf7e5bf
openat: provide more convenience names
Eric Blake <ebb9@byu.net>
parents:
11942
diff
changeset
|
86 { |
25d12bf7e5bf
openat: provide more convenience names
Eric Blake <ebb9@byu.net>
parents:
11942
diff
changeset
|
87 return fstatat (fd, name, st, 0); |
25d12bf7e5bf
openat: provide more convenience names
Eric Blake <ebb9@byu.net>
parents:
11942
diff
changeset
|
88 } |
25d12bf7e5bf
openat: provide more convenience names
Eric Blake <ebb9@byu.net>
parents:
11942
diff
changeset
|
89 |
25d12bf7e5bf
openat: provide more convenience names
Eric Blake <ebb9@byu.net>
parents:
11942
diff
changeset
|
90 static inline int |
25d12bf7e5bf
openat: provide more convenience names
Eric Blake <ebb9@byu.net>
parents:
11942
diff
changeset
|
91 lstatat (int fd, char const *name, struct stat *st) |
25d12bf7e5bf
openat: provide more convenience names
Eric Blake <ebb9@byu.net>
parents:
11942
diff
changeset
|
92 { |
25d12bf7e5bf
openat: provide more convenience names
Eric Blake <ebb9@byu.net>
parents:
11942
diff
changeset
|
93 return fstatat (fd, name, st, AT_SYMLINK_NOFOLLOW); |
25d12bf7e5bf
openat: provide more convenience names
Eric Blake <ebb9@byu.net>
parents:
11942
diff
changeset
|
94 } |
25d12bf7e5bf
openat: provide more convenience names
Eric Blake <ebb9@byu.net>
parents:
11942
diff
changeset
|
95 |
16023
dc33aa820898
New module 'fstatat', split off from module 'openat'.
Bruno Haible <bruno@clisp.org>
parents:
16021
diff
changeset
|
96 #endif |
dc33aa820898
New module 'fstatat', split off from module 'openat'.
Bruno Haible <bruno@clisp.org>
parents:
16021
diff
changeset
|
97 |
11969
25d12bf7e5bf
openat: provide more convenience names
Eric Blake <ebb9@byu.net>
parents:
11942
diff
changeset
|
98 /* 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
|
99 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
|
100 since access rights on symlinks are of limited utility. Likewise, |
9ef7abcf9136
faccessat: remove unused wrappers
Eric Blake <eblake@redhat.com>
parents:
12559
diff
changeset
|
101 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
|
102 avoid dragging in -lgen on some platforms. */ |
11969
25d12bf7e5bf
openat: provide more convenience names
Eric Blake <ebb9@byu.net>
parents:
11942
diff
changeset
|
103 |
11937 | 104 #endif /* _GL_HEADER_OPENAT */ |