1 /* readlink -- obtain contents of symlink.
3 Copyright 2008, 2009 Karl Berry.
4 Copyright 1998, 1999, 2001, 2005 Olaf Weber.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with this library; if not, see <http://www.gnu.org/licenses/>. */
19 #include <kpathsea/config.h>
20 #include <kpathsea/c-pathmx.h>
21 #include <kpathsea/c-unistd.h>
22 #include <kpathsea/c-stat.h>
30 * Returns 0 if name exists and is a symlink, 1 otherwise. The contents
31 * of the link are printed on standard output.
35 main (int argc
, char **argv
)
42 if (argc
> 1 && strcmp (argv
[1], "--help") == 0) {
43 printf("Usage: %s FILE\n\
44 If FILE exists and is a symlink, print the contents of the link and\n\
45 exit successfully. Otherwise print nothing and fail.\n\
47 --help display this help and exit\n\
48 --version output version information and exit\n\n", argv
[0]);
49 fputs ("Email bug reports to tex-k@tug.org.\n", stdout
);
51 } else if (argc
> 1 && strcmp (argv
[1], "--version") == 0) {
53 Copyright (C) 2009 Olaf Weber & Karl Berry.\n\
54 There is NO warranty. You may redistribute this software\n\
55 under the terms of the GNU General Public License\n\
56 For more information about these matters, see the file named GPL.\n\
57 Primary author of %s: Olaf Weber.\n",
58 argv
[0], KPSEVERSION
, argv
[0]);
62 /* insist on exactly one arg */
64 fprintf(stderr
, "%s: Need exactly one argument.\n\
65 Try `%s --help' for more information.\n", argv
[0], argv
[0]);
70 status
= readlink(argv
[1], path
, PATH_MAX
);
72 printf("%.*s\n", status
, path
);