* lisp/emacs-lisp/package.el: Revert async package transactions
[emacs.git] / lib / readlinkat.c
blobf4826f92028712a41777f5025a9cea9d276532af
1 /* Read a symlink relative to an open directory.
2 Copyright (C) 2009-2015 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17 /* written by Eric Blake */
19 #include <config.h>
21 #include <unistd.h>
23 #if HAVE_READLINKAT
25 # undef readlinkat
27 ssize_t
28 rpl_readlinkat (int fd, char const *file, char *buf, size_t len)
30 return readlinkat (fd, file, buf, len);
33 #else
35 /* Gnulib provides a readlink stub for mingw; use it for distinction
36 between EINVAL and ENOENT, rather than always failing with ENOSYS. */
38 /* POSIX 2008 says that unlike readlink, readlinkat returns 0 for
39 success instead of the buffer length. But this would render
40 readlinkat worthless since readlink does not guarantee a
41 NUL-terminated buffer. Assume this was a bug in POSIX. */
43 /* Read the contents of symlink FILE into buffer BUF of size LEN, in the
44 directory open on descriptor FD. If possible, do it without changing
45 the working directory. Otherwise, resort to using save_cwd/fchdir,
46 then readlink/restore_cwd. If either the save_cwd or the restore_cwd
47 fails, then give a diagnostic and exit nonzero. */
49 # define AT_FUNC_NAME readlinkat
50 # define AT_FUNC_F1 readlink
51 # define AT_FUNC_POST_FILE_PARAM_DECLS , char *buf, size_t len
52 # define AT_FUNC_POST_FILE_ARGS , buf, len
53 # define AT_FUNC_RESULT ssize_t
54 # include "at-func.c"
55 # undef AT_FUNC_NAME
56 # undef AT_FUNC_F1
57 # undef AT_FUNC_POST_FILE_PARAM_DECLS
58 # undef AT_FUNC_POST_FILE_ARGS
59 # undef AT_FUNC_RESULT
61 #endif