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 --- 19 unchanged lines hidden (view full) --- 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34 * SUCH DAMAGE. 35 * |
36 * $Id: mv.c,v 1.7 1996/02/20 23:27:57 wosch Exp $ |
37 */ 38 39#ifndef lint 40static char copyright[] = 41"@(#) Copyright (c) 1989, 1993, 1994\n\ 42 The Regents of the University of California. All rights reserved.\n"; 43#endif /* not lint */ 44 --- 29 unchanged lines hidden (view full) --- 74 char *argv[]; 75{ 76 register int baselen, len, rval; 77 register char *p, *endp; 78 struct stat sb; 79 int ch; 80 char path[MAXPATHLEN + 1]; 81 |
82 while ((ch = getopt(argc, argv, "fi")) != EOF) |
83 switch (ch) { 84 case 'i': 85 iflg = 1; 86 fflg = 0; 87 break; 88 case 'f': 89 fflg = 1; 90 iflg = 0; 91 break; 92 default: 93 usage(); 94 } |
95 argc -= optind; |
96 argv += optind; 97 98 if (argc < 2) 99 usage(); 100 101 /* 102 * If the stat on the target fails or the target isn't a directory, 103 * try the move. More than 2 arguments is an error in this case. --- 45 unchanged lines hidden (view full) --- 149 * Check access. If interactive and file exists, ask user if it 150 * should be replaced. Otherwise if file exists but isn't writable 151 * make sure the user wants to clobber it. 152 */ 153 if (!fflg && !access(to, F_OK)) { 154 155 /* prompt only if source exist */ 156 if (lstat(from, &sb) == -1) { |
157 warn("%s", from); 158 return (1); |
159 } 160 161 ask = 0; 162 if (iflg) { 163 (void)fprintf(stderr, "overwrite %s? ", to); 164 ask = 1; 165 } else if (access(to, W_OK) && !stat(to, &sb)) { 166 strmode(sb.st_mode, modep); --- 136 unchanged lines hidden (view full) --- 303 return (1); 304 } 305 return (0); 306} 307 308void 309usage() 310{ |
311 (void)fprintf(stderr, "%s\n%s\n", 312 "usage: mv [-f | -i] src target", 313 " mv [-f | -i] src1 ... srcN directory"); |
314 exit(1); 315} |