| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: ln.c,v 1.34 2008/07/20 00:52:40 lukem Exp $ */ | | 1 | /* $NetBSD: ln.c,v 1.35 2011/08/29 14:38:30 joerg Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (c) 1987, 1993, 1994 | | 4 | * Copyright (c) 1987, 1993, 1994 |
5 | * The Regents of the University of California. All rights reserved. | | 5 | * The Regents of the University of California. All rights reserved. |
6 | * | | 6 | * |
7 | * Redistribution and use in source and binary forms, with or without | | 7 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions | | 8 | * modification, are permitted provided that the following conditions |
9 | * are met: | | 9 | * are met: |
10 | * 1. Redistributions of source code must retain the above copyright | | 10 | * 1. Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer. | | 11 | * notice, this list of conditions and the following disclaimer. |
12 | * 2. Redistributions in binary form must reproduce the above copyright | | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the | | 13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. | | 14 | * documentation and/or other materials provided with the distribution. |
| @@ -29,54 +29,53 @@ | | | @@ -29,54 +29,53 @@ |
29 | * SUCH DAMAGE. | | 29 | * SUCH DAMAGE. |
30 | */ | | 30 | */ |
31 | | | 31 | |
32 | #include <sys/cdefs.h> | | 32 | #include <sys/cdefs.h> |
33 | #ifndef lint | | 33 | #ifndef lint |
34 | __COPYRIGHT("@(#) Copyright (c) 1987, 1993, 1994\ | | 34 | __COPYRIGHT("@(#) Copyright (c) 1987, 1993, 1994\ |
35 | The Regents of the University of California. All rights reserved."); | | 35 | The Regents of the University of California. All rights reserved."); |
36 | #endif /* not lint */ | | 36 | #endif /* not lint */ |
37 | | | 37 | |
38 | #ifndef lint | | 38 | #ifndef lint |
39 | #if 0 | | 39 | #if 0 |
40 | static char sccsid[] = "@(#)ln.c 8.2 (Berkeley) 3/31/94"; | | 40 | static char sccsid[] = "@(#)ln.c 8.2 (Berkeley) 3/31/94"; |
41 | #else | | 41 | #else |
42 | __RCSID("$NetBSD: ln.c,v 1.34 2008/07/20 00:52:40 lukem Exp $"); | | 42 | __RCSID("$NetBSD: ln.c,v 1.35 2011/08/29 14:38:30 joerg Exp $"); |
43 | #endif | | 43 | #endif |
44 | #endif /* not lint */ | | 44 | #endif /* not lint */ |
45 | | | 45 | |
46 | #include <sys/param.h> | | 46 | #include <sys/param.h> |
47 | #include <sys/stat.h> | | 47 | #include <sys/stat.h> |
48 | | | 48 | |
49 | #include <err.h> | | 49 | #include <err.h> |
50 | #include <errno.h> | | 50 | #include <errno.h> |
51 | #include <locale.h> | | 51 | #include <locale.h> |
52 | #include <stdio.h> | | 52 | #include <stdio.h> |
53 | #include <stdlib.h> | | 53 | #include <stdlib.h> |
54 | #include <string.h> | | 54 | #include <string.h> |
55 | #include <unistd.h> | | 55 | #include <unistd.h> |
56 | | | 56 | |
57 | int fflag; /* Unlink existing files. */ | | 57 | static int fflag; /* Unlink existing files. */ |
58 | int hflag; /* Check new name for symlink first. */ | | 58 | static int hflag; /* Check new name for symlink first. */ |
59 | int iflag; /* Interactive mode. */ | | 59 | static int iflag; /* Interactive mode. */ |
60 | int sflag; /* Symbolic, not hard, link. */ | | 60 | static int sflag; /* Symbolic, not hard, link. */ |
61 | int vflag; /* Verbose output */ | | 61 | static int vflag; /* Verbose output */ |
62 | | | 62 | |
63 | /* System link call. */ | | 63 | /* System link call. */ |
64 | int (*linkf)(const char *, const char *); | | 64 | static int (*linkf)(const char *, const char *); |
65 | char linkch; | | 65 | static char linkch; |
66 | | | 66 | |
67 | int linkit(const char *, const char *, int); | | 67 | static int linkit(const char *, const char *, int); |
68 | void usage(void); | | 68 | __dead static void usage(void); |
69 | int main(int, char *[]); | | | |
70 | | | 69 | |
71 | int | | 70 | int |
72 | main(int argc, char *argv[]) | | 71 | main(int argc, char *argv[]) |
73 | { | | 72 | { |
74 | struct stat sb; | | 73 | struct stat sb; |
75 | int ch, exitval; | | 74 | int ch, exitval; |
76 | char *sourcedir; | | 75 | char *sourcedir; |
77 | | | 76 | |
78 | setprogname(argv[0]); | | 77 | setprogname(argv[0]); |
79 | (void)setlocale(LC_ALL, ""); | | 78 | (void)setlocale(LC_ALL, ""); |
80 | | | 79 | |
81 | while ((ch = getopt(argc, argv, "fhinsv")) != -1) | | 80 | while ((ch = getopt(argc, argv, "fhinsv")) != -1) |
82 | switch (ch) { | | 81 | switch (ch) { |
| @@ -140,27 +139,27 @@ main(int argc, char *argv[]) | | | @@ -140,27 +139,27 @@ main(int argc, char *argv[]) |
140 | err(EXIT_FAILURE, "%s", sourcedir); | | 139 | err(EXIT_FAILURE, "%s", sourcedir); |
141 | /* NOTREACHED */ | | 140 | /* NOTREACHED */ |
142 | } | | 141 | } |
143 | if (!S_ISDIR(sb.st_mode)) { | | 142 | if (!S_ISDIR(sb.st_mode)) { |
144 | usage(); | | 143 | usage(); |
145 | /* NOTREACHED */ | | 144 | /* NOTREACHED */ |
146 | } | | 145 | } |
147 | for (exitval = 0; *argv != sourcedir; ++argv) | | 146 | for (exitval = 0; *argv != sourcedir; ++argv) |
148 | exitval |= linkit(*argv, sourcedir, 1); | | 147 | exitval |= linkit(*argv, sourcedir, 1); |
149 | exit(exitval); | | 148 | exit(exitval); |
150 | /* NOTREACHED */ | | 149 | /* NOTREACHED */ |
151 | } | | 150 | } |
152 | | | 151 | |
153 | int | | 152 | static int |
154 | linkit(const char *target, const char *source, int isdir) | | 153 | linkit(const char *target, const char *source, int isdir) |
155 | { | | 154 | { |
156 | struct stat sb; | | 155 | struct stat sb; |
157 | const char *p; | | 156 | const char *p; |
158 | char path[MAXPATHLEN]; | | 157 | char path[MAXPATHLEN]; |
159 | int ch, exists, first; | | 158 | int ch, exists, first; |
160 | | | 159 | |
161 | if (!sflag) { | | 160 | if (!sflag) { |
162 | /* If target doesn't exist, quit now. */ | | 161 | /* If target doesn't exist, quit now. */ |
163 | if (stat(target, &sb)) { | | 162 | if (stat(target, &sb)) { |
164 | warn("%s", target); | | 163 | warn("%s", target); |
165 | return (1); | | 164 | return (1); |
166 | } | | 165 | } |
| @@ -209,23 +208,23 @@ linkit(const char *target, const char *s | | | @@ -209,23 +208,23 @@ linkit(const char *target, const char *s |
209 | } | | 208 | } |
210 | | | 209 | |
211 | /* Attempt the link. */ | | 210 | /* Attempt the link. */ |
212 | if ((*linkf)(target, source)) { | | 211 | if ((*linkf)(target, source)) { |
213 | warn("%s", source); | | 212 | warn("%s", source); |
214 | return (1); | | 213 | return (1); |
215 | } | | 214 | } |
216 | if (vflag) | | 215 | if (vflag) |
217 | (void)printf("%s %c> %s\n", source, linkch, target); | | 216 | (void)printf("%s %c> %s\n", source, linkch, target); |
218 | | | 217 | |
219 | return (0); | | 218 | return (0); |
220 | } | | 219 | } |
221 | | | 220 | |
222 | void | | 221 | static void |
223 | usage(void) | | 222 | usage(void) |
224 | { | | 223 | { |
225 | | | 224 | |
226 | (void)fprintf(stderr, | | 225 | (void)fprintf(stderr, |
227 | "usage:\t%s [-fhinsv] file1 file2\n\t%s [-fhinsv] file ... directory\n", | | 226 | "usage:\t%s [-fhinsv] file1 file2\n\t%s [-fhinsv] file ... directory\n", |
228 | getprogname(), getprogname()); | | 227 | getprogname(), getprogname()); |
229 | exit(1); | | 228 | exit(1); |
230 | /* NOTREACHED */ | | 229 | /* NOTREACHED */ |
231 | } | | 230 | } |