Mercurial > hg > octave-nkf > gnulib-hg
annotate lib/readlinkat.c @ 17848:ab58d4870664
version-etc: new year
* doc/gnulib.texi:
* lib/version-etc.c (COPYRIGHT_YEAR): Update copyright date.
* all files: Run 'make update-copyright'.
author | Paul Eggert <eggert@cs.ucla.edu> |
---|---|
date | Thu, 01 Jan 2015 01:38:23 +0000 |
parents | 05d77e098e6e |
children |
rev | line source |
---|---|
13539
56e31af9a41e
readlinkat: split into its own module
Eric Blake <eblake@redhat.com>
parents:
diff
changeset
|
1 /* Read a symlink relative to an open directory. |
17848 | 2 Copyright (C) 2009-2015 Free Software Foundation, Inc. |
13539
56e31af9a41e
readlinkat: split into its own module
Eric Blake <eblake@redhat.com>
parents:
diff
changeset
|
3 |
56e31af9a41e
readlinkat: split into its own module
Eric Blake <eblake@redhat.com>
parents:
diff
changeset
|
4 This program is free software: you can redistribute it and/or modify |
56e31af9a41e
readlinkat: split into its own module
Eric Blake <eblake@redhat.com>
parents:
diff
changeset
|
5 it under the terms of the GNU General Public License as published by |
56e31af9a41e
readlinkat: split into its own module
Eric Blake <eblake@redhat.com>
parents:
diff
changeset
|
6 the Free Software Foundation; either version 3 of the License, or |
56e31af9a41e
readlinkat: split into its own module
Eric Blake <eblake@redhat.com>
parents:
diff
changeset
|
7 (at your option) any later version. |
56e31af9a41e
readlinkat: split into its own module
Eric Blake <eblake@redhat.com>
parents:
diff
changeset
|
8 |
56e31af9a41e
readlinkat: split into its own module
Eric Blake <eblake@redhat.com>
parents:
diff
changeset
|
9 This program is distributed in the hope that it will be useful, |
56e31af9a41e
readlinkat: split into its own module
Eric Blake <eblake@redhat.com>
parents:
diff
changeset
|
10 but WITHOUT ANY WARRANTY; without even the implied warranty of |
56e31af9a41e
readlinkat: split into its own module
Eric Blake <eblake@redhat.com>
parents:
diff
changeset
|
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
56e31af9a41e
readlinkat: split into its own module
Eric Blake <eblake@redhat.com>
parents:
diff
changeset
|
12 GNU General Public License for more details. |
56e31af9a41e
readlinkat: split into its own module
Eric Blake <eblake@redhat.com>
parents:
diff
changeset
|
13 |
56e31af9a41e
readlinkat: split into its own module
Eric Blake <eblake@redhat.com>
parents:
diff
changeset
|
14 You should have received a copy of the GNU General Public License |
56e31af9a41e
readlinkat: split into its own module
Eric Blake <eblake@redhat.com>
parents:
diff
changeset
|
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
56e31af9a41e
readlinkat: split into its own module
Eric Blake <eblake@redhat.com>
parents:
diff
changeset
|
16 |
56e31af9a41e
readlinkat: split into its own module
Eric Blake <eblake@redhat.com>
parents:
diff
changeset
|
17 /* written by Eric Blake */ |
56e31af9a41e
readlinkat: split into its own module
Eric Blake <eblake@redhat.com>
parents:
diff
changeset
|
18 |
56e31af9a41e
readlinkat: split into its own module
Eric Blake <eblake@redhat.com>
parents:
diff
changeset
|
19 #include <config.h> |
56e31af9a41e
readlinkat: split into its own module
Eric Blake <eblake@redhat.com>
parents:
diff
changeset
|
20 |
56e31af9a41e
readlinkat: split into its own module
Eric Blake <eblake@redhat.com>
parents:
diff
changeset
|
21 #include <unistd.h> |
56e31af9a41e
readlinkat: split into its own module
Eric Blake <eblake@redhat.com>
parents:
diff
changeset
|
22 |
17769
05d77e098e6e
readlinkat: port to AIX 7.1
Paul Eggert <eggert@cs.ucla.edu>
parents:
17587
diff
changeset
|
23 #if HAVE_READLINKAT |
05d77e098e6e
readlinkat: port to AIX 7.1
Paul Eggert <eggert@cs.ucla.edu>
parents:
17587
diff
changeset
|
24 |
05d77e098e6e
readlinkat: port to AIX 7.1
Paul Eggert <eggert@cs.ucla.edu>
parents:
17587
diff
changeset
|
25 # undef readlinkat |
05d77e098e6e
readlinkat: port to AIX 7.1
Paul Eggert <eggert@cs.ucla.edu>
parents:
17587
diff
changeset
|
26 |
05d77e098e6e
readlinkat: port to AIX 7.1
Paul Eggert <eggert@cs.ucla.edu>
parents:
17587
diff
changeset
|
27 ssize_t |
05d77e098e6e
readlinkat: port to AIX 7.1
Paul Eggert <eggert@cs.ucla.edu>
parents:
17587
diff
changeset
|
28 rpl_readlinkat (int fd, char const *file, char *buf, size_t len) |
05d77e098e6e
readlinkat: port to AIX 7.1
Paul Eggert <eggert@cs.ucla.edu>
parents:
17587
diff
changeset
|
29 { |
05d77e098e6e
readlinkat: port to AIX 7.1
Paul Eggert <eggert@cs.ucla.edu>
parents:
17587
diff
changeset
|
30 return readlinkat (fd, file, buf, len); |
05d77e098e6e
readlinkat: port to AIX 7.1
Paul Eggert <eggert@cs.ucla.edu>
parents:
17587
diff
changeset
|
31 } |
05d77e098e6e
readlinkat: port to AIX 7.1
Paul Eggert <eggert@cs.ucla.edu>
parents:
17587
diff
changeset
|
32 |
05d77e098e6e
readlinkat: port to AIX 7.1
Paul Eggert <eggert@cs.ucla.edu>
parents:
17587
diff
changeset
|
33 #else |
05d77e098e6e
readlinkat: port to AIX 7.1
Paul Eggert <eggert@cs.ucla.edu>
parents:
17587
diff
changeset
|
34 |
13539
56e31af9a41e
readlinkat: split into its own module
Eric Blake <eblake@redhat.com>
parents:
diff
changeset
|
35 /* Gnulib provides a readlink stub for mingw; use it for distinction |
56e31af9a41e
readlinkat: split into its own module
Eric Blake <eblake@redhat.com>
parents:
diff
changeset
|
36 between EINVAL and ENOENT, rather than always failing with ENOSYS. */ |
56e31af9a41e
readlinkat: split into its own module
Eric Blake <eblake@redhat.com>
parents:
diff
changeset
|
37 |
56e31af9a41e
readlinkat: split into its own module
Eric Blake <eblake@redhat.com>
parents:
diff
changeset
|
38 /* POSIX 2008 says that unlike readlink, readlinkat returns 0 for |
56e31af9a41e
readlinkat: split into its own module
Eric Blake <eblake@redhat.com>
parents:
diff
changeset
|
39 success instead of the buffer length. But this would render |
56e31af9a41e
readlinkat: split into its own module
Eric Blake <eblake@redhat.com>
parents:
diff
changeset
|
40 readlinkat worthless since readlink does not guarantee a |
56e31af9a41e
readlinkat: split into its own module
Eric Blake <eblake@redhat.com>
parents:
diff
changeset
|
41 NUL-terminated buffer. Assume this was a bug in POSIX. */ |
56e31af9a41e
readlinkat: split into its own module
Eric Blake <eblake@redhat.com>
parents:
diff
changeset
|
42 |
56e31af9a41e
readlinkat: split into its own module
Eric Blake <eblake@redhat.com>
parents:
diff
changeset
|
43 /* Read the contents of symlink FILE into buffer BUF of size LEN, in the |
56e31af9a41e
readlinkat: split into its own module
Eric Blake <eblake@redhat.com>
parents:
diff
changeset
|
44 directory open on descriptor FD. If possible, do it without changing |
56e31af9a41e
readlinkat: split into its own module
Eric Blake <eblake@redhat.com>
parents:
diff
changeset
|
45 the working directory. Otherwise, resort to using save_cwd/fchdir, |
56e31af9a41e
readlinkat: split into its own module
Eric Blake <eblake@redhat.com>
parents:
diff
changeset
|
46 then readlink/restore_cwd. If either the save_cwd or the restore_cwd |
56e31af9a41e
readlinkat: split into its own module
Eric Blake <eblake@redhat.com>
parents:
diff
changeset
|
47 fails, then give a diagnostic and exit nonzero. */ |
56e31af9a41e
readlinkat: split into its own module
Eric Blake <eblake@redhat.com>
parents:
diff
changeset
|
48 |
17769
05d77e098e6e
readlinkat: port to AIX 7.1
Paul Eggert <eggert@cs.ucla.edu>
parents:
17587
diff
changeset
|
49 # define AT_FUNC_NAME readlinkat |
05d77e098e6e
readlinkat: port to AIX 7.1
Paul Eggert <eggert@cs.ucla.edu>
parents:
17587
diff
changeset
|
50 # define AT_FUNC_F1 readlink |
05d77e098e6e
readlinkat: port to AIX 7.1
Paul Eggert <eggert@cs.ucla.edu>
parents:
17587
diff
changeset
|
51 # define AT_FUNC_POST_FILE_PARAM_DECLS , char *buf, size_t len |
05d77e098e6e
readlinkat: port to AIX 7.1
Paul Eggert <eggert@cs.ucla.edu>
parents:
17587
diff
changeset
|
52 # define AT_FUNC_POST_FILE_ARGS , buf, len |
05d77e098e6e
readlinkat: port to AIX 7.1
Paul Eggert <eggert@cs.ucla.edu>
parents:
17587
diff
changeset
|
53 # define AT_FUNC_RESULT ssize_t |
05d77e098e6e
readlinkat: port to AIX 7.1
Paul Eggert <eggert@cs.ucla.edu>
parents:
17587
diff
changeset
|
54 # include "at-func.c" |
05d77e098e6e
readlinkat: port to AIX 7.1
Paul Eggert <eggert@cs.ucla.edu>
parents:
17587
diff
changeset
|
55 # undef AT_FUNC_NAME |
05d77e098e6e
readlinkat: port to AIX 7.1
Paul Eggert <eggert@cs.ucla.edu>
parents:
17587
diff
changeset
|
56 # undef AT_FUNC_F1 |
05d77e098e6e
readlinkat: port to AIX 7.1
Paul Eggert <eggert@cs.ucla.edu>
parents:
17587
diff
changeset
|
57 # undef AT_FUNC_POST_FILE_PARAM_DECLS |
05d77e098e6e
readlinkat: port to AIX 7.1
Paul Eggert <eggert@cs.ucla.edu>
parents:
17587
diff
changeset
|
58 # undef AT_FUNC_POST_FILE_ARGS |
05d77e098e6e
readlinkat: port to AIX 7.1
Paul Eggert <eggert@cs.ucla.edu>
parents:
17587
diff
changeset
|
59 # undef AT_FUNC_RESULT |
05d77e098e6e
readlinkat: port to AIX 7.1
Paul Eggert <eggert@cs.ucla.edu>
parents:
17587
diff
changeset
|
60 |
05d77e098e6e
readlinkat: port to AIX 7.1
Paul Eggert <eggert@cs.ucla.edu>
parents:
17587
diff
changeset
|
61 #endif |