- Timestamp:
- Dec 17, 2005 5:31:29 AM (19 years ago)
- Location:
- trunk/src/gmake
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/gmake/Makefile.kmk
r362 r368 77 77 kmkbuiltin/cp.c \ 78 78 kmkbuiltin/cp_utils.c \ 79 kmkbuiltin/ln.c \ 80 kmkbuiltin/install.c \ 79 81 \ 80 82 kmkbuiltin/strmode.c \ … … 87 89 # 88 90 ifneq ($(BUILD_TARGET),win32) 89 PROGRAMS += kmk_append kmk_cp kmk_echo kmk_mkdir kmk_rm 91 PROGRAMS += kmk_append kmk_cp kmk_echo kmk_mkdir kmk_rm kmk_install kmk_ln 90 92 else 91 93 PROGRAMS += kmk_append kmk_echo kmk_mkdir … … 109 111 kmk_echo_SOURCES = \ 110 112 kmkbuiltin/echo.c 113 114 kmk_install_TEMPLATE = BIN 115 kmk_install_DEFS = kmk_builtin_install=main 116 kmk_install_SOURCES = \ 117 kmkbuiltin/install.c 118 119 kmk_ln_TEMPLATE = BIN 120 kmk_ln_DEFS = kmk_builtin_ln=main 121 kmk_ln_SOURCES = \ 122 kmkbuiltin/ln.c 111 123 112 124 kmk_mkdir_TEMPLATE = BIN -
trunk/src/gmake/kmkbuiltin.c
r362 r368 32 32 33 33 extern char **environ; 34 35 extern int kmk_builtin_append(int argc, char **argv, char **envp);36 extern int kmk_builtin_cp(int argc, char **argv, char **envp);37 extern int kmk_builtin_chmod(int argc, char **argv, char **envp);38 extern int kmk_builtin_echo(int argc, char **argv, char **envp);39 extern int kmk_builtin_mkdir(int argc, char **argv, char **envp);40 extern int kmk_builtin_mv(int argc, char **argv, char **envp);41 extern int kmk_builtin_rm(int argc, char **argv, char **envp);42 extern int kmk_builtin_rmdir(int argc, char **argv, char **envp);43 34 44 35 int kmk_builtin_command(const char *pszCmd) … … 195 186 else if (!strcmp(pszCmd, "echo")) 196 187 rc = kmk_builtin_echo(argc, argv, environ); 188 else if (!strcmp(pszCmd, "install")) 189 rc = kmk_builtin_install(argc, argv, environ); 190 else if (!strcmp(pszCmd, "ln")) 191 rc = kmk_builtin_ln(argc, argv, environ); 197 192 else if (!strcmp(pszCmd, "mkdir")) 198 193 rc = kmk_builtin_mkdir(argc, argv, environ); -
trunk/src/gmake/kmkbuiltin.h
r348 r368 32 32 extern int kmk_builtin_chmod(int argc, char **argv, char **envp); 33 33 extern int kmk_builtin_echo(int argc, char **argv, char **envp); 34 extern int kmk_builtin_install(int argc, char **argv, char **envp); 35 extern int kmk_builtin_ln(int argc, char **argv, char **envp); 34 36 extern int kmk_builtin_mkdir(int argc, char **argv, char **envp); 35 37 extern int kmk_builtin_mv(int argc, char **argv, char **envp); -
trunk/src/gmake/kmkbuiltin/install.c
r367 r368 79 79 #define BACKUP_SUFFIX ".old" 80 80 81 struct passwd *pp; 82 struct group *gp; 83 gid_t gid; 84 uid_t uid; 85 int dobackup, docompare, dodir, dopreserve, dostrip, nommap, safecopy, verbose; 86 mode_t mode = S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH; 87 const char *suffix = BACKUP_SUFFIX; 88 89 void copy(int, const char *, int, const char *, off_t); 90 int compare(int, const char *, size_t, int, const char *, size_t); 91 int create_newfile(const char *, int, struct stat *); 92 int create_tempfile(const char *, char *, size_t); 93 void install(const char *, const char *, u_long, u_int); 94 void install_dir(char *); 95 u_long numeric_id(const char *, const char *); 96 void strip(const char *); 97 int trymmap(int); 98 void usage(void); 81 #ifndef O_BINARY 82 # define O_BINARY 0 83 #endif 84 85 static struct passwd *pp; 86 static struct group *gp; 87 static gid_t gid; 88 static uid_t uid; 89 static int dobackup, docompare, dodir, dopreserve, dostrip, nommap, safecopy, verbose; 90 static mode_t mode = S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH; 91 static const char *suffix = BACKUP_SUFFIX; 92 93 static void copy(int, const char *, int, const char *, off_t); 94 static int compare(int, const char *, size_t, int, const char *, size_t); 95 static int create_newfile(const char *, int, struct stat *); 96 static int create_tempfile(const char *, char *, size_t); 97 static void install(const char *, const char *, u_long, u_int); 98 static void install_dir(char *); 99 static u_long numeric_id(const char *, const char *); 100 static void strip(const char *); 101 static int trymmap(int); 102 static void usage(void); 99 103 100 104 int 101 main(int argc, char *argv[])105 kmk_builtin_install(int argc, char *argv[]) 102 106 { 103 107 struct stat from_sb, to_sb; … … 128 132 dodir = 1; 129 133 break; 130 case 'f': 134 case 'f': 135 #ifdef UF_IMMUTABLE 131 136 flags = optarg; 132 137 if (strtofflags(&flags, &fset, NULL)) 133 138 errx(EX_USAGE, "%s: invalid flag", flags); 134 139 iflags |= SETFLAGS; 140 #endif 135 141 break; 136 142 case 'g': … … 140 146 nommap = 1; 141 147 break; 142 case 'm': 148 case 'm': 149 #ifdef __EMX__ 150 if (!(set = bsd_setmode(optarg))) 151 #else 143 152 if (!(set = setmode(optarg))) 153 #endif 144 154 errx(EX_USAGE, "invalid file mode: %s", 145 155 optarg); … … 230 240 if (to_sb.st_dev == from_sb.st_dev && 231 241 to_sb.st_ino == from_sb.st_ino) 232 errx(EX_USAGE, 242 errx(EX_USAGE, 233 243 "%s and %s are the same file", *argv, to_name); 234 244 } … … 306 316 tempcopy = safecopy && target; 307 317 308 if (!devnull && (from_fd = open(from_name, O_RDONLY , 0)) < 0)318 if (!devnull && (from_fd = open(from_name, O_RDONLY | O_BINARY, 0)) < 0) 309 319 err(EX_OSERR, "%s", from_name); 310 320 311 321 /* If we don't strip, we can compare first. */ 312 322 if (docompare && !dostrip && target) { 313 if ((to_fd = open(to_name, O_RDONLY , 0)) < 0)323 if ((to_fd = open(to_name, O_RDONLY | O_BINARY, 0)) < 0) 314 324 err(EX_OSERR, "%s", to_name); 315 325 if (devnull) … … 352 362 */ 353 363 close(to_fd); 354 to_fd = open(tempcopy ? tempfile : to_name, O_RDONLY , 0);364 to_fd = open(tempcopy ? tempfile : to_name, O_RDONLY | O_BINARY, 0); 355 365 if (to_fd < 0) 356 366 err(EX_OSERR, "stripping %s", to_name); … … 364 374 365 375 /* Re-open to_fd using the real target name. */ 366 if ((to_fd = open(to_name, O_RDONLY , 0)) < 0)376 if ((to_fd = open(to_name, O_RDONLY | O_BINARY, 0)) < 0) 367 377 err(EX_OSERR, "%s", to_name); 368 378 … … 400 410 */ 401 411 if (tempcopy && !files_match) { 412 #ifdef UF_IMMUTABLE 402 413 /* Try to turn off the immutable bits. */ 403 414 if (to_sb.st_flags & NOCHANGEBITS) 404 415 (void)chflags(to_name, to_sb.st_flags & ~NOCHANGEBITS); 416 #endif 405 417 if (dobackup) { 406 418 if ((size_t)snprintf(backup, MAXPATHLEN, "%s%s", to_name, … … 432 444 /* Re-open to_fd so we aren't hosed by the rename(2). */ 433 445 (void) close(to_fd); 434 if ((to_fd = open(to_name, O_RDONLY , 0)) < 0)446 if ((to_fd = open(to_name, O_RDONLY | O_BINARY, 0)) < 0) 435 447 err(EX_OSERR, "%s", to_name); 436 448 } … … 458 470 * chown may lose the setuid bits. 459 471 */ 472 #ifdef UF_IMMUTABLE 460 473 if ((gid != (gid_t)-1 && gid != to_sb.st_gid) || 461 474 (uid != (uid_t)-1 && uid != to_sb.st_uid) || … … 465 478 (void)fchflags(to_fd, to_sb.st_flags & ~NOCHANGEBITS); 466 479 } 480 #endif 467 481 468 482 if ((gid != (gid_t)-1 && gid != to_sb.st_gid) || … … 490 504 * then warn if the the fs doesn't support it, otherwise fail. 491 505 */ 506 #ifdef UF_IMMUTABLE 492 507 if (!devnull && (flags & SETFLAGS || 493 508 (from_sb.st_flags & ~UF_NODUMP) != to_sb.st_flags) && … … 505 520 } 506 521 } 522 #endif 507 523 508 524 (void)close(to_fd); … … 528 544 529 545 if (from_len <= MAX_CMP_SIZE) { 546 #if !defined(__EMX__) && !defined(_MSC_VER) 530 547 done_compare = 0; 531 548 if (trymmap(from_fd) && trymmap(to_fd)) { … … 544 561 done_compare = 1; 545 562 } 563 #endif 546 564 out: 547 565 if (!done_compare) { … … 612 630 * it might work. 613 631 */ 632 #ifdef UF_IMMUTABLE 614 633 if (sbp->st_flags & NOCHANGEBITS) 615 634 (void)chflags(path, sbp->st_flags & ~NOCHANGEBITS); 635 #endif 616 636 617 637 if (dobackup) { … … 632 652 } 633 653 634 newfd = open(path, O_CREAT | O_RDWR | O_TRUNC , S_IRUSR | S_IWUSR);654 newfd = open(path, O_CREAT | O_RDWR | O_TRUNC | O_BINARY, S_IRUSR | S_IWUSR); 635 655 if (newfd < 0 && saved_errno != 0) 636 656 errno = saved_errno; … … 663 683 */ 664 684 done_copy = 0; 685 #if !defined(__EMX__) && !defined(_MSC_VER) 665 686 if (size <= 8 * 1048576 && trymmap(from_fd) && 666 687 (p = mmap(NULL, (size_t)size, PROT_READ, MAP_SHARED, … … 674 695 done_copy = 1; 675 696 } 697 #endif 676 698 if (!done_copy) { 677 699 while ((nr = read(from_fd, buf, sizeof(buf))) > 0) -
trunk/src/gmake/kmkbuiltin/ln.c
r367 r368 53 53 #include <unistd.h> 54 54 55 int fflag; /* Unlink existing files. */56 int hflag; /* Check new name for symlink first. */57 int iflag; /* Interactive mode. */58 int sflag; /* Symbolic, not hard, link. */59 int vflag; /* Verbose output. */55 static int fflag; /* Unlink existing files. */ 56 static int hflag; /* Check new name for symlink first. */ 57 static int iflag; /* Interactive mode. */ 58 static int sflag; /* Symbolic, not hard, link. */ 59 static int vflag; /* Verbose output. */ 60 60 /* System link call. */ 61 int (*linkf)(const char *, const char *);62 char linkch;63 64 int linkit(const char *, const char *, int);65 void usage(void);61 static int (*linkf)(const char *, const char *); 62 static char linkch; 63 64 static int linkit(const char *, const char *, int); 65 static void usage(void); 66 66 67 67 int 68 main(int argc, char *argv[])68 kmk_builtin_ln(int argc, char *argv[]) 69 69 { 70 70 struct stat sb; -
trunk/src/gmake/variable.c
r362 r368 688 688 (void) define_variable ("KMK_BUILTIN", 11, "append echo mkdir", o_default, 0); 689 689 #else 690 (void) define_variable ("KMK_BUILTIN", 11, "append cp echo mkdir rm", o_default, 0);691 #endif 690 (void) define_variable ("KMK_BUILTIN", 11, "append cp echo install ln mkdir rm", o_default, 0); 691 #endif 692 692 #endif 693 693
Note:
See TracChangeset
for help on using the changeset viewer.