mv.c (226961) | mv.c (239951) |
---|---|
1/*- 2 * Copyright (c) 1989, 1993, 1994 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Ken Smith of The State University of New York at Buffalo. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 28 unchanged lines hidden (view full) --- 37 The Regents of the University of California. All rights reserved.\n"; 38#endif /* not lint */ 39 40#ifndef lint 41static char sccsid[] = "@(#)mv.c 8.2 (Berkeley) 4/2/94"; 42#endif /* not lint */ 43#endif 44#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 1989, 1993, 1994 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Ken Smith of The State University of New York at Buffalo. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 28 unchanged lines hidden (view full) --- 37 The Regents of the University of California. All rights reserved.\n"; 38#endif /* not lint */ 39 40#ifndef lint 41static char sccsid[] = "@(#)mv.c 8.2 (Berkeley) 4/2/94"; 42#endif /* not lint */ 43#endif 44#include <sys/cdefs.h> |
45__FBSDID("$FreeBSD: head/bin/mv/mv.c 226961 2011-10-31 08:59:17Z ed $"); | 45__FBSDID("$FreeBSD: head/bin/mv/mv.c 239951 2012-08-31 14:35:01Z jhb $"); |
46 47#include <sys/types.h> 48#include <sys/acl.h> 49#include <sys/param.h> 50#include <sys/time.h> 51#include <sys/wait.h> 52#include <sys/stat.h> 53#include <sys/mount.h> --- 9 unchanged lines hidden (view full) --- 63#include <stdlib.h> 64#include <string.h> 65#include <sysexits.h> 66#include <unistd.h> 67 68/* Exit code for a failed exec. */ 69#define EXEC_FAILED 127 70 | 46 47#include <sys/types.h> 48#include <sys/acl.h> 49#include <sys/param.h> 50#include <sys/time.h> 51#include <sys/wait.h> 52#include <sys/stat.h> 53#include <sys/mount.h> --- 9 unchanged lines hidden (view full) --- 63#include <stdlib.h> 64#include <string.h> 65#include <sysexits.h> 66#include <unistd.h> 67 68/* Exit code for a failed exec. */ 69#define EXEC_FAILED 127 70 |
71static int fflg, iflg, nflg, vflg; | 71static int fflg, hflg, iflg, nflg, vflg; |
72 73static int copy(const char *, const char *); 74static int do_move(const char *, const char *); 75static int fastcopy(const char *, const char *, struct stat *); 76static void usage(void); 77static void preserve_fd_acls(int source_fd, int dest_fd, const char *source_path, 78 const char *dest_path); 79 80int 81main(int argc, char *argv[]) 82{ 83 size_t baselen, len; 84 int rval; 85 char *p, *endp; 86 struct stat sb; 87 int ch; 88 char path[PATH_MAX]; 89 | 72 73static int copy(const char *, const char *); 74static int do_move(const char *, const char *); 75static int fastcopy(const char *, const char *, struct stat *); 76static void usage(void); 77static void preserve_fd_acls(int source_fd, int dest_fd, const char *source_path, 78 const char *dest_path); 79 80int 81main(int argc, char *argv[]) 82{ 83 size_t baselen, len; 84 int rval; 85 char *p, *endp; 86 struct stat sb; 87 int ch; 88 char path[PATH_MAX]; 89 |
90 while ((ch = getopt(argc, argv, "finv")) != -1) | 90 while ((ch = getopt(argc, argv, "fhinv")) != -1) |
91 switch (ch) { | 91 switch (ch) { |
92 case 'h': 93 hflg = 1; 94 break; |
|
92 case 'i': 93 iflg = 1; 94 fflg = nflg = 0; 95 break; 96 case 'f': 97 fflg = 1; 98 iflg = nflg = 0; 99 break; --- 18 unchanged lines hidden (view full) --- 118 * try the move. More than 2 arguments is an error in this case. 119 */ 120 if (stat(argv[argc - 1], &sb) || !S_ISDIR(sb.st_mode)) { 121 if (argc > 2) 122 usage(); 123 exit(do_move(argv[0], argv[1])); 124 } 125 | 95 case 'i': 96 iflg = 1; 97 fflg = nflg = 0; 98 break; 99 case 'f': 100 fflg = 1; 101 iflg = nflg = 0; 102 break; --- 18 unchanged lines hidden (view full) --- 121 * try the move. More than 2 arguments is an error in this case. 122 */ 123 if (stat(argv[argc - 1], &sb) || !S_ISDIR(sb.st_mode)) { 124 if (argc > 2) 125 usage(); 126 exit(do_move(argv[0], argv[1])); 127 } 128 |
129 /* 130 * If -h was specified, treat the target as a symlink instead of 131 * directory. 132 */ 133 if (hflg) { 134 if (argc > 2) 135 usage(); 136 if (lstat(argv[1], &sb) == 0 && S_ISLNK(sb.st_mode)) 137 exit(do_move(argv[0], argv[1])); 138 } 139 |
|
126 /* It's a directory, move each file into it. */ 127 if (strlen(argv[argc - 1]) > sizeof(path) - 1) 128 errx(1, "%s: destination pathname too long", *argv); 129 (void)strcpy(path, argv[argc - 1]); 130 baselen = strlen(path); 131 endp = &path[baselen]; 132 if (!baselen || *(endp - 1) != '/') { 133 *endp++ = '/'; --- 344 unchanged lines hidden (view full) --- 478 acl_free(acl); 479} 480 481static void 482usage(void) 483{ 484 485 (void)fprintf(stderr, "%s\n%s\n", | 140 /* It's a directory, move each file into it. */ 141 if (strlen(argv[argc - 1]) > sizeof(path) - 1) 142 errx(1, "%s: destination pathname too long", *argv); 143 (void)strcpy(path, argv[argc - 1]); 144 baselen = strlen(path); 145 endp = &path[baselen]; 146 if (!baselen || *(endp - 1) != '/') { 147 *endp++ = '/'; --- 344 unchanged lines hidden (view full) --- 492 acl_free(acl); 493} 494 495static void 496usage(void) 497{ 498 499 (void)fprintf(stderr, "%s\n%s\n", |
486 "usage: mv [-f | -i | -n] [-v] source target", | 500 "usage: mv [-f | -i | -n] [-hv] source target", |
487 " mv [-f | -i | -n] [-v] source ... directory"); 488 exit(EX_USAGE); 489} | 501 " mv [-f | -i | -n] [-v] source ... directory"); 502 exit(EX_USAGE); 503} |