564704a08fa7505ba9a389a8adfdf7a2400d1844
[debian/tar] / gnu / areadlinkat.c
1 /* -*- buffer-read-only: t -*- vi: set ro: */
2 /* DO NOT EDIT! GENERATED AUTOMATICALLY! */
3 /* areadlinkat.c -- readlinkat wrapper to return malloc'd link name
4    Unlike xreadlinkat, only call exit on failure to change directory.
5
6    Copyright (C) 2001, 2003-2007, 2009-2014 Free Software Foundation, Inc.
7
8    This program is free software: you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 3 of the License, or
11    (at your option) any later version.
12
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
20
21 /* Written by Jim Meyering <jim@meyering.net>,
22    and Bruno Haible <bruno@clisp.org>,
23    and Eric Blake <ebb9@byu.net>.  */
24
25 #include <config.h>
26
27 /* Specification.  */
28 #include "areadlink.h"
29
30 #include "careadlinkat.h"
31
32 #if HAVE_READLINKAT
33
34 /* Call readlinkat to get the symbolic link value of FILENAME relative to FD.
35    Return a pointer to that NUL-terminated string in malloc'd storage.
36    If readlinkat fails, return NULL and set errno (although failure to
37    change directory will issue a diagnostic and exit).
38    If allocation fails, or if the link value is longer than SIZE_MAX :-),
39    return NULL and set errno to ENOMEM.  */
40
41 char *
42 areadlinkat (int fd, char const *filename)
43 {
44   return careadlinkat (fd, filename, NULL, 0, NULL, readlinkat);
45 }
46
47 #else /* !HAVE_READLINKAT */
48
49 /* It is more efficient to change directories only once and call
50    areadlink, rather than repeatedly call the replacement
51    readlinkat.  */
52
53 # define AT_FUNC_NAME areadlinkat
54 # define AT_FUNC_F1 areadlink
55 # define AT_FUNC_POST_FILE_PARAM_DECLS /* empty */
56 # define AT_FUNC_POST_FILE_ARGS        /* empty */
57 # define AT_FUNC_RESULT char *
58 # define AT_FUNC_FAIL NULL
59 # include "at-func.c"
60 # undef AT_FUNC_NAME
61 # undef AT_FUNC_F1
62 # undef AT_FUNC_POST_FILE_PARAM_DECLS
63 # undef AT_FUNC_POST_FILE_ARGS
64 # undef AT_FUNC_RESULT
65 # undef AT_FUNC_FAIL
66
67 #endif /* !HAVE_READLINKAT */