annotate lib/openat-priv.h @ 17363:5a51fb7777a9

sys_select, sys_time: port 2013-01-30 Solaris 2.6 fix to Cygwin Problem reported by Marco Atzeri in <http://lists.gnu.org/archive/html/bug-gnulib/2013-03/msg00000.html>. * lib/sys_select.in.h [HAVE_SYS_SELECT_H && _CYGWIN_SYS_TIME_H]: Simply delegate to the system <sys/select.h> in this case too. Also, pay attention to _GL_SYS_SELECT_H_REDIRECT_FROM_SYS_TIME_H only if OSF/1, since otherwise Cygwin breaks, and it doesn't seem to be needed on Solaris either. * lib/sys_time.in.h [_CYGWIN_SYS_TIME_H]: Simply delgate to the system <sys/time.h> in this case.
author Paul Eggert <eggert@cs.ucla.edu>
date Tue, 19 Mar 2013 09:08:47 -0700
parents e542fd46ad6f
children 344018b6e5d7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7389
0f8d70c02f29 [lib/ChangeLog]
Paul Eggert <eggert@cs.ucla.edu>
parents: 7151
diff changeset
1 /* Internals for openat-like functions.
0f8d70c02f29 [lib/ChangeLog]
Paul Eggert <eggert@cs.ucla.edu>
parents: 7151
diff changeset
2
17249
e542fd46ad6f maint: update all copyright year number ranges
Eric Blake <eblake@redhat.com>
parents: 16201
diff changeset
3 Copyright (C) 2005-2006, 2009-2013 Free Software Foundation, Inc.
6527
6b31c8787689 Sync from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
4
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 7537
diff changeset
5 This program is free software: you can redistribute it and/or modify
6527
6b31c8787689 Sync from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
6 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: 7537
diff changeset
7 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: 7537
diff changeset
8 (at your option) any later version.
6527
6b31c8787689 Sync from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
9
6b31c8787689 Sync from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
10 This program is distributed in the hope that it will be useful,
6b31c8787689 Sync from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
6b31c8787689 Sync from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6b31c8787689 Sync from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
13 GNU General Public License for more details.
6b31c8787689 Sync from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
14
6b31c8787689 Sync from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
15 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: 7537
diff changeset
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
6527
6b31c8787689 Sync from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
17
6b31c8787689 Sync from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
18 /* written by Jim Meyering */
6b31c8787689 Sync from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
19
12028
a65ac3b41872 openat: simplify use of at-func.c
Eric Blake <ebb9@byu.net>
parents: 11941
diff changeset
20 #ifndef _GL_HEADER_OPENAT_PRIV
a65ac3b41872 openat: simplify use of at-func.c
Eric Blake <ebb9@byu.net>
parents: 11941
diff changeset
21 #define _GL_HEADER_OPENAT_PRIV
a65ac3b41872 openat: simplify use of at-func.c
Eric Blake <ebb9@byu.net>
parents: 11941
diff changeset
22
7151
43e3888c56c4 Update from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 6527
diff changeset
23 #include <errno.h>
14166
f81d85f6a1c3 openat: Increase OPENAT_BUFFER_SIZE from 512 to at least 1024
Paul Eggert <eggert@cs.ucla.edu>
parents: 14079
diff changeset
24 #include <limits.h>
7389
0f8d70c02f29 [lib/ChangeLog]
Paul Eggert <eggert@cs.ucla.edu>
parents: 7151
diff changeset
25 #include <stdlib.h>
6527
6b31c8787689 Sync from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
26
14166
f81d85f6a1c3 openat: Increase OPENAT_BUFFER_SIZE from 512 to at least 1024
Paul Eggert <eggert@cs.ucla.edu>
parents: 14079
diff changeset
27 /* Maximum number of bytes that it is safe to allocate as a single
f81d85f6a1c3 openat: Increase OPENAT_BUFFER_SIZE from 512 to at least 1024
Paul Eggert <eggert@cs.ucla.edu>
parents: 14079
diff changeset
28 array on the stack, and that is known as a compile-time constant.
f81d85f6a1c3 openat: Increase OPENAT_BUFFER_SIZE from 512 to at least 1024
Paul Eggert <eggert@cs.ucla.edu>
parents: 14079
diff changeset
29 The assumption is that we'll touch the array very quickly, or a
f81d85f6a1c3 openat: Increase OPENAT_BUFFER_SIZE from 512 to at least 1024
Paul Eggert <eggert@cs.ucla.edu>
parents: 14079
diff changeset
30 temporary very near the array, provoking an out-of-memory trap. On
f81d85f6a1c3 openat: Increase OPENAT_BUFFER_SIZE from 512 to at least 1024
Paul Eggert <eggert@cs.ucla.edu>
parents: 14079
diff changeset
31 some operating systems, there is only one guard page for the stack,
f81d85f6a1c3 openat: Increase OPENAT_BUFFER_SIZE from 512 to at least 1024
Paul Eggert <eggert@cs.ucla.edu>
parents: 14079
diff changeset
32 and a page size can be as small as 4096 bytes. Subtract 64 in the
f81d85f6a1c3 openat: Increase OPENAT_BUFFER_SIZE from 512 to at least 1024
Paul Eggert <eggert@cs.ucla.edu>
parents: 14079
diff changeset
33 hope that this will let the compiler touch a nearby temporary and
f81d85f6a1c3 openat: Increase OPENAT_BUFFER_SIZE from 512 to at least 1024
Paul Eggert <eggert@cs.ucla.edu>
parents: 14079
diff changeset
34 provoke a trap. */
f81d85f6a1c3 openat: Increase OPENAT_BUFFER_SIZE from 512 to at least 1024
Paul Eggert <eggert@cs.ucla.edu>
parents: 14079
diff changeset
35 #define SAFER_ALLOCA_MAX (4096 - 64)
f81d85f6a1c3 openat: Increase OPENAT_BUFFER_SIZE from 512 to at least 1024
Paul Eggert <eggert@cs.ucla.edu>
parents: 14079
diff changeset
36
f81d85f6a1c3 openat: Increase OPENAT_BUFFER_SIZE from 512 to at least 1024
Paul Eggert <eggert@cs.ucla.edu>
parents: 14079
diff changeset
37 #define SAFER_ALLOCA(m) ((m) < SAFER_ALLOCA_MAX ? (m) : SAFER_ALLOCA_MAX)
f81d85f6a1c3 openat: Increase OPENAT_BUFFER_SIZE from 512 to at least 1024
Paul Eggert <eggert@cs.ucla.edu>
parents: 14079
diff changeset
38
f81d85f6a1c3 openat: Increase OPENAT_BUFFER_SIZE from 512 to at least 1024
Paul Eggert <eggert@cs.ucla.edu>
parents: 14079
diff changeset
39 #if defined PATH_MAX
f81d85f6a1c3 openat: Increase OPENAT_BUFFER_SIZE from 512 to at least 1024
Paul Eggert <eggert@cs.ucla.edu>
parents: 14079
diff changeset
40 # define OPENAT_BUFFER_SIZE SAFER_ALLOCA (PATH_MAX)
f81d85f6a1c3 openat: Increase OPENAT_BUFFER_SIZE from 512 to at least 1024
Paul Eggert <eggert@cs.ucla.edu>
parents: 14079
diff changeset
41 #elif defined _XOPEN_PATH_MAX
f81d85f6a1c3 openat: Increase OPENAT_BUFFER_SIZE from 512 to at least 1024
Paul Eggert <eggert@cs.ucla.edu>
parents: 14079
diff changeset
42 # define OPENAT_BUFFER_SIZE SAFER_ALLOCA (_XOPEN_PATH_MAX)
f81d85f6a1c3 openat: Increase OPENAT_BUFFER_SIZE from 512 to at least 1024
Paul Eggert <eggert@cs.ucla.edu>
parents: 14079
diff changeset
43 #else
f81d85f6a1c3 openat: Increase OPENAT_BUFFER_SIZE from 512 to at least 1024
Paul Eggert <eggert@cs.ucla.edu>
parents: 14079
diff changeset
44 # define OPENAT_BUFFER_SIZE SAFER_ALLOCA (1024)
f81d85f6a1c3 openat: Increase OPENAT_BUFFER_SIZE from 512 to at least 1024
Paul Eggert <eggert@cs.ucla.edu>
parents: 14079
diff changeset
45 #endif
f81d85f6a1c3 openat: Increase OPENAT_BUFFER_SIZE from 512 to at least 1024
Paul Eggert <eggert@cs.ucla.edu>
parents: 14079
diff changeset
46
7389
0f8d70c02f29 [lib/ChangeLog]
Paul Eggert <eggert@cs.ucla.edu>
parents: 7151
diff changeset
47 char *openat_proc_name (char buf[OPENAT_BUFFER_SIZE], int fd, char const *file);
6527
6b31c8787689 Sync from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
48
6b31c8787689 Sync from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
49 /* Trying to access a BUILD_PROC_NAME file will fail on systems without
6b31c8787689 Sync from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
50 /proc support, and even on systems *with* ProcFS support. Return
6b31c8787689 Sync from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
51 nonzero if the failure may be legitimate, e.g., because /proc is not
6b31c8787689 Sync from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
52 readable, or the particular .../fd/N directory is not present. */
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12068
diff changeset
53 #define EXPECTED_ERRNO(Errno) \
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12068
diff changeset
54 ((Errno) == ENOTDIR || (Errno) == ENOENT \
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12068
diff changeset
55 || (Errno) == EPERM || (Errno) == EACCES \
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12068
diff changeset
56 || (Errno) == ENOSYS /* Solaris 8 */ \
6527
6b31c8787689 Sync from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
57 || (Errno) == EOPNOTSUPP /* FreeBSD */)
12028
a65ac3b41872 openat: simplify use of at-func.c
Eric Blake <ebb9@byu.net>
parents: 11941
diff changeset
58
12068
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents: 12028
diff changeset
59 /* Wrapper function shared among linkat and renameat. */
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents: 12028
diff changeset
60 int at_func2 (int fd1, char const *file1,
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12068
diff changeset
61 int fd2, char const *file2,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12068
diff changeset
62 int (*func) (char const *file1, char const *file2));
12068
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents: 12028
diff changeset
63
12028
a65ac3b41872 openat: simplify use of at-func.c
Eric Blake <ebb9@byu.net>
parents: 11941
diff changeset
64 #endif /* _GL_HEADER_OPENAT_PRIV */