Fix last ChangeLog entry.
[gnulib.git] / lib / openat-priv.h
bloba8513994ea53b7a9ca7b60e0a08d452815c6eb6b
1 /* Internals for openat-like functions.
3 Copyright (C) 2005-2006, 2009-2025 Free Software Foundation, Inc.
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
18 /* written by Jim Meyering */
20 #ifndef _GL_HEADER_OPENAT_PRIV
21 #define _GL_HEADER_OPENAT_PRIV
23 #include <errno.h>
24 #include <limits.h>
25 #include <stdlib.h>
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
32 /* Maximum number of bytes that it is safe to allocate as a single
33 array on the stack, and that is known as a compile-time constant.
34 The assumption is that we'll touch the array very quickly, or a
35 temporary very near the array, provoking an out-of-memory trap. On
36 some operating systems, there is only one guard page for the stack,
37 and a page size can be as small as 4096 bytes. Subtract 64 in the
38 hope that this will let the compiler touch a nearby temporary and
39 provoke a trap. */
40 #define SAFER_ALLOCA_MAX (4096 - 64)
42 #define SAFER_ALLOCA(m) ((m) < SAFER_ALLOCA_MAX ? (m) : SAFER_ALLOCA_MAX)
44 #if defined PATH_MAX
45 # define OPENAT_BUFFER_SIZE SAFER_ALLOCA (PATH_MAX)
46 #elif defined _XOPEN_PATH_MAX
47 # define OPENAT_BUFFER_SIZE SAFER_ALLOCA (_XOPEN_PATH_MAX)
48 #else
49 # define OPENAT_BUFFER_SIZE SAFER_ALLOCA (1024)
50 #endif
52 char *openat_proc_name (char buf[OPENAT_BUFFER_SIZE], int fd, char const *file);
54 /* Trying to access a BUILD_PROC_NAME file will fail on systems without
55 /proc support, and even on systems *with* ProcFS support. Return
56 nonzero if the failure may be legitimate, e.g., because /proc is not
57 readable, or the particular .../fd/N directory is not present. */
58 #define EXPECTED_ERRNO(Errno) \
59 ((Errno) == ENOTDIR || (Errno) == ENOENT \
60 || (Errno) == EPERM || (Errno) == EACCES \
61 || (Errno) == ENOSYS /* Solaris 8 */ \
62 || (Errno) == EOPNOTSUPP /* FreeBSD */)
64 /* Wrapper function shared among linkat and renameat. */
65 int at_func2 (int fd1, char const *file1,
66 int fd2, char const *file2,
67 int (*func) (char const *file1, char const *file2));
70 #ifdef __cplusplus
72 #endif
74 #endif /* _GL_HEADER_OPENAT_PRIV */