annotate kpathsea/readlink.c @ 4337:d56e0d75e7c9 ss-2-1-45

[project @ 2003-02-19 21:20:19 by jwe]
author jwe
date Wed, 19 Feb 2003 21:20:19 +0000
parents 1f0b06020e36
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3172
1f0b06020e36 [project @ 1998-04-24 04:24:34 by jwe]
jwe
parents:
diff changeset
1 /* readlink -- obtain contents of symlink.
1f0b06020e36 [project @ 1998-04-24 04:24:34 by jwe]
jwe
parents:
diff changeset
2 Copyright (C) 1998 Olaf Weber.
1f0b06020e36 [project @ 1998-04-24 04:24:34 by jwe]
jwe
parents:
diff changeset
3
1f0b06020e36 [project @ 1998-04-24 04:24:34 by jwe]
jwe
parents:
diff changeset
4 This program is free software; you can redistribute it and/or modify
1f0b06020e36 [project @ 1998-04-24 04:24:34 by jwe]
jwe
parents:
diff changeset
5 it under the terms of the GNU General Public License as published by
1f0b06020e36 [project @ 1998-04-24 04:24:34 by jwe]
jwe
parents:
diff changeset
6 the Free Software Foundation; either version 2, or (at your option)
1f0b06020e36 [project @ 1998-04-24 04:24:34 by jwe]
jwe
parents:
diff changeset
7 any later version.
1f0b06020e36 [project @ 1998-04-24 04:24:34 by jwe]
jwe
parents:
diff changeset
8
1f0b06020e36 [project @ 1998-04-24 04:24:34 by jwe]
jwe
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
1f0b06020e36 [project @ 1998-04-24 04:24:34 by jwe]
jwe
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
1f0b06020e36 [project @ 1998-04-24 04:24:34 by jwe]
jwe
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1f0b06020e36 [project @ 1998-04-24 04:24:34 by jwe]
jwe
parents:
diff changeset
12 GNU General Public License for more details.
1f0b06020e36 [project @ 1998-04-24 04:24:34 by jwe]
jwe
parents:
diff changeset
13
1f0b06020e36 [project @ 1998-04-24 04:24:34 by jwe]
jwe
parents:
diff changeset
14 You should have received a copy of the GNU General Public License
1f0b06020e36 [project @ 1998-04-24 04:24:34 by jwe]
jwe
parents:
diff changeset
15 along with this program; if not, write to the Free Software Foundation,
1f0b06020e36 [project @ 1998-04-24 04:24:34 by jwe]
jwe
parents:
diff changeset
16 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
1f0b06020e36 [project @ 1998-04-24 04:24:34 by jwe]
jwe
parents:
diff changeset
17
1f0b06020e36 [project @ 1998-04-24 04:24:34 by jwe]
jwe
parents:
diff changeset
18 #include <stdio.h>
1f0b06020e36 [project @ 1998-04-24 04:24:34 by jwe]
jwe
parents:
diff changeset
19 #include <kpathsea/config.h>
1f0b06020e36 [project @ 1998-04-24 04:24:34 by jwe]
jwe
parents:
diff changeset
20 #include <kpathsea/c-pathmx.h>
1f0b06020e36 [project @ 1998-04-24 04:24:34 by jwe]
jwe
parents:
diff changeset
21 #include <kpathsea/c-unistd.h>
1f0b06020e36 [project @ 1998-04-24 04:24:34 by jwe]
jwe
parents:
diff changeset
22 #include <kpathsea/c-stat.h>
1f0b06020e36 [project @ 1998-04-24 04:24:34 by jwe]
jwe
parents:
diff changeset
23
1f0b06020e36 [project @ 1998-04-24 04:24:34 by jwe]
jwe
parents:
diff changeset
24 #ifdef WIN32
1f0b06020e36 [project @ 1998-04-24 04:24:34 by jwe]
jwe
parents:
diff changeset
25 #include <string.h>
1f0b06020e36 [project @ 1998-04-24 04:24:34 by jwe]
jwe
parents:
diff changeset
26 #endif
1f0b06020e36 [project @ 1998-04-24 04:24:34 by jwe]
jwe
parents:
diff changeset
27
1f0b06020e36 [project @ 1998-04-24 04:24:34 by jwe]
jwe
parents:
diff changeset
28 /*
1f0b06020e36 [project @ 1998-04-24 04:24:34 by jwe]
jwe
parents:
diff changeset
29 * readlink name
1f0b06020e36 [project @ 1998-04-24 04:24:34 by jwe]
jwe
parents:
diff changeset
30 * Returns 0 if name exists and is a symlink, 1 otherwise. The contents
1f0b06020e36 [project @ 1998-04-24 04:24:34 by jwe]
jwe
parents:
diff changeset
31 * of the link are printed on standard output.
1f0b06020e36 [project @ 1998-04-24 04:24:34 by jwe]
jwe
parents:
diff changeset
32 */
1f0b06020e36 [project @ 1998-04-24 04:24:34 by jwe]
jwe
parents:
diff changeset
33
1f0b06020e36 [project @ 1998-04-24 04:24:34 by jwe]
jwe
parents:
diff changeset
34 int main (argc, argv)
1f0b06020e36 [project @ 1998-04-24 04:24:34 by jwe]
jwe
parents:
diff changeset
35 int argc;
1f0b06020e36 [project @ 1998-04-24 04:24:34 by jwe]
jwe
parents:
diff changeset
36 char *argv[];
1f0b06020e36 [project @ 1998-04-24 04:24:34 by jwe]
jwe
parents:
diff changeset
37 {
1f0b06020e36 [project @ 1998-04-24 04:24:34 by jwe]
jwe
parents:
diff changeset
38 #ifdef S_ISLNK
1f0b06020e36 [project @ 1998-04-24 04:24:34 by jwe]
jwe
parents:
diff changeset
39 int status;
1f0b06020e36 [project @ 1998-04-24 04:24:34 by jwe]
jwe
parents:
diff changeset
40 char path[PATH_MAX];
1f0b06020e36 [project @ 1998-04-24 04:24:34 by jwe]
jwe
parents:
diff changeset
41 #endif
1f0b06020e36 [project @ 1998-04-24 04:24:34 by jwe]
jwe
parents:
diff changeset
42
1f0b06020e36 [project @ 1998-04-24 04:24:34 by jwe]
jwe
parents:
diff changeset
43 if (argc > 1 && strcmp (argv[1], "--help") == 0) {
1f0b06020e36 [project @ 1998-04-24 04:24:34 by jwe]
jwe
parents:
diff changeset
44 printf("Usage: %s FILE\n\
1f0b06020e36 [project @ 1998-04-24 04:24:34 by jwe]
jwe
parents:
diff changeset
45 If FILE exists and is a symlink, print the contents of the link and\n\
1f0b06020e36 [project @ 1998-04-24 04:24:34 by jwe]
jwe
parents:
diff changeset
46 exit successfully. Otherwise print nothing and fail.\n\
1f0b06020e36 [project @ 1998-04-24 04:24:34 by jwe]
jwe
parents:
diff changeset
47 \n\
1f0b06020e36 [project @ 1998-04-24 04:24:34 by jwe]
jwe
parents:
diff changeset
48 --help display this help and exit\n\
1f0b06020e36 [project @ 1998-04-24 04:24:34 by jwe]
jwe
parents:
diff changeset
49 --version output version information and exit\n\n", argv[0]);
1f0b06020e36 [project @ 1998-04-24 04:24:34 by jwe]
jwe
parents:
diff changeset
50 fputs ("Email bug reports to tex-k@mail.tug.org.\n", stdout);
1f0b06020e36 [project @ 1998-04-24 04:24:34 by jwe]
jwe
parents:
diff changeset
51 exit(0);
1f0b06020e36 [project @ 1998-04-24 04:24:34 by jwe]
jwe
parents:
diff changeset
52 } else if (argc > 1 && strcmp (argv[1], "--version") == 0) {
1f0b06020e36 [project @ 1998-04-24 04:24:34 by jwe]
jwe
parents:
diff changeset
53 printf ("%s (%s)\n\
1f0b06020e36 [project @ 1998-04-24 04:24:34 by jwe]
jwe
parents:
diff changeset
54 Copyright (C) 1998 Olaf Weber.\n\
1f0b06020e36 [project @ 1998-04-24 04:24:34 by jwe]
jwe
parents:
diff changeset
55 There is NO warranty. You may redistribute this software\n\
1f0b06020e36 [project @ 1998-04-24 04:24:34 by jwe]
jwe
parents:
diff changeset
56 under the terms of the GNU General Public License\n\
1f0b06020e36 [project @ 1998-04-24 04:24:34 by jwe]
jwe
parents:
diff changeset
57 For more information about these matters, see the file named COPYING.\n\
1f0b06020e36 [project @ 1998-04-24 04:24:34 by jwe]
jwe
parents:
diff changeset
58 Primary author of %s: Olaf Weber.\n",
1f0b06020e36 [project @ 1998-04-24 04:24:34 by jwe]
jwe
parents:
diff changeset
59 argv[0], KPSEVERSION, argv[0]);
1f0b06020e36 [project @ 1998-04-24 04:24:34 by jwe]
jwe
parents:
diff changeset
60 exit (0);
1f0b06020e36 [project @ 1998-04-24 04:24:34 by jwe]
jwe
parents:
diff changeset
61 }
1f0b06020e36 [project @ 1998-04-24 04:24:34 by jwe]
jwe
parents:
diff changeset
62
1f0b06020e36 [project @ 1998-04-24 04:24:34 by jwe]
jwe
parents:
diff changeset
63 /* insist on exactly one arg */
1f0b06020e36 [project @ 1998-04-24 04:24:34 by jwe]
jwe
parents:
diff changeset
64 if (argc != 2) {
1f0b06020e36 [project @ 1998-04-24 04:24:34 by jwe]
jwe
parents:
diff changeset
65 fprintf(stderr, "%s: Need exactly one argument.\n\
1f0b06020e36 [project @ 1998-04-24 04:24:34 by jwe]
jwe
parents:
diff changeset
66 Try `access --help' for more information.\n", argv[0]);
1f0b06020e36 [project @ 1998-04-24 04:24:34 by jwe]
jwe
parents:
diff changeset
67 exit(1);
1f0b06020e36 [project @ 1998-04-24 04:24:34 by jwe]
jwe
parents:
diff changeset
68 }
1f0b06020e36 [project @ 1998-04-24 04:24:34 by jwe]
jwe
parents:
diff changeset
69
1f0b06020e36 [project @ 1998-04-24 04:24:34 by jwe]
jwe
parents:
diff changeset
70 #ifdef S_ISLNK
1f0b06020e36 [project @ 1998-04-24 04:24:34 by jwe]
jwe
parents:
diff changeset
71 status = readlink(argv[1], path, PATH_MAX);
1f0b06020e36 [project @ 1998-04-24 04:24:34 by jwe]
jwe
parents:
diff changeset
72 if (status != -1) {
1f0b06020e36 [project @ 1998-04-24 04:24:34 by jwe]
jwe
parents:
diff changeset
73 printf("%.*s\n", status, path);
1f0b06020e36 [project @ 1998-04-24 04:24:34 by jwe]
jwe
parents:
diff changeset
74 return 0;
1f0b06020e36 [project @ 1998-04-24 04:24:34 by jwe]
jwe
parents:
diff changeset
75 }
1f0b06020e36 [project @ 1998-04-24 04:24:34 by jwe]
jwe
parents:
diff changeset
76 #endif
1f0b06020e36 [project @ 1998-04-24 04:24:34 by jwe]
jwe
parents:
diff changeset
77 return 1;
1f0b06020e36 [project @ 1998-04-24 04:24:34 by jwe]
jwe
parents:
diff changeset
78 }