Debian Codegraph @

lib/careadlinkat.h

raw
1 /* Read symbolic links into a buffer without size limitation, relative to fd.
2
3 Copyright (C) 2011-2025 Free Software Foundation, Inc.
4
5 This file is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as
7 published by the Free Software Foundation; either version 2.1 of the
8 License, or (at your option) any later version.
9
10 This file 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 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17
18 /* Written by Paul Eggert, Bruno Haible, and Jim Meyering. */
19
20 #ifndef _GL_CAREADLINKAT_H
21 #define _GL_CAREADLINKAT_H
22
23 /* This file uses HAVE_READLINKAT. */
24 #if !_GL_CONFIG_H_INCLUDED
25 #error "Please include config.h first."
26 #endif
27
28 #include <fcntl.h>
29 #include <unistd.h>
30
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34
35
36 struct allocator;
37
38 /* Assuming the current directory is FD, get the symbolic link value
39 of FILENAME as a null-terminated string and put it into a buffer.
40 If FD is AT_FDCWD, FILENAME is interpreted relative to the current
41 working directory, as in openat.
42
43 If the link is small enough to fit into BUFFER put it there.
44 BUFFER's size is BUFFER_SIZE, and BUFFER can be null
45 if BUFFER_SIZE is zero.
46
47 If the link is not small, put it into a dynamically allocated
48 buffer managed by ALLOC. It is the caller's responsibility to free
49 the returned value if it is nonnull and is not BUFFER.
50
51 The PREADLINKAT function specifies how to read links. It operates
52 like POSIX readlinkat()
53 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/readlink.html>
54 but can assume that its first argument is the same as FD.
55
56 If successful, return the buffer address; otherwise return NULL and
57 set errno. */
58
59 char *careadlinkat (int fd, char const *filename,
60 char *restrict buffer, size_t buffer_size,
61 struct allocator const *alloc,
62 ssize_t (*preadlinkat) (int, char const *,
63 char *, size_t));
64
65 /* Suitable value for careadlinkat's FD argument. */
66 #if HAVE_READLINKAT
67 /* AT_FDCWD is declared in <fcntl.h>. */
68 #else
69 /* Define AT_FDCWD independently, so that the careadlinkat module does
70 not depend on the fcntl-h module. We might as well use the same value
71 as fcntl-h. */
72 # ifndef AT_FDCWD
73 # define AT_FDCWD (-3041965)
74 # endif
75 #endif
76
77
78 #ifdef __cplusplus
79 }
80 #endif
81
82 #endif /* _GL_CAREADLINKAT_H */