3172
|
1 /* readlink -- obtain contents of symlink. |
|
2 Copyright (C) 1998 Olaf Weber. |
|
3 |
|
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 2, or (at your option) |
|
7 any later version. |
|
8 |
|
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. |
|
13 |
|
14 You should have received a copy of the GNU General Public License |
|
15 along with this program; if not, write to the Free Software Foundation, |
|
16 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
|
17 |
|
18 #include <stdio.h> |
|
19 #include <kpathsea/config.h> |
|
20 #include <kpathsea/c-pathmx.h> |
|
21 #include <kpathsea/c-unistd.h> |
|
22 #include <kpathsea/c-stat.h> |
|
23 |
|
24 #ifdef WIN32 |
|
25 #include <string.h> |
|
26 #endif |
|
27 |
|
28 /* |
|
29 * readlink name |
|
30 * Returns 0 if name exists and is a symlink, 1 otherwise. The contents |
|
31 * of the link are printed on standard output. |
|
32 */ |
|
33 |
|
34 int main (argc, argv) |
|
35 int argc; |
|
36 char *argv[]; |
|
37 { |
|
38 #ifdef S_ISLNK |
|
39 int status; |
|
40 char path[PATH_MAX]; |
|
41 #endif |
|
42 |
|
43 if (argc > 1 && strcmp (argv[1], "--help") == 0) { |
|
44 printf("Usage: %s FILE\n\ |
|
45 If FILE exists and is a symlink, print the contents of the link and\n\ |
|
46 exit successfully. Otherwise print nothing and fail.\n\ |
|
47 \n\ |
|
48 --help display this help and exit\n\ |
|
49 --version output version information and exit\n\n", argv[0]); |
|
50 fputs ("Email bug reports to tex-k@mail.tug.org.\n", stdout); |
|
51 exit(0); |
|
52 } else if (argc > 1 && strcmp (argv[1], "--version") == 0) { |
|
53 printf ("%s (%s)\n\ |
|
54 Copyright (C) 1998 Olaf Weber.\n\ |
|
55 There is NO warranty. You may redistribute this software\n\ |
|
56 under the terms of the GNU General Public License\n\ |
|
57 For more information about these matters, see the file named COPYING.\n\ |
|
58 Primary author of %s: Olaf Weber.\n", |
|
59 argv[0], KPSEVERSION, argv[0]); |
|
60 exit (0); |
|
61 } |
|
62 |
|
63 /* insist on exactly one arg */ |
|
64 if (argc != 2) { |
|
65 fprintf(stderr, "%s: Need exactly one argument.\n\ |
|
66 Try `access --help' for more information.\n", argv[0]); |
|
67 exit(1); |
|
68 } |
|
69 |
|
70 #ifdef S_ISLNK |
|
71 status = readlink(argv[1], path, PATH_MAX); |
|
72 if (status != -1) { |
|
73 printf("%.*s\n", status, path); |
|
74 return 0; |
|
75 } |
|
76 #endif |
|
77 return 1; |
|
78 } |