annotate lib/xreadlink.c @ 17476:6057744acd2c default tip master

autoupdate
author Karl Berry <karl@freefriends.org>
date Fri, 16 Aug 2013 06:32:22 -0700 (2013-08-16)
parents e542fd46ad6f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8263
0b51384602a2 Add the xreadlink module from GNU gettext (based on code from Jim Meyering).
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1 /* xreadlink.c -- readlink wrapper to return the link name in malloc'd storage
0b51384602a2 Add the xreadlink module from GNU gettext (based on code from Jim Meyering).
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
2
17249
e542fd46ad6f maint: update all copyright year number ranges
Eric Blake <eblake@redhat.com>
parents: 16201
diff changeset
3 Copyright (C) 2001, 2003-2007, 2009-2013 Free Software Foundation, Inc.
8263
0b51384602a2 Add the xreadlink module from GNU gettext (based on code from Jim Meyering).
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
4
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 9238
diff changeset
5 This program is free software: you can redistribute it and/or modify
8263
0b51384602a2 Add the xreadlink module from GNU gettext (based on code from Jim Meyering).
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
6 it under the terms of the GNU General Public License as published by
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 9238
diff changeset
7 the Free Software Foundation; either version 3 of the License, or
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 9238
diff changeset
8 (at your option) any later version.
8263
0b51384602a2 Add the xreadlink module from GNU gettext (based on code from Jim Meyering).
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9
0b51384602a2 Add the xreadlink module from GNU gettext (based on code from Jim Meyering).
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 This program is distributed in the hope that it will be useful,
0b51384602a2 Add the xreadlink module from GNU gettext (based on code from Jim Meyering).
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
0b51384602a2 Add the xreadlink module from GNU gettext (based on code from Jim Meyering).
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0b51384602a2 Add the xreadlink module from GNU gettext (based on code from Jim Meyering).
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13 GNU General Public License for more details.
0b51384602a2 Add the xreadlink module from GNU gettext (based on code from Jim Meyering).
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
14
0b51384602a2 Add the xreadlink module from GNU gettext (based on code from Jim Meyering).
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
15 You should have received a copy of the GNU General Public License
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 9238
diff changeset
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
8263
0b51384602a2 Add the xreadlink module from GNU gettext (based on code from Jim Meyering).
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17
0b51384602a2 Add the xreadlink module from GNU gettext (based on code from Jim Meyering).
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18 /* Written by Jim Meyering <jim@meyering.net>
0b51384602a2 Add the xreadlink module from GNU gettext (based on code from Jim Meyering).
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
19 and Bruno Haible <bruno@clisp.org>. */
0b51384602a2 Add the xreadlink module from GNU gettext (based on code from Jim Meyering).
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20
0b51384602a2 Add the xreadlink module from GNU gettext (based on code from Jim Meyering).
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21 #include <config.h>
0b51384602a2 Add the xreadlink module from GNU gettext (based on code from Jim Meyering).
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
22
0b51384602a2 Add the xreadlink module from GNU gettext (based on code from Jim Meyering).
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
23 /* Specification. */
0b51384602a2 Add the xreadlink module from GNU gettext (based on code from Jim Meyering).
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
24 #include "xreadlink.h"
0b51384602a2 Add the xreadlink module from GNU gettext (based on code from Jim Meyering).
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
25
0b51384602a2 Add the xreadlink module from GNU gettext (based on code from Jim Meyering).
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
26 #include <errno.h>
0b51384602a2 Add the xreadlink module from GNU gettext (based on code from Jim Meyering).
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
27
9238
6d715fbc981c Change xreadlink module to use areadlink.
Bruno Haible <bruno@clisp.org>
parents: 8303
diff changeset
28 #include "areadlink.h"
6d715fbc981c Change xreadlink module to use areadlink.
Bruno Haible <bruno@clisp.org>
parents: 8303
diff changeset
29 #include "xalloc.h"
8263
0b51384602a2 Add the xreadlink module from GNU gettext (based on code from Jim Meyering).
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
30
0b51384602a2 Add the xreadlink module from GNU gettext (based on code from Jim Meyering).
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
31 /* Call readlink to get the symbolic link value of FILENAME.
0b51384602a2 Add the xreadlink module from GNU gettext (based on code from Jim Meyering).
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
32 Return a pointer to that NUL-terminated string in malloc'd storage.
9238
6d715fbc981c Change xreadlink module to use areadlink.
Bruno Haible <bruno@clisp.org>
parents: 8303
diff changeset
33 If readlink fails, return NULL and set errno.
8263
0b51384602a2 Add the xreadlink module from GNU gettext (based on code from Jim Meyering).
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
34 If realloc fails, or if the link value is longer than SIZE_MAX :-),
0b51384602a2 Add the xreadlink module from GNU gettext (based on code from Jim Meyering).
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
35 give a diagnostic and exit. */
0b51384602a2 Add the xreadlink module from GNU gettext (based on code from Jim Meyering).
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
36
0b51384602a2 Add the xreadlink module from GNU gettext (based on code from Jim Meyering).
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
37 char *
0b51384602a2 Add the xreadlink module from GNU gettext (based on code from Jim Meyering).
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
38 xreadlink (char const *filename)
0b51384602a2 Add the xreadlink module from GNU gettext (based on code from Jim Meyering).
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
39 {
9238
6d715fbc981c Change xreadlink module to use areadlink.
Bruno Haible <bruno@clisp.org>
parents: 8303
diff changeset
40 char *result = areadlink (filename);
6d715fbc981c Change xreadlink module to use areadlink.
Bruno Haible <bruno@clisp.org>
parents: 8303
diff changeset
41 if (result == NULL && errno == ENOMEM)
6d715fbc981c Change xreadlink module to use areadlink.
Bruno Haible <bruno@clisp.org>
parents: 8303
diff changeset
42 xalloc_die ();
6d715fbc981c Change xreadlink module to use areadlink.
Bruno Haible <bruno@clisp.org>
parents: 8303
diff changeset
43 return result;
8263
0b51384602a2 Add the xreadlink module from GNU gettext (based on code from Jim Meyering).
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
44 }