Changeset 370 for trunk/src/gmake/kmkbuiltin/ln.c
- Timestamp:
- Dec 18, 2005, 4:48:02 AM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/gmake/kmkbuiltin/ln.c
r368 r370 38 38 static char sccsid[] = "@(#)ln.c 8.2 (Berkeley) 3/31/94"; 39 39 #endif /* not lint */ 40 #endif41 40 #include <sys/cdefs.h> 42 41 __FBSDID("$FreeBSD: src/bin/ln/ln.c,v 1.33 2005/02/09 17:37:37 ru Exp $"); 43 42 #endif /* no $id */ 43 44 #ifndef _MSC_VER 44 45 #include <sys/param.h> 46 #endif 45 47 #include <sys/stat.h> 46 48 47 #include <err.h>49 #include "err.h" 48 50 #include <errno.h> 49 51 #include <limits.h> … … 51 53 #include <stdlib.h> 52 54 #include <string.h> 55 #ifndef _MSC_VER 53 56 #include <unistd.h> 57 #else 58 #include "mscfakes.h" 59 #endif 54 60 55 61 static int fflag; /* Unlink existing files. */ … … 63 69 64 70 static int linkit(const char *, const char *, int); 65 static void usage(void); 71 static int usage(void); 72 66 73 67 74 int … … 72 79 int ch, exitval; 73 80 81 /* kmk: reset getopt() and set program name. */ 82 g_progname = argv[0]; 83 opterr = 1; 84 optarg = NULL; 85 optopt = 0; 86 #if defined(__FreeBSD__) || defined(__EMX__) 87 optreset = 1; 88 optind = 1; 89 #else 90 optind = 0; /* init */ 91 #endif 92 93 #if 0 /* kmk: we don't need this. */ 74 94 /* 75 95 * Test for the special case where the utility is called as … … 83 103 if (strcmp(p, "link") == 0) { 84 104 while (getopt(argc, argv, "") != -1) 85 usage();105 return usage(); 86 106 argc -= optind; 87 107 argv += optind; 88 108 if (argc != 2) 89 usage();109 return usage(); 90 110 linkf = link; 91 exit(linkit(argv[0], argv[1], 0)); 92 } 111 return linkit(argv[0], argv[1], 0); 112 } 113 #else 114 (void)p; 115 #endif 116 93 117 94 118 while ((ch = getopt(argc, argv, "fhinsv")) != -1) … … 114 138 case '?': 115 139 default: 116 usage();140 return usage(); 117 141 } 118 142 … … 125 149 switch(argc) { 126 150 case 0: 127 usage();151 return usage(); 128 152 /* NOTREACHED */ 129 153 case 1: /* ln target */ 130 exit(linkit(argv[0], ".", 1));154 return linkit(argv[0], ".", 1); 131 155 case 2: /* ln target source */ 132 exit(linkit(argv[0], argv[1], 0));156 return linkit(argv[0], argv[1], 0); 133 157 default: 134 158 ; … … 142 166 */ 143 167 errno = ENOTDIR; 144 err(1, "%s", sourcedir);168 return err(1, "%s", sourcedir); 145 169 } 146 170 if (stat(sourcedir, &sb)) 147 err(1, "%s", sourcedir);171 return err(1, "%s", sourcedir); 148 172 if (!S_ISDIR(sb.st_mode)) 149 usage();173 return usage(); 150 174 for (exitval = 0; *argv != sourcedir; ++argv) 151 175 exitval |= linkit(*argv, sourcedir, 1); 152 exit(exitval);176 return exitval; 153 177 } 154 178 155 int179 static int 156 180 linkit(const char *target, const char *source, int isdir) 157 181 { … … 233 257 } 234 258 235 void 259 static int 236 260 usage(void) 237 261 { … … 240 264 " ln [-fhinsv] source_file ... target_dir", 241 265 " link source_file target_file"); 242 exit(1);266 return 1; 243 267 }
Note:
See TracChangeset
for help on using the changeset viewer.