declare smobs in alloc.c
[bpt/emacs.git] / lib / careadlinkat.h
CommitLineData
d1fdcab7
PE
1/* Read symbolic links into a buffer without size limitation, relative to fd.
2
ba318903 3 Copyright (C) 2011-2014 Free Software Foundation, Inc.
d1fdcab7
PE
4
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.
9
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.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17
18/* Written by Paul Eggert, Bruno Haible, and Jim Meyering. */
19
20#ifndef _GL_CAREADLINKAT_H
e5b28a7a 21#define _GL_CAREADLINKAT_H
d1fdcab7
PE
22
23#include <fcntl.h>
24#include <unistd.h>
25
26struct allocator;
27
28/* Assuming the current directory is FD, get the symbolic link value
29 of FILENAME as a null-terminated string and put it into a buffer.
30 If FD is AT_FDCWD, FILENAME is interpreted relative to the current
31 working directory, as in openat.
32
33 If the link is small enough to fit into BUFFER put it there.
34 BUFFER's size is BUFFER_SIZE, and BUFFER can be null
35 if BUFFER_SIZE is zero.
36
37 If the link is not small, put it into a dynamically allocated
38 buffer managed by ALLOC. It is the caller's responsibility to free
39 the returned value if it is nonnull and is not BUFFER.
40
e5b28a7a
PE
41 The PREADLINKAT function specifies how to read links. It operates
42 like POSIX readlinkat()
43 <http://pubs.opengroup.org/onlinepubs/9699919799/functions/readlink.html>
44 but can assume that its first argument is the same as FD.
d1fdcab7
PE
45
46 If successful, return the buffer address; otherwise return NULL and
47 set errno. */
48
49char *careadlinkat (int fd, char const *filename,
50 char *buffer, size_t buffer_size,
51 struct allocator const *alloc,
52 ssize_t (*preadlinkat) (int, char const *,
53 char *, size_t));
54
8376d87e 55/* Suitable value for careadlinkat's FD argument. */
d1fdcab7 56#if HAVE_READLINKAT
9afafefb 57/* AT_FDCWD is declared in <fcntl.h>. */
d1fdcab7
PE
58#else
59/* Define AT_FDCWD independently, so that the careadlinkat module does
8376d87e 60 not depend on the fcntl-h module. We might as well use the same value
d1fdcab7
PE
61 as fcntl-h. */
62# ifndef AT_FDCWD
63# define AT_FDCWD (-3041965)
64# endif
9afafefb 65#endif
d1fdcab7
PE
66
67#endif /* _GL_CAREADLINKAT_H */