Changeset 370 in kBuild
- Timestamp:
- Dec 18, 2005 3:48:02 AM (19 years ago)
- Location:
- trunk/src/gmake
- Files:
-
- 6 added
- 16 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/gmake/Makefile.kmk
r368 r370 71 71 kmkbuiltin/echo.c \ 72 72 kmkbuiltin/mkdir.c \ 73 kmkbuiltin/setmode.c 73 kmkbuiltin/ln.c \ 74 kmkbuiltin/install.c \ 75 kmkbuiltin/rm.c \ 76 \ 77 kmkbuiltin/err.c \ 78 kmkbuiltin/setmode.c \ 79 kmkbuiltin/strmode.c 74 80 ifneq ($(BUILD_TARGET),win32) 75 81 kmk_SOURCES += \ 76 kmkbuiltin/rm.c \77 82 kmkbuiltin/cp.c \ 78 83 kmkbuiltin/cp_utils.c \ 79 kmkbuiltin/ln.c \80 kmkbuiltin/install.c \81 84 \ 82 kmkbuiltin/strmode.c \83 85 kmkbuiltin/strlcpy.c 84 86 endif 87 kmk_SOURCES.win32 += kmkbuiltin/mscfakes.c 85 88 86 89 … … 88 91 # Standalone kmkbuiltin commands. 89 92 # 90 ifneq ($(BUILD_TARGET),win32) 91 PROGRAMS += kmk_append kmk_cp kmk_echo kmk_mkdir kmk_rm kmk_install kmk_ln 92 else 93 PROGRAMS += kmk_append kmk_echo kmk_mkdir 94 endif 93 PROGRAMS += kmk_append kmk_cp kmk_echo kmk_mkdir kmk_install kmk_ln kmk_rm 95 94 96 95 kmk_append_TEMPLATE = BIN … … 99 98 kmk_append_SOURCES = \ 100 99 kmkbuiltin/append.c \ 100 kmkbuiltin/err.c 101 101 102 102 kmk_cp_TEMPLATE = BIN … … 105 105 kmkbuiltin/cp.c \ 106 106 kmkbuiltin/cp_utils.c \ 107 kmkbuiltin/strlcpy.c 107 kmkbuiltin/strlcpy.c \ 108 kmkbuiltin/err.c 109 kmk_cp_INCS.win32 = $(PATH_TARGET) . 110 kmk_cp_DEFS.win32 = HAVE_CONFIG_H 111 kmk_cp_SOURCES.win32 = \ 112 kmkbuiltin/mscfakes.c \ 113 kmkbuiltin/fts.c \ 114 w32/compat/dirent.c \ 115 getopt.c \ 116 getopt1.c 108 117 109 118 kmk_echo_TEMPLATE = BIN … … 111 120 kmk_echo_SOURCES = \ 112 121 kmkbuiltin/echo.c 122 kmk_echo_SOURCES.win32 = \ 123 kmkbuiltin/mscfakes.c \ 124 kmkbuiltin/err.c 113 125 114 126 kmk_install_TEMPLATE = BIN 115 127 kmk_install_DEFS = kmk_builtin_install=main 116 128 kmk_install_SOURCES = \ 117 kmkbuiltin/install.c 129 kmkbuiltin/install.c \ 130 kmkbuiltin/err.c \ 131 kmkbuiltin/strmode.c \ 132 kmkbuiltin/setmode.c 133 kmk_install_INCS.win32 = $(PATH_TARGET) . 134 kmk_install_DEFS.win32 = HAVE_CONFIG_H 135 kmk_install_SOURCES.win32 = \ 136 kmkbuiltin/mscfakes.c \ 137 getopt.c \ 138 getopt1.c 118 139 119 140 kmk_ln_TEMPLATE = BIN 120 141 kmk_ln_DEFS = kmk_builtin_ln=main 121 142 kmk_ln_SOURCES = \ 122 kmkbuiltin/ln.c 143 kmkbuiltin/ln.c \ 144 kmkbuiltin/err.c 145 kmk_ln_INCS.win32 = $(PATH_TARGET) . 146 kmk_ln_DEFS.win32 = HAVE_CONFIG_H 147 kmk_ln_SOURCES.win32 = \ 148 kmkbuiltin/mscfakes.c\ 149 getopt.c \ 150 getopt1.c 123 151 124 152 kmk_mkdir_TEMPLATE = BIN … … 126 154 kmk_mkdir_SOURCES = \ 127 155 kmkbuiltin/mkdir.c \ 156 kmkbuiltin/err.c \ 128 157 kmkbuiltin/setmode.c 129 158 kmk_mkdir_INCS.win32 = $(PATH_TARGET) . 130 159 kmk_mkdir_DEFS.win32 = HAVE_CONFIG_H 131 160 kmk_mkdir_SOURCES.win32 = \ 132 getopt.c \ 133 getopt1.c \ 161 kmkbuiltin/mscfakes.c \ 162 getopt.c \ 163 getopt1.c 134 164 135 165 kmk_rm_TEMPLATE = BIN … … 137 167 kmk_rm_SOURCES = \ 138 168 kmkbuiltin/rm.c \ 139 kmkbuiltin/ setmode.c \169 kmkbuiltin/err.c \ 140 170 kmkbuiltin/strmode.c 171 kmk_rm_INCS.win32 = $(PATH_TARGET) . 172 kmk_rm_DEFS.win32 = HAVE_CONFIG_H 173 kmk_rm_SOURCES.win32 = \ 174 kmkbuiltin/mscfakes.c\ 175 getopt.c \ 176 getopt1.c 141 177 142 178 -
trunk/src/gmake/kmkbuiltin.c
r368 r370 29 29 #include <stdio.h> 30 30 #include <ctype.h> 31 #include "kmkbuiltin/err.h" 31 32 #include "kmkbuiltin.h" 32 33 … … 178 179 if (!strcmp(pszCmd, "append")) 179 180 rc = kmk_builtin_append(argc, argv, environ); 180 #ifndef _MSC_VER181 else if (!strcmp(pszCmd, "cp"))182 rc = kmk_builtin_cp(argc, argv, environ);183 //else if (!strcmp(pszCmd, "chmod"))184 // rc = kmk_builtin_chmod(argc, argv, environ);185 #endif186 181 else if (!strcmp(pszCmd, "echo")) 187 182 rc = kmk_builtin_echo(argc, argv, environ); … … 192 187 else if (!strcmp(pszCmd, "mkdir")) 193 188 rc = kmk_builtin_mkdir(argc, argv, environ); 194 #ifndef _MSC_VER195 189 //else if (!strcmp(pszCmd, "mv")) 196 190 // rc = kmk_builtin_mv(argc, argv, environ); … … 199 193 //else if (!strcmp(pszCmd, "rmdir")) 200 194 // rc = kmk_builtin_rmdir(argc, argv, environ); 195 /* obsolete */ 196 #ifndef _MSC_VER 197 else if (!strcmp(pszCmd, "cp")) 198 rc = kmk_builtin_cp(argc, argv, environ); 201 199 #endif 202 200 else … … 205 203 return 1; 206 204 } 205 g_progname = "kmk"; /* paranoia, make sure it's not pointing at a freed argv[0]. */ 207 206 return rc; 208 207 } -
trunk/src/gmake/kmkbuiltin.h
r368 r370 30 30 extern int kmk_builtin_append(int argc, char **argv, char **envp); 31 31 extern int kmk_builtin_cp(int argc, char **argv, char **envp); 32 extern int kmk_builtin_chmod(int argc, char **argv, char **envp);33 32 extern int kmk_builtin_echo(int argc, char **argv, char **envp); 34 33 extern int kmk_builtin_install(int argc, char **argv, char **envp); -
trunk/src/gmake/kmkbuiltin/append.c
r348 r370 27 27 #include <string.h> 28 28 #include <stdio.h> 29 #include <errno.h>29 #include "err.h" 30 30 #include "kmkbuiltin.h" 31 31 … … 38 38 FILE *pFile; 39 39 40 g_progname = argv[0]; 41 40 42 /* 41 43 * Open the output file. … … 43 45 if (argc <= 1) 44 46 { 45 fprintf(stderr, "append: missing filename!\n");47 errx(1, "missing filename!"); 46 48 fprintf(stderr, "usage: append file [string ...]\n"); 47 49 return 1; … … 49 51 pFile = fopen(argv[1], "a"); 50 52 if (!pFile) 51 { 52 fprintf(stderr, "append: failed to open '%s': %s\n", argv[1], strerror(errno)); 53 return 1; 54 } 53 return err(1, "failed to open '%s'.", argv[1]); 55 54 56 55 /* … … 72 71 || ferror(pFile)) 73 72 { 74 fprintf(stderr, "append: error writing to '%s'!\n", argv[1]);75 73 fclose(pFile); 76 return 1;74 return errx(1, "error writing to '%s'!", argv[1]); 77 75 } 78 76 if (fclose(pFile)) 79 { 80 fprintf(stderr, "append: failed to fclose '%s': %s\n", argv[1], strerror(errno)); 81 return 1; 82 } 77 return err(1, "failed to fclose '%s'!", argv[1]); 83 78 return 0; 84 79 } -
trunk/src/gmake/kmkbuiltin/cp.c
r299 r370 41 41 static char sccsid[] = "@(#)cp.c 8.2 (Berkeley) 4/1/94"; 42 42 #endif /* not lint */ 43 #endif44 43 #include <sys/cdefs.h> 45 //__FBSDID("$FreeBSD: src/bin/cp/cp.c,v 1.50 2004/04/06 20:06:44 markm Exp $"); 44 __FBSDID("$FreeBSD: src/bin/cp/cp.c,v 1.50 2004/04/06 20:06:44 markm Exp $"); 45 #endif 46 46 47 47 /* … … 63 63 #include <sys/stat.h> 64 64 65 #include <err.h>65 #include "err.h" 66 66 #include <errno.h> 67 #ifdef DO_CP_TREE 67 68 #include <fts.h> 69 #endif 68 70 #include <limits.h> 69 71 #include <signal.h> … … 71 73 #include <stdlib.h> 72 74 #include <string.h> 75 #ifndef _MSC_VER 73 76 #include <unistd.h> 77 #else 78 #include "mscfakes.h" 79 #include "ftsfake.h" 80 #endif 74 81 75 82 #include "cp_extern.h" … … 103 110 104 111 int fflag, iflag, nflag, pflag, vflag; 105 int Rflag, rflag;112 static int Rflag, rflag; 106 113 volatile sig_atomic_t info; 107 114 … … 122 129 char *target; 123 130 124 argv0 = argv[0]; 131 /* init globals */ 132 cp_argv0 = argv[0]; 125 133 to.p_end = to.p_path; 126 134 to.target_end = emptystring; … … 128 136 fflag = iflag = nflag = pflag = vflag = Rflag = rflag = 0; 129 137 info = 0; 138 /* reset getopt and set progname. */ 139 g_progname = argv[0]; 130 140 opterr = 1; 131 141 optarg = NULL; … … 154 164 break; 155 165 case 'R': 166 #ifdef DO_CP_TREE 156 167 Rflag = 1; 157 168 break; 169 #else 170 return errx(1, "recursive copy is not implemented!"); 171 #endif 158 172 case 'f': 159 173 fflag = 1; … … 172 186 break; 173 187 case 'r': 188 #ifdef DO_CP_TREE 174 189 rflag = 1; 175 190 break; 191 #else 192 return errx(1, "recursive copy is not implemented!"); 193 #endif 176 194 case 'v': 177 195 vflag = 1; 178 196 break; 179 197 default: 180 usage(); 181 break; 198 return usage(); 182 199 } 183 200 argc -= optind; … … 185 202 186 203 if (argc < 2) 187 usage();204 return usage(); 188 205 189 206 fts_options = FTS_NOCHDIR | FTS_PHYSICAL; 190 207 if (rflag) { 191 if (Rflag) { 192 fprintf(stderr, 193 "%s: the -R and -r options may not be specified together.\n", argv0); 194 return 1; 195 } 196 if (Hflag || Lflag || Pflag) { 197 fprintf(stderr, "%s: the -H, -L, and -P options may not be specified with the -r option.\n", argv0); 198 return 1; 199 } 208 if (Rflag) 209 return errx(1, 210 "the -R and -r options may not be specified together."); 211 if (Hflag || Lflag || Pflag) 212 errx(1, 213 "the -H, -L, and -P options may not be specified with the -r option."); 214 #ifdef DO_CP_TREE 200 215 fts_options &= ~FTS_PHYSICAL; 201 216 fts_options |= FTS_LOGICAL; 217 #endif 202 218 } 219 #ifdef DO_CP_TREE 203 220 if (Rflag) { 204 221 if (Hflag) … … 208 225 fts_options |= FTS_LOGICAL; 209 226 } 210 } else { 227 } else 228 #endif 229 { 211 230 fts_options &= ~FTS_PHYSICAL; 212 231 fts_options |= FTS_LOGICAL | FTS_COMFOLLOW; … … 218 237 /* Save the target base in "to". */ 219 238 target = argv[--argc]; 220 if (strlcpy(to.p_path, target, sizeof(to.p_path)) >= sizeof(to.p_path)) { 221 fprintf(stderr, "%s: %s: name too long\n", argv0, target); 222 return 1; 223 } 239 if (strlcpy(to.p_path, target, sizeof(to.p_path)) >= sizeof(to.p_path)) 240 return errx(1, "%s: name too long", target); 224 241 to.p_end = to.p_path + strlen(to.p_path); 225 242 if (to.p_path == to.p_end) { … … 250 267 */ 251 268 r = stat(to.p_path, &to_stat); 252 if (r == -1 && errno != ENOENT) { 253 fprintf(stderr, "%s: %s: %s\n", argv0, to.p_path, strerror(errno)); 254 } 269 if (r == -1 && errno != ENOENT) 270 return err(1, "%s", to.p_path); 255 271 if (r == -1 || !S_ISDIR(to_stat.st_mode)) { 256 272 /* 257 273 * Case (1). Target is not a directory. 258 274 */ 259 if (argc > 1) { 260 usage(); 261 return 1; 262 } 275 if (argc > 1) 276 return usage(); 263 277 /* 264 278 * Need to detect the case: … … 283 297 if (have_trailing_slash && type == FILE_TO_FILE) { 284 298 if (r == -1) 285 fprintf(stderr, "%s: directory %s does not exist\n", argv0,286 to.p_path);299 return errx(1, "directory %s does not exist", 300 to.p_path); 287 301 else 288 fprintf(stderr, "%s: %s is not a directory\n", argv0, to.p_path); 289 return 1; 302 return errx(1, "%s is not a directory", to.p_path); 290 303 } 291 304 } else … … 316 329 umask(~mask); 317 330 318 if ((ftsp = fts_open(argv, fts_options, mastercmp)) == NULL) { 319 fprintf(stderr, "%s: fts_open: %s\n", argv0, strerror(errno)); 320 return 1; 321 } 331 if ((ftsp = fts_open(argv, fts_options, mastercmp)) == NULL) 332 return err(1, "fts_open"); 322 333 for (badcp = rval = 0; (curr = fts_read(ftsp)) != NULL; badcp = 0) { 323 334 switch (curr->fts_info) { … … 325 336 case FTS_DNR: 326 337 case FTS_ERR: 327 fprintf(stderr, "%s: %s: %s\n",328 argv0,curr->fts_path, strerror(curr->fts_errno));338 warnx("%s: %s", 339 curr->fts_path, strerror(curr->fts_errno)); 329 340 badcp = rval = 1; 330 341 continue; 331 342 case FTS_DC: /* Warn, continue. */ 332 fprintf(stderr, "%s: %s: directory causes a cycle\n", argv0, curr->fts_path);343 warnx("%s: directory causes a cycle", curr->fts_path); 333 344 badcp = rval = 1; 334 345 continue; … … 381 392 *target_mid = 0; 382 393 if (target_mid - to.p_path + nlen >= PATH_MAX) { 383 fprintf(stderr, "%s: %s%s: name too long (not copied)\n", argv0,394 warnx("%s%s: name too long (not copied)", 384 395 to.p_path, p); 385 396 badcp = rval = 1; … … 417 428 ((mode | S_IRWXU) & mask) != (mode & mask)) 418 429 if (chmod(to.p_path, mode & mask) != 0){ 419 fprintf(stderr, "%s: chmod: %s: %s\n", argv0, to.p_path, strerror(errno));430 warn("chmod: %s", to.p_path); 420 431 rval = 1; 421 432 } … … 429 440 else { 430 441 if (to_stat.st_dev == curr->fts_statp->st_dev && 431 to_stat.st_ino == curr->fts_statp->st_ino) { 432 fprintf(stderr, "%s: %s and %s are identical (not copied).\n", 433 argv0, to.p_path, curr->fts_path); 442 to_stat.st_dev != 0 && 443 to_stat.st_ino == curr->fts_statp->st_ino && 444 to_stat.st_ino != 0) { 445 warnx("%s and %s are identical (not copied).", 446 to.p_path, curr->fts_path); 434 447 badcp = rval = 1; 435 448 if (S_ISDIR(curr->fts_statp->st_mode)) … … 439 452 if (!S_ISDIR(curr->fts_statp->st_mode) && 440 453 S_ISDIR(to_stat.st_mode)) { 441 fprintf(stderr, 442 "%s: cannot overwrite directory %s with " 443 "non-directory %s\n", 444 argv0, to.p_path, curr->fts_path); 454 warnx("cannot overwrite directory %s with " 455 "non-directory %s", 456 to.p_path, curr->fts_path); 445 457 badcp = rval = 1; 446 458 continue; … … 450 462 451 463 switch (curr->fts_statp->st_mode & S_IFMT) { 464 #ifdef S_IFLNK 452 465 case S_IFLNK: 453 466 /* Catch special case of a non-dangling symlink */ … … 462 475 } 463 476 break; 477 #endif 464 478 case S_IFDIR: 465 479 if (!Rflag && !rflag) { 466 fprintf(stderr, "%s: %s is a directory (not copied).\n",467 argv0,curr->fts_path);480 warnx("%s is a directory (not copied).", 481 curr->fts_path); 468 482 (void)fts_set(ftsp, curr, FTS_SKIP); 469 483 badcp = rval = 1; … … 480 494 if (dne) { 481 495 if (mkdir(to.p_path, 482 curr->fts_statp->st_mode | S_IRWXU) < 0) { 483 fprintf(stderr, "%s: %s: %s\n", argv0, to.p_path, strerror(errno)); 484 return 1; 485 } 496 curr->fts_statp->st_mode | S_IRWXU) < 0) 497 return err(1, "%s", to.p_path); 486 498 } else if (!S_ISDIR(to_stat.st_mode)) { 487 499 errno = ENOTDIR; 488 fprintf(stderr, "%s: %s: %s\n", argv0, to.p_path, strerror(errno));500 return err(1, "%s", to.p_path); 489 501 } 490 502 /* … … 495 507 curr->fts_number = pflag || dne; 496 508 break; 509 #ifdef S_IFBLK 497 510 case S_IFBLK: 511 #endif 498 512 case S_IFCHR: 499 513 if (Rflag) { … … 505 519 } 506 520 break; 521 #ifdef S_IFIFO 507 522 case S_IFIFO: 523 #endif 508 524 if (Rflag) { 509 525 if (copy_fifo(curr->fts_statp, !dne)) … … 522 538 (void)printf("%s -> %s\n", curr->fts_path, to.p_path); 523 539 } 524 if (errno) { 525 fprintf(stderr, "%s: fts_read: %s\n", argv0, strerror(errno)); 526 } 540 if (errno) 541 return err(1, "fts_read"); 527 542 return (rval); 528 543 } -
trunk/src/gmake/kmkbuiltin/cp_extern.h
r229 r370 53 53 extern volatile sig_atomic_t info; 54 54 55 __BEGIN_DECLS56 55 int copy_fifo(struct stat *, int); 57 56 int copy_file(const FTSENT *, int); … … 59 58 int copy_special(struct stat *, int); 60 59 int setfile(struct stat *, int); 61 void usage(void); 62 __END_DECLS 60 int usage(void); -
trunk/src/gmake/kmkbuiltin/cp_utils.c
r347 r370 31 31 #if 0 32 32 static char sccsid[] = "@(#)utils.c 8.3 (Berkeley) 4/1/94"; 33 #include <sys/cdefs.h> 34 __FBSDID("$FreeBSD: src/bin/cp/utils.c,v 1.43 2004/04/06 20:06:44 markm Exp $"); 33 35 #endif 34 36 #endif /* not lint */ 35 #include <sys/cdefs.h> 36 //__FBSDID("$FreeBSD: src/bin/cp/utils.c,v 1.43 2004/04/06 20:06:44 markm Exp $"); 37 37 38 #ifndef _MSC_VER 38 39 #include <sys/param.h> 40 #endif 39 41 #include <sys/stat.h> 40 42 #ifdef VM_AND_BUFFER_CACHE_SYNCHRONIZED … … 42 44 #endif 43 45 44 #include <err.h>46 #include "err.h" 45 47 #include <errno.h> 46 48 #include <fcntl.h> 49 #ifndef _MSC_VER 47 50 #include <fts.h> 51 #endif 48 52 #include <limits.h> 49 53 #include <stdio.h> 50 54 #include <stdlib.h> 55 #include <signal.h> 56 #ifndef _MSC_VER 51 57 #include <sysexits.h> 52 58 #include <unistd.h> 53 #include <signal.h> 59 #else 60 #include "mscfakes.h" 61 #include "ftsfake.h" 62 #endif 54 63 55 64 #include "cp_extern.h" … … 57 66 58 67 #ifndef MAXBSIZE 59 # define MAXBSIZE (128*1024)68 # define MAXBSIZE 16384 60 69 #endif 61 70 #ifndef O_BINARY 62 71 # define O_BINARY 0 63 72 #endif 73 74 #ifndef S_ISVTX 75 # define S_ISVTX 0 76 #endif 64 77 65 78 int … … 78 91 79 92 if ((from_fd = open(entp->fts_path, O_RDONLY | O_BINARY, 0)) == -1) { 80 fprintf(stderr, "%s: %s: %s\n", argv0, entp->fts_path, strerror(errno));93 warn("%s", entp->fts_path); 81 94 return (1); 82 95 } … … 125 138 126 139 if (to_fd == -1) { 127 fprintf(stderr, "%s: %s: %s\n", argv0, to.p_path, strerror(errno));140 warn("%s", to.p_path); 128 141 (void)close(from_fd); 129 142 return (1); … … 142 155 if ((p = mmap(NULL, (size_t)fs->st_size, PROT_READ, 143 156 MAP_SHARED, from_fd, (off_t)0)) == MAP_FAILED) { 144 fprintf(stderr, "%s: %s: %s\n", argv0, entp->fts_path, strerror(errno));157 warn("%s", entp->fts_path); 145 158 rval = 1; 146 159 } else { … … 162 175 } 163 176 if (wcount != (ssize_t)wresid) { 164 fprintf(stderr, "%s: %s: %s\n", argv0, to.p_path, strerror(errno));177 warn("%s", to.p_path); 165 178 rval = 1; 166 179 } 167 180 /* Some systems don't unmap on close(2). */ 168 181 if (munmap(p, fs->st_size) < 0) { 169 fprintf(stderr, "%s: %s: %s\n", entp->fts_path, strerror(errno));182 warn("%s", entp->fts_path); 170 183 rval = 1; 171 184 } … … 192 205 } 193 206 if (wcount != (ssize_t)wresid) { 194 fprintf(stderr, "%s: %s: %s\n", argv0, to.p_path, strerror(errno));207 warn("%s", to.p_path); 195 208 rval = 1; 196 209 break; … … 198 211 } 199 212 if (rcount < 0) { 200 fprintf(stderr, "%s: %s: %s\n", argv0, entp->fts_path, strerror(errno));213 warn("%s", entp->fts_path); 201 214 rval = 1; 202 215 } … … 214 227 (void)close(from_fd); 215 228 if (close(to_fd)) { 216 fprintf(stderr, "%s: %s: %s\n", argv0, to.p_path, strerror(errno));229 warn("%s", to.p_path); 217 230 rval = 1; 218 231 } … … 227 240 228 241 if ((len = readlink(p->fts_path, llink, sizeof(llink) - 1)) == -1) { 229 fprintf(stderr, "%s: readlink: %s: %s\n", argv0, p->fts_path, strerror(errno));242 warn("readlink: %s", p->fts_path); 230 243 return (1); 231 244 } 232 245 llink[len] = '\0'; 233 246 if (exists && unlink(to.p_path)) { 234 fprintf(stderr, "%s: unlink: %s: %s\n", argv0, to.p_path, strerror(errno));247 warn("unlink: %s", to.p_path); 235 248 return (1); 236 249 } 237 250 if (symlink(llink, to.p_path)) { 238 fprintf(stderr, "%s: symlink: %s: %s\n", argv0, llink, strerror(errno));251 warn("symlink: %s", llink); 239 252 return (1); 240 253 } … … 246 259 { 247 260 if (exists && unlink(to.p_path)) { 248 fprintf(stderr, "%s: unlink: %s: %s\n", argv0, to.p_path, strerror(errno));261 warn("unlink: %s", to.p_path); 249 262 return (1); 250 263 } 251 264 if (mkfifo(to.p_path, from_stat->st_mode)) { 252 fprintf(stderr, "%s: mkfifo: %s\n", argv0, to.p_path, strerror(errno));265 warn("mkfifo: %s", to.p_path); 253 266 return (1); 254 267 } … … 260 273 { 261 274 if (exists && unlink(to.p_path)) { 262 fprintf(stderr, "%s: unlink: %s: %s\n", argv0, to.p_path, strerror(errno));275 warn("unlink: %s", to.p_path); 263 276 return (1); 264 277 } 265 278 if (mknod(to.p_path, from_stat->st_mode, from_stat->st_rdev)) { 266 fprintf(stderr, "%s: mknod: %s: %s\n", argv0, to.p_path, strerror(errno));279 warn("mknod: %s", to.p_path); 267 280 return (1); 268 281 } … … 292 305 #endif 293 306 if (islink ? lutimes(to.p_path, tv) : utimes(to.p_path, tv)) { 294 fprintf(stderr, "%s: %sutimes: %s: %s\n", argv0, islink ? "l" : "", to.p_path, strerror(errno));307 warn("%sutimes: %s", islink ? "l" : "", to.p_path); 295 308 rval = 1; 296 309 } … … 314 327 chown(to.p_path, fs->st_uid, fs->st_gid))) { 315 328 if (errno != EPERM) { 316 fprintf(stderr, "%s: chown: %s: %s\n", argv0, to.p_path, strerror(errno));329 warn("chown: %s", to.p_path); 317 330 rval = 1; 318 331 } … … 324 337 (islink ? lchmod(to.p_path, fs->st_mode) : 325 338 chmod(to.p_path, fs->st_mode))) { 326 fprintf(stderr, "%s: chmod: %s: %s\n", to.p_path, strerror(errno));339 warn("chmod: %s", to.p_path); 327 340 rval = 1; 328 341 } … … 334 347 (islink ? (errno = ENOSYS) : 335 348 chflags(to.p_path, fs->st_flags))) { 336 fprintf(stderr, "%s: chflags: %s: %s", argv0, to.p_path, strerror(errno));349 warn("chflags: %s", to.p_path); 337 350 rval = 1; 338 351 } … … 342 355 } 343 356 344 void 357 int 345 358 usage(void) 346 359 { … … 349 362 "usage: cp [-R [-H | -L | -P]] [-f | -i | -n] [-pv] src target", 350 363 " cp [-R [-H | -L | -P]] [-f | -i | -n] [-pv] src1 ... srcN directory"); 351 exit(EX_USAGE);352 } 364 return EX_USAGE; 365 } -
trunk/src/gmake/kmkbuiltin/echo.c
r360 r370 38 38 static char sccsid[] = "@(#)echo.c 8.1 (Berkeley) 5/31/93"; 39 39 #endif /* not lint */ 40 #include <sys/cdefs.h> 41 //__FBSDID("$FreeBSD: src/bin/echo/echo.c,v 1.17 2004/04/06 20:06:46 markm Exp $"); 40 42 #endif 41 #ifndef _MSC_VER42 #include <sys/cdefs.h>43 #endif44 //__FBSDID("$FreeBSD: src/bin/echo/echo.c,v 1.17 2004/04/06 20:06:46 markm Exp $");45 43 46 44 #include <sys/types.h> … … 57 55 #ifndef _MSC_VER 58 56 #include <unistd.h> 57 #else 58 #include "mscfakes.h" 59 59 #endif 60 60 … … 63 63 #endif 64 64 65 #ifdef _MSC_VER66 #include <io.h>67 68 struct iovec {69 char *iov_base;70 size_t iov_len;71 };72 73 int writev(int fd, const struct iovec *vector, int count)74 {75 int size = 0;76 int i;77 for (i = 0; i < count; i++)78 {79 int cb = write(fd, vector[i].iov_base, vector[i].iov_len);80 if (cb < 0)81 return -1;82 size += cb;83 }84 return size;85 }86 87 #define STDERR_FILENO 288 #define STDOUT_FILENO 189 #endif /* _MSC_VER */90 65 91 66 /* … … 127 102 if ((iovfree = vp = iov = malloc((veclen + 1) * sizeof(struct iovec))) == NULL) { 128 103 errexit(progname, "malloc"); 129 return 1;104 exit(1); 130 105 } 131 106 -
trunk/src/gmake/kmkbuiltin/install.c
r368 r370 42 42 static char sccsid[] = "@(#)xinstall.c 8.1 (Berkeley) 7/21/93"; 43 43 #endif /* not lint */ 44 #endif45 44 46 45 #include <sys/cdefs.h> 47 46 __FBSDID("$FreeBSD: src/usr.bin/xinstall/xinstall.c,v 1.66 2005/01/25 14:34:57 ssouhlal Exp $"); 48 47 #endif 48 49 #ifndef _MSC_VER 49 50 #include <sys/param.h> 51 #ifdef USE_MMAP 50 52 #include <sys/mman.h> 53 #endif 51 54 #include <sys/mount.h> 55 #include <sys/wait.h> 56 #include <sys/time.h> 57 #else 58 #include <process.h> 59 #endif 52 60 #include <sys/stat.h> 53 #include <sys/time.h>54 #include <sys/wait.h>55 61 56 62 #include <ctype.h> 57 #include <err.h>63 #include "err.h" 58 64 #include <errno.h> 59 65 #include <fcntl.h> 66 #ifndef _MSC_VER 60 67 #include <grp.h> 61 68 #include <paths.h> 62 69 #include <pwd.h> 70 #endif 63 71 #include <stdio.h> 64 72 #include <stdlib.h> 65 73 #include <string.h> 74 #ifndef _MSC_VER 66 75 #include <sysexits.h> 67 76 #include <unistd.h> 77 #else 78 #include "mscfakes.h" 79 #endif 80 81 extern void * setmode(const char *p); 82 extern mode_t getmode(const void *bbox, mode_t omode); 83 84 #ifndef __unused 85 # define __unused 86 #endif 87 88 #ifndef MAXBSIZE 89 # define MAXBSIZE 16384 90 #endif 68 91 69 92 /* Bootstrap aid - this doesn't exist in most older releases */ … … 83 106 #endif 84 107 85 static struct passwd *pp;86 static struct group *gp;87 108 static gid_t gid; 88 109 static uid_t uid; … … 91 112 static const char *suffix = BACKUP_SUFFIX; 92 113 93 static voidcopy(int, const char *, int, const char *, off_t);114 static int copy(int, const char *, int, const char *, off_t); 94 115 static int compare(int, const char *, size_t, int, const char *, size_t); 95 116 static int create_newfile(const char *, int, struct stat *); 96 117 static int create_tempfile(const char *, char *, size_t); 97 static voidinstall(const char *, const char *, u_long, u_int);98 static voidinstall_dir(char *);118 static int install(const char *, const char *, u_long, u_int); 119 static int install_dir(char *); 99 120 static u_long numeric_id(const char *, const char *); 100 static void strip(const char *); 121 static int strip(const char *); 122 #ifdef USE_MMAP 101 123 static int trymmap(int); 102 static void usage(void); 124 #endif 125 static int usage(void); 103 126 104 127 int … … 107 130 struct stat from_sb, to_sb; 108 131 mode_t *set; 109 u_long fset ;132 u_long fset = 0; 110 133 int ch, no_target; 111 134 u_int iflags; … … 132 155 dodir = 1; 133 156 break; 134 157 case 'f': 135 158 #ifdef UF_IMMUTABLE 136 159 flags = optarg; 137 160 if (strtofflags(&flags, &fset, NULL)) 138 errx(EX_USAGE, "%s: invalid flag", flags);161 return errx(EX_USAGE, "%s: invalid flag", flags); 139 162 iflags |= SETFLAGS; 163 #else 164 (void)flags; 140 165 #endif 141 166 break; … … 152 177 if (!(set = setmode(optarg))) 153 178 #endif 154 errx(EX_USAGE, "invalid file mode: %s",155 optarg);179 return errx(EX_USAGE, "invalid file mode: %s", 180 optarg); 156 181 mode = getmode(set, 0); 157 182 free(set); … … 174 199 case '?': 175 200 default: 176 usage();201 return usage(); 177 202 } 178 203 argc -= optind; … … 182 207 if (dostrip && dodir) { 183 208 warnx("-d and -s may not be specified together"); 184 usage();209 return usage(); 185 210 } 186 211 187 212 /* must have at least two arguments, except when creating directories */ 188 213 if (argc == 0 || (argc == 1 && !dodir)) 189 usage();214 return usage(); 190 215 191 216 /* need to make a temp copy so we can compare stripped version */ … … 195 220 /* get group and owner id's */ 196 221 if (group != NULL) { 222 #ifndef _MSC_VER 223 struct group *gp; 197 224 if ((gp = getgrnam(group)) != NULL) 198 225 gid = gp->gr_gid; 199 226 else 227 #endif 228 { 200 229 gid = (gid_t)numeric_id(group, "group"); 230 if (gid == (gid_t)-1) 231 return 1; 232 } 201 233 } else 202 234 gid = (gid_t)-1; 203 235 204 236 if (owner != NULL) { 237 #ifndef _MSC_VER 238 struct passwd *pp; 205 239 if ((pp = getpwnam(owner)) != NULL) 206 240 uid = pp->pw_uid; 207 241 else 242 #endif 243 { 208 244 uid = (uid_t)numeric_id(owner, "user"); 245 if (uid == (uid_t)-1) 246 return 1; 247 } 209 248 } else 210 249 uid = (uid_t)-1; 211 250 212 251 if (dodir) { 213 for (; *argv != NULL; ++argv) 214 install_dir(*argv); 215 exit(EX_OK); 252 for (; *argv != NULL; ++argv) { 253 int rc = install_dir(*argv); 254 if (rc) 255 return rc; 256 } 257 return EX_OK; 216 258 /* NOTREACHED */ 217 259 } … … 219 261 no_target = stat(to_name = argv[argc - 1], &to_sb); 220 262 if (!no_target && S_ISDIR(to_sb.st_mode)) { 221 for (; *argv != to_name; ++argv) 222 install(*argv, to_name, fset, iflags | DIRECTORY); 223 exit(EX_OK); 224 /* NOTREACHED */ 263 for (; *argv != to_name; ++argv) { 264 int rc = install(*argv, to_name, fset, iflags | DIRECTORY); 265 if (rc) 266 return rc; 267 } 268 return EX_OK; 225 269 } 226 270 … … 228 272 if (argc != 2) { 229 273 warnx("wrong number or types of arguments"); 230 usage();274 return usage(); 231 275 } 232 276 233 277 if (!no_target) { 234 278 if (stat(*argv, &from_sb)) 235 err(EX_OSERR, "%s", *argv);279 return err(EX_OSERR, "%s", *argv); 236 280 if (!S_ISREG(to_sb.st_mode)) { 237 281 errno = EFTYPE; 238 err(EX_OSERR, "%s", to_name);282 return err(EX_OSERR, "%s", to_name); 239 283 } 240 284 if (to_sb.st_dev == from_sb.st_dev && 241 to_sb.st_ino == from_sb.st_ino) 242 errx(EX_USAGE,243 "%s and %s are the same file", *argv, to_name);244 }245 install(*argv, to_name, fset, iflags);246 exit(EX_OK);247 /* NOTREACHED */248 } 249 250 u_long285 to_sb.st_dev != 0 && 286 to_sb.st_ino == from_sb.st_ino && 287 to_sb.st_ino != 0) 288 return errx(EX_USAGE, 289 "%s and %s are the same file", *argv, to_name); 290 } 291 return install(*argv, to_name, fset, iflags); 292 } 293 294 static u_long 251 295 numeric_id(const char *name, const char *type) 252 296 { … … 261 305 val = strtoul(name, &ep, 10); 262 306 if (errno) 263 err(EX_NOUSER, "%s", name);307 return err(-1, "%s", name); 264 308 if (*ep != '\0') 265 errx(EX_NOUSER, "unknown %s %s", type, name);309 return errx(-1, "unknown %s %s", type, name); 266 310 return (val); 267 311 } … … 271 315 * build a path name and install the file 272 316 */ 273 void 317 static int 274 318 install(const char *from_name, const char *to_name, u_long fset, u_int flags) 275 319 { … … 279 323 int tempcopy, temp_fd, to_fd; 280 324 char backup[MAXPATHLEN], *p, pathbuf[MAXPATHLEN], tempfile[MAXPATHLEN]; 325 int rc = EX_OK; 281 326 282 327 files_match = 0; 283 328 from_fd = -1; 284 329 to_fd = -1; 330 temp_fd = -1; 285 331 286 332 /* If try to install NULL file to a directory, fails. */ 287 if (flags & DIRECTORY || strcmp(from_name, _PATH_DEVNULL)) { 333 if (flags & DIRECTORY 334 #if defined(__EMX__) || defined(_MSC_VER) 335 || ( stricmp(from_name, _PATH_DEVNULL) 336 && stricmp(from_name, "nul") 337 #ifdef __EMX__ 338 && stricmp(from_name, "/dev/nul") 339 #endif 340 ) 341 #else 342 || strcmp(from_name, _PATH_DEVNULL) 343 #endif 344 ) { 288 345 if (stat(from_name, &from_sb)) 289 err(EX_OSERR, "%s", from_name);346 return err(EX_OSERR, "%s", from_name); 290 347 if (!S_ISREG(from_sb.st_mode)) { 291 348 errno = EFTYPE; 292 err(EX_OSERR, "%s", from_name);349 return err(EX_OSERR, "%s", from_name); 293 350 } 294 351 /* Build the target path. */ … … 310 367 errno = EFTYPE; 311 368 warn("%s", to_name); 312 return ;369 return EX_OK; 313 370 } 314 371 … … 317 374 318 375 if (!devnull && (from_fd = open(from_name, O_RDONLY | O_BINARY, 0)) < 0) 319 err(EX_OSERR, "%s", from_name);376 return err(EX_OSERR, "%s", from_name); 320 377 321 378 /* If we don't strip, we can compare first. */ 322 379 if (docompare && !dostrip && target) { 323 if ((to_fd = open(to_name, O_RDONLY | O_BINARY, 0)) < 0) 324 err(EX_OSERR, "%s", to_name); 380 if ((to_fd = open(to_name, O_RDONLY | O_BINARY, 0)) < 0) { 381 rc = err(EX_OSERR, "%s", to_name); 382 goto l_done; 383 } 325 384 if (devnull) 326 385 files_match = to_sb.st_size == 0; … … 331 390 332 391 /* Close "to" file unless we match. */ 333 if (!files_match) 392 if (!files_match) { 334 393 (void)close(to_fd); 394 to_fd = -1; 395 } 335 396 } 336 397 … … 339 400 to_fd = create_tempfile(to_name, tempfile, 340 401 sizeof(tempfile)); 341 if (to_fd < 0) 342 err(EX_OSERR, "%s", tempfile); 402 if (to_fd < 0) { 403 rc = err(EX_OSERR, "%s", tempfile); 404 goto l_done; 405 } 343 406 } else { 344 407 if ((to_fd = create_newfile(to_name, target, 345 &to_sb)) < 0) 346 err(EX_OSERR, "%s", to_name); 408 &to_sb)) < 0) { 409 rc = err(EX_OSERR, "%s", to_name); 410 goto l_done; 411 } 347 412 if (verbose) 348 413 (void)printf("install: %s -> %s\n", 349 414 from_name, to_name); 350 415 } 351 if (!devnull) 352 copy(from_fd, from_name, to_fd, 353 tempcopy ? tempfile : to_name, from_sb.st_size); 416 if (!devnull) { 417 rc = copy(from_fd, from_name, to_fd, 418 tempcopy ? tempfile : to_name, from_sb.st_size); 419 if (rc) 420 goto l_done; 421 } 354 422 } 355 423 356 424 if (dostrip) { 357 strip(tempcopy ? tempfile : to_name); 425 #if defined(__EMX__) || defined(_MSC_VER) 426 /* close before we strip. */ 427 close(to_fd); 428 to_fd = -1; 429 #endif 430 rc = strip(tempcopy ? tempfile : to_name); 431 if (rc) 432 goto l_done; 358 433 359 434 /* … … 361 436 * that does not work in-place -- like GNU binutils strip. 362 437 */ 438 #if !defined(__EMX__) && !defined(_MSC_VER) 363 439 close(to_fd); 440 #endif 364 441 to_fd = open(tempcopy ? tempfile : to_name, O_RDONLY | O_BINARY, 0); 365 if (to_fd < 0) 366 err(EX_OSERR, "stripping %s", to_name); 442 if (to_fd < 0) { 443 rc = err(EX_OSERR, "stripping %s", to_name); 444 goto l_done; 445 } 367 446 } 368 447 … … 374 453 375 454 /* Re-open to_fd using the real target name. */ 376 if ((to_fd = open(to_name, O_RDONLY | O_BINARY, 0)) < 0) 377 err(EX_OSERR, "%s", to_name); 455 if ((to_fd = open(to_name, O_RDONLY | O_BINARY, 0)) < 0) { 456 rc = err(EX_OSERR, "%s", to_name); 457 goto l_done; 458 } 378 459 379 460 if (fstat(temp_fd, &temp_sb)) { … … 381 462 (void)unlink(tempfile); 382 463 errno = serrno; 383 err(EX_OSERR, "%s", tempfile); 464 rc = err(EX_OSERR, "%s", tempfile); 465 goto l_done; 384 466 } 385 467 … … 391 473 * Need to preserve target file times, though. 392 474 */ 475 #if !defined(_MSC_VER) && !defined(__EMX__) 393 476 if (to_sb.st_nlink != 1) { 394 477 tvb[0].tv_sec = to_sb.st_atime; … … 397 480 tvb[1].tv_usec = 0; 398 481 (void)utimes(tempfile, tvb); 399 } else { 482 } else 483 #endif 484 { 485 400 486 files_match = 1; 401 487 (void)unlink(tempfile); 402 488 } 403 489 (void) close(temp_fd); 490 temp_fd = -1; 404 491 } 405 492 } … … 419 506 suffix) != strlen(to_name) + strlen(suffix)) { 420 507 unlink(tempfile); 421 errx(EX_OSERR, "%s: backup filename too long", 422 to_name); 508 rc = errx(EX_OSERR, "%s: backup filename too long", 509 to_name); 510 goto l_done; 423 511 } 424 512 if (verbose) … … 428 516 unlink(tempfile); 429 517 errno = serrno; 430 err(EX_OSERR, "rename: %s to %s", to_name, 431 backup); 518 rc = err(EX_OSERR, "rename: %s to %s", to_name, 519 backup); 520 goto l_done; 432 521 } 433 522 } … … 438 527 unlink(tempfile); 439 528 errno = serrno; 440 err(EX_OSERR, "rename: %s to %s", 441 tempfile, to_name); 529 rc = err(EX_OSERR, "rename: %s to %s", 530 tempfile, to_name); 531 goto l_done; 442 532 } 443 533 444 534 /* Re-open to_fd so we aren't hosed by the rename(2). */ 445 535 (void) close(to_fd); 446 if ((to_fd = open(to_name, O_RDONLY | O_BINARY, 0)) < 0) 447 err(EX_OSERR, "%s", to_name); 536 if ((to_fd = open(to_name, O_RDONLY | O_BINARY, 0)) < 0) { 537 rc = err(EX_OSERR, "%s", to_name); 538 goto l_done; 539 } 448 540 } 449 541 … … 463 555 (void)unlink(to_name); 464 556 errno = serrno; 465 err(EX_OSERR, "%s", to_name); 557 rc = err(EX_OSERR, "%s", to_name); 558 goto l_done; 466 559 } 467 560 … … 486 579 (void)unlink(to_name); 487 580 errno = serrno; 488 err(EX_OSERR,"%s: chown/chgrp", to_name); 581 rc = err(EX_OSERR,"%s: chown/chgrp", to_name); 582 goto l_done; 489 583 } 490 584 … … 494 588 (void)unlink(to_name); 495 589 errno = serrno; 496 err(EX_OSERR, "%s: chmod", to_name); 590 rc = err(EX_OSERR, "%s: chmod", to_name); 591 goto l_done; 497 592 } 498 593 … … 516 611 (void)unlink(to_name); 517 612 errno = serrno; 518 err(EX_OSERR, "%s: chflags", to_name); 519 } 520 } 521 } 522 #endif 523 524 (void)close(to_fd); 613 rc = err(EX_OSERR, "%s: chflags", to_name); 614 goto l_done; 615 } 616 } 617 } 618 #endif 619 620 l_done: 621 if (to_fd >= 0) 622 (void)close(to_fd); 623 if (temp_fd >= 0) 624 (void)close(temp_fd); 525 625 if (!devnull) 526 626 (void)close(from_fd); 627 return rc; 527 628 } 528 629 … … 531 632 * compare two files; non-zero means files differ 532 633 */ 533 int634 static int 534 635 compare(int from_fd, const char *from_name __unused, size_t from_len, 535 636 int to_fd, const char *to_name __unused, size_t to_len) … … 544 645 545 646 if (from_len <= MAX_CMP_SIZE) { 546 #if !defined(__EMX__) && !defined(_MSC_VER)647 #ifdef USE_MMAP 547 648 done_compare = 0; 548 649 if (trymmap(from_fd) && trymmap(to_fd)) { … … 561 662 done_compare = 1; 562 663 } 563 #endif564 664 out: 665 #else 666 (void)p; (void)q; 667 done_compare = 0; 668 #endif 565 669 if (!done_compare) { 566 670 char buf1[MAXBSIZE]; … … 637 741 if (dobackup) { 638 742 if ((size_t)snprintf(backup, MAXPATHLEN, "%s%s", 639 path, suffix) != strlen(path) + strlen(suffix)) 743 path, suffix) != strlen(path) + strlen(suffix)) { 640 744 errx(EX_OSERR, "%s: backup filename too long", 641 path); 745 path); 746 errno = ENAMETOOLONG; 747 return -1; 748 } 642 749 (void)snprintf(backup, MAXPATHLEN, "%s%s", 643 750 path, suffix); … … 645 752 (void)printf("install: %s -> %s\n", 646 753 path, backup); 647 if (rename(path, backup) < 0) 754 if (rename(path, backup) < 0) { 648 755 err(EX_OSERR, "rename: %s to %s", path, backup); 756 return -1; 757 } 649 758 } else 650 759 if (unlink(path) < 0) … … 662 771 * copy from one file to another 663 772 */ 664 void 773 static int 665 774 copy(int from_fd, const char *from_name, int to_fd, const char *to_name, 666 775 off_t size) … … 673 782 /* Rewind file descriptors. */ 674 783 if (lseek(from_fd, (off_t)0, SEEK_SET) == (off_t)-1) 675 err(EX_OSERR, "lseek: %s", from_name);784 return err(EX_OSERR, "lseek: %s", from_name); 676 785 if (lseek(to_fd, (off_t)0, SEEK_SET) == (off_t)-1) 677 err(EX_OSERR, "lseek: %s", to_name);786 return err(EX_OSERR, "lseek: %s", to_name); 678 787 679 788 /* … … 683 792 */ 684 793 done_copy = 0; 685 #if !defined(__EMX__) && !defined(_MSC_VER)794 #ifdef USE_MMAP 686 795 if (size <= 8 * 1048576 && trymmap(from_fd) && 687 796 (p = mmap(NULL, (size_t)size, PROT_READ, MAP_SHARED, … … 695 804 done_copy = 1; 696 805 } 806 #else 807 (void)p; 697 808 #endif 698 809 if (!done_copy) { … … 702 813 (void)unlink(to_name); 703 814 errno = nw > 0 ? EIO : serrno; 704 err(EX_OSERR, "%s", to_name);815 return err(EX_OSERR, "%s", to_name); 705 816 } 706 817 if (nr != 0) { … … 708 819 (void)unlink(to_name); 709 820 errno = serrno; 710 err(EX_OSERR, "%s", from_name); 711 } 712 } 821 return err(EX_OSERR, "%s", from_name); 822 } 823 } 824 return EX_OK; 713 825 } 714 826 … … 717 829 * use strip(1) to strip the target file 718 830 */ 719 void 831 static int 720 832 strip(const char *to_name) 721 833 { 834 #if defined(__EMX__) || defined(_MSC_VER) 835 const char *stripbin = getenv("STRIPBIN"); 836 if (stripbin == NULL) 837 stripbin = "strip"; 838 return spawnlp(P_WAIT, stripbin, stripbin, to_name, NULL); 839 #else 722 840 const char *stripbin; 723 841 int serrno, status; … … 743 861 } 744 862 } 863 #endif 745 864 } 746 865 … … 749 868 * build directory heirarchy 750 869 */ 751 void 870 static int 752 871 install_dir(char *path) 753 872 { … … 762 881 if (stat(path, &sb)) { 763 882 if (errno != ENOENT || mkdir(path, 0755) < 0) { 764 err(EX_OSERR, "mkdir %s", path);883 return err(EX_OSERR, "mkdir %s", path); 765 884 /* NOTREACHED */ 766 885 } else if (verbose) … … 768 887 path); 769 888 } else if (!S_ISDIR(sb.st_mode)) 770 errx(EX_OSERR, "%s exists but is not a directory", path);889 return errx(EX_OSERR, "%s exists but is not a directory", path); 771 890 if (!(*p = ch)) 772 891 break; … … 777 896 if (chmod(path, mode)) 778 897 warn("chmod %o %s", mode, path); 898 return EX_OK; 779 899 } 780 900 … … 783 903 * print a usage message and die 784 904 */ 785 void 905 static int 786 906 usage() 787 907 { … … 792 912 " [-o owner] file1 ... fileN directory\n" 793 913 " install -d [-v] [-g group] [-m mode] [-o owner] directory ...\n"); 794 exit(EX_USAGE);795 /* NOTREACHED */ 796 } 797 914 return EX_USAGE; 915 } 916 917 #ifdef USE_MMAP 798 918 /* 799 919 * trymmap -- 800 920 * return true (1) if mmap should be tried, false (0) if not. 801 921 */ 802 int922 static int 803 923 trymmap(int fd) 804 924 { … … 818 938 return (0); 819 939 } 940 #endif -
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 } -
trunk/src/gmake/kmkbuiltin/mkdir.c
r363 r370 38 38 static char sccsid[] = "@(#)mkdir.c 8.2 (Berkeley) 1/25/94"; 39 39 #endif /* not lint */ 40 #include <sys/cdefs.h> 41 __FBSDID("$FreeBSD: src/bin/mkdir/mkdir.c,v 1.28 2004/04/06 20:06:48 markm Exp $"); 40 42 #endif 41 #ifndef _MSC_VER42 #include <sys/cdefs.h>43 #endif44 //__FBSDID("$FreeBSD: src/bin/mkdir/mkdir.c,v 1.28 2004/04/06 20:06:48 markm Exp $");45 43 46 44 #include <sys/types.h> 47 45 #include <sys/stat.h> 48 46 49 //#include <err.h> 47 #include "err.h" 50 48 #include <errno.h> 51 49 #ifndef _MSC_VER … … 58 56 #include <sysexits.h> 59 57 #include <unistd.h> 60 #endif 61 62 #ifdef _MSC_VER 63 #define setmode setmode_msc 64 #include <stdarg.h> 65 #include <io.h> 66 #include <direct.h> 67 #undef setmode 68 #include "getopt.h" 69 70 typedef int mode_t; 71 #define EX_USAGE 1 72 void warn(const char *fmt, ...) 73 { 74 int err = errno; 75 va_list args; 76 va_start(args, fmt); 77 fprintf(stderr, "mkdir: "); 78 vfprintf(stderr, fmt, args); 79 fprintf(stderr, ": %s\n", strerror(err)); 80 va_end(args); 81 } 82 83 int mkdir_msc(const char *path, mode_t mode) 84 { 85 int rc = mkdir(path); 86 if (rc) 87 { 88 int len = strlen(path); 89 if (len > 0 && (path[len - 1] == '/' || path[len - 1] == '\\')) 90 { 91 char *str = strdup(path); 92 while (len > 0 && (str[len - 1] == '/' || str[len - 1] == '\\')) 93 str[--len] = '\0'; 94 rc = mkdir(str); 95 free(str); 96 } 97 } 98 return rc; 99 } 100 #define mkdir(a,b) mkdir_msc(a,b) 101 102 char *dirname(char *path) 103 { 104 return path; 105 } 106 107 #define S_ISDIR(m) (((m) & _S_IFMT) == _S_IFDIR) 108 #define S_IRWXG 0000070 109 #define S_IRWXO 0000007 110 #define S_IRWXU (_S_IREAD | _S_IWRITE | _S_IEXEC) 111 #define S_IXUSR _S_IEXEC 112 #define S_IWUSR _S_IWRITE 113 #define S_IRUSR _S_IREAD 114 58 #else 59 #include "mscfakes.h" 115 60 #endif 116 61 … … 133 78 mode = NULL; 134 79 vflag = 0; 80 /* kmk: reset getopt and set progname */ 81 g_progname = argv[0]; 135 82 opterr = 1; 136 83 optarg = NULL; … … 166 113 omode = S_IRWXU | S_IRWXG | S_IRWXO; 167 114 } else { 168 if ((set = setmode(mode)) == NULL) { 169 fprintf(stderr, "%s: invalid file mode: %s\n", mode, argv[0]); 170 return 1; 171 } 115 if ((set = setmode(mode)) == NULL) 116 return errx(1, "invalid file mode: %s", mode); 172 117 omode = getmode(set, S_IRWXU | S_IRWXG | S_IRWXO); 173 118 free(set); … … 181 126 } else if (mkdir(*argv, omode) < 0) { 182 127 if (errno == ENOTDIR || errno == ENOENT) 183 fprintf(stderr, "%s: %s: %s\n", argv[0], dirname(*argv), strerror(errno));128 warn("%s", dirname(*argv)); 184 129 else 185 fprintf(stderr, "%s: %s: %s\n", argv[0], *argv, strerror(errno));130 warn("%s", *argv); 186 131 success = 0; 187 132 } else if (vflag) … … 198 143 */ 199 144 if (success && mode != NULL && chmod(*argv, omode) == -1) { 200 fprintf(stderr, "%s: %s: %s\n", argv[0], *argv, strerror(errno));145 warn("%s", *argv); 201 146 exitval = 1; 202 147 } … … 240 185 continue; 241 186 *p = '\0'; 242 if ( p[1] == '\0')187 if (!last && p[1] == '\0') 243 188 last = 1; 244 189 if (first) { -
trunk/src/gmake/kmkbuiltin/rm.c
r341 r370 38 38 static char sccsid[] = "@(#)rm.c 8.5 (Berkeley) 4/18/94"; 39 39 #endif /* not lint */ 40 #endif41 40 #include <sys/cdefs.h> 42 41 //__FBSDID("$FreeBSD: src/bin/rm/rm.c,v 1.47 2004/04/06 20:06:50 markm Exp $"); 42 #endif 43 43 44 44 #include <sys/stat.h> 45 #ifndef _MSC_VER 45 46 #include <sys/param.h> 46 47 #include <sys/mount.h> 47 48 #include <err.h> 48 #endif 49 50 #include "err.h" 49 51 #include <errno.h> 50 52 #include <fcntl.h> 53 #ifdef DO_RMTREE 51 54 #include <fts.h> 55 #endif 56 #ifndef _MSC_VER 52 57 #include <grp.h> 53 58 #include <pwd.h> 59 #endif 54 60 #include <stdio.h> 55 61 #include <stdlib.h> 56 62 #include <string.h> 63 #ifndef _MSC_VER 57 64 #include <sysexits.h> 58 65 #include <unistd.h> 66 #else 67 #include "mscfakes.h" 68 #endif 59 69 60 70 #ifdef __EMX__ … … 81 91 static void rm_file(char **); 82 92 static int rm_overwrite(char *, struct stat *); 93 #ifdef DO_RMTREE 83 94 static void rm_tree(char **); 95 #endif 84 96 static int usage(void); 85 97 … … 100 112 dflag = eval = fflag = iflag = Pflag = vflag = Wflag = stdin_ok = 0; 101 113 uid = 0; 114 /* kmk: reset getopt and set program name. */ 115 g_progname = argv[0]; 102 116 opterr = 1; 103 117 optarg = NULL; … … 110 124 #endif 111 125 126 #if 0 /* kmk: we don't need this */ 112 127 /* 113 128 * Test for the special case where the utility is called as … … 129 144 return eval; 130 145 } 131 146 #else 147 (void)p; 148 #endif 132 149 Pflag = rflag = 0; 133 150 while ((ch = getopt(argc, argv, "dfiPRrvW")) != -1) … … 149 166 case 'R': 150 167 case 'r': /* Compatibility. */ 168 #ifdef DO_RMTREE 151 169 rflag = 1; 152 170 break; 171 #else 172 errno = EINVAL; 173 return err(1, "Recursion is not supported!"); 174 #endif 153 175 case 'v': 154 176 vflag = 1; … … 176 198 if (*argv) { 177 199 stdin_ok = isatty(STDIN_FILENO); 178 200 #ifdef DO_RMTREE 179 201 if (rflag) 180 202 rm_tree(argv); 181 203 else 204 #endif 182 205 rm_file(argv); 183 206 } … … 186 209 } 187 210 211 #ifdef DO_RMTREE 188 212 static void 189 213 rm_tree(char **argv) … … 214 238 flags |= FTS_WHITEOUT; 215 239 #endif 216 if (!(fts = fts_open(argv, flags, NULL))) 217 err(1, "fts_open"); 240 if (!(fts = fts_open(argv, flags, NULL))) { 241 eval = err(1, "fts_open"); 242 return; 243 } 218 244 while ((p = fts_read(fts)) != NULL) { 219 245 switch (p->fts_info) { … … 226 252 continue; 227 253 case FTS_ERR: 228 errx(1, "%s: %s", p->fts_path, strerror(p->fts_errno)); 254 eval = errx(1, "%s: %s", p->fts_path, strerror(p->fts_errno)); 255 return; 229 256 case FTS_NS: 230 257 /* … … 318 345 continue; 319 346 rval = unlink(p->fts_accpath); 347 #ifdef _MSC_VER 348 if (rval != 0) { 349 chmod(p->fts_accpath, 0777); 350 rval = unlink(p->fts_accpath); 351 } 352 #endif 353 320 354 if (rval == 0 || (fflag && errno == ENOENT)) { 321 355 if (rval == 0 && vflag) … … 335 369 } 336 370 } 371 #endif /* DO_RMTREE */ 337 372 338 373 static void … … 395 430 continue; 396 431 rval = unlink(f); 432 #ifdef _MSC_VER 433 if (rval != 0) { 434 chmod(f, 0777); 435 rval = unlink(f); 436 } 437 #endif 397 438 } 398 439 } … … 448 489 #endif 449 490 if ((buf = malloc(bsize)) == NULL) 450 e rr(1, "%s: malloc", file);491 exit(err(1, "%s: malloc", file)); 451 492 452 493 #define PASS(byte) { \ … … 512 553 #ifdef SF_APPEND 513 554 if ((flagsp = fflagstostr(sp->st_flags)) == NULL) 514 e rr(1, "fflagstostr");555 exit(err(1, "fflagstostr")); 515 556 (void)fprintf(stderr, "override %s%s%s/%s %s%sfor %s? ", 516 557 modep + 1, modep[9] == ' ' ? "" : " ", … … 521 562 free(flagsp); 522 563 #else 564 (void)flagsp; 523 565 (void)fprintf(stderr, "override %s%s %d/%d for %s? ", 524 566 modep + 1, modep[9] == ' ' ? "" : " ", -
trunk/src/gmake/kmkbuiltin/setmode.c
r361 r370 37 37 #if defined(LIBC_SCCS) && !defined(lint) 38 38 static char sccsid[] = "@(#)setmode.c 8.2 (Berkeley) 3/25/94"; 39 #include <sys/cdefs.h> 40 //__FBSDID("$FreeBSD: src/lib/libc/gen/setmode.c,v 1.9 2003/02/23 00:24:03 mikeh Exp $"); 39 41 #endif /* LIBC_SCCS and not lint */ 40 #ifndef _MSC_VER41 #include <sys/cdefs.h>42 #endif43 //__FBSDID("$FreeBSD: src/lib/libc/gen/setmode.c,v 1.9 2003/02/23 00:24:03 mikeh Exp $");44 42 45 43 //#include "namespace.h" … … 53 51 #ifndef _MSC_VER 54 52 #include <unistd.h> 53 #else 54 #include "mscfakes.h" 55 55 #endif 56 56 … … 59 59 #endif 60 60 //#include "un-namespace.h" 61 62 #ifdef _MSC_VER63 #define setmode setmode_msc64 #include <io.h>65 #undef setmode66 typedef unsigned int u_int;67 typedef int mode_t;68 #define S_ISDIR(m) (((m) & _S_IFMT) == _S_IFDIR)69 #define S_IRWXU (_S_IREAD | _S_IWRITE | _S_IEXEC)70 #define S_IXUSR _S_IEXEC71 #define S_IWUSR _S_IWRITE72 #define S_IRUSR _S_IREAD73 #define S_IRWXG 000007074 #define S_IRGRP 000004075 #define S_IWGRP 000002076 #define S_IXGRP 000001077 #define S_IRWXO 000000778 #define S_IROTH 000000479 #define S_IWOTH 000000280 #define S_IXOTH 000000181 #define S_ISUID 000400082 #define S_ISGID 000200083 #endif /* _MSC_VER */84 85 61 86 62 #define SET_LEN 6 /* initial # of bitcmd struct to malloc */ -
trunk/src/gmake/kmkbuiltin/strlcpy.c
r229 r370 30 30 #if defined(LIBC_SCCS) && !defined(lint) 31 31 static char *rcsid = "$OpenBSD: strlcpy.c,v 1.4 1999/05/01 18:56:41 millert Exp $"); 32 #endif /* LIBC_SCCS and not lint */33 32 #include <sys/cdefs.h> 34 33 //__FBSDID("$FreeBSD: src/lib/libc/string/strlcpy.c,v 1.7 2003/05/01 19:03:14 nectar Exp $"); 34 #endif /* LIBC_SCCS and not lint */ 35 35 36 36 #include <sys/types.h> -
trunk/src/gmake/kmkbuiltin/strmode.c
r228 r370 34 34 #if defined(LIBC_SCCS) && !defined(lint) 35 35 static char sccsid[] = "@(#)strmode.c 8.3 (Berkeley) 8/15/94"; 36 #endif /* LIBC_SCCS and not lint */37 36 #include <sys/cdefs.h> 38 37 //__FBSDID("$FreeBSD: src/lib/libc/string/strmode.c,v 1.4 2002/03/21 18:44:54 obrien Exp $"); 38 #endif /* LIBC_SCCS and not lint */ 39 39 40 40 41 #include <sys/types.h> 41 42 #include <sys/stat.h> 42 43 #include <string.h> 44 #ifdef _MSC_VER 45 #include "mscfakes.h" 46 #endif 43 47 44 48 void … … 55 59 *p++ = 'c'; 56 60 break; 61 #ifdef S_IFBLK 57 62 case S_IFBLK: /* block special */ 58 63 *p++ = 'b'; 59 64 break; 65 #endif 60 66 case S_IFREG: /* regular */ 61 67 *p++ = '-'; 62 68 break; 69 #ifndef _MSC_VER 63 70 case S_IFLNK: /* symbolic link */ 64 71 *p++ = 'l'; 65 72 break; 73 #endif 74 #ifdef S_IFSOCK 66 75 case S_IFSOCK: /* socket */ 67 76 *p++ = 's'; 68 77 break; 78 #endif 69 79 #ifdef S_IFIFO 70 80 case S_IFIFO: /* fifo */ … … 136 146 else 137 147 *p++ = '-'; 148 #ifdef S_ISVTX 138 149 switch (mode & (S_IXOTH | S_ISVTX)) { 150 #else 151 switch (mode & (S_IXOTH)) { 152 #endif 139 153 case 0: 140 154 *p++ = '-'; … … 143 157 *p++ = 'x'; 144 158 break; 159 #ifdef S_ISVTX 145 160 case S_ISVTX: 146 161 *p++ = 'T'; … … 149 164 *p++ = 't'; 150 165 break; 166 #endif 151 167 } 152 168 *p++ = ' '; /* will be a '+' if ACL's implemented */ -
trunk/src/gmake/variable.c
r368 r370 685 685 #ifdef CONFIG_WITH_KMK_BUILTIN 686 686 /* The supported kMk Builtin commands. */ 687 #ifdef _MSC_VER688 (void) define_variable ("KMK_BUILTIN", 11, "append echo mkdir", o_default, 0);689 #else690 687 (void) define_variable ("KMK_BUILTIN", 11, "append cp echo install ln mkdir rm", o_default, 0); 691 #endif692 688 #endif 693 689
Note:
See TracChangeset
for help on using the changeset viewer.