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 --- 31 unchanged lines hidden (view full) --- 40 The Regents of the University of California. All rights reserved.\n"; 41#endif /* not lint */ 42 43#ifndef lint 44#if 0 45static char sccsid[] = "@(#)mv.c 8.2 (Berkeley) 4/2/94"; 46#endif 47static const char rcsid[] = |
48 "$FreeBSD: head/bin/mv/mv.c 50544 1999-08-29 08:21:16Z mharo $"; |
49#endif /* not lint */ 50 51#include <sys/param.h> 52#include <sys/time.h> 53#include <sys/wait.h> 54#include <sys/stat.h> 55#include <sys/mount.h> 56 57#include <err.h> 58#include <errno.h> 59#include <fcntl.h> 60#include <stdio.h> 61#include <stdlib.h> 62#include <string.h> |
63#include <sysexits.h> |
64#include <unistd.h> 65 66#include "pathnames.h" 67 |
68int fflg, iflg, vflg; |
69 70int copy __P((char *, char *)); 71int do_move __P((char *, char *)); 72int fastcopy __P((char *, char *, struct stat *)); 73void usage __P((void)); 74 75int 76main(argc, argv) 77 int argc; 78 char *argv[]; 79{ 80 register int baselen, len, rval; 81 register char *p, *endp; 82 struct stat sb; 83 int ch; 84 char path[MAXPATHLEN]; 85 |
86 while ((ch = getopt(argc, argv, "fiv")) != -1) |
87 switch (ch) { 88 case 'i': 89 iflg = 1; 90 fflg = 0; 91 break; 92 case 'f': 93 fflg = 1; 94 iflg = 0; 95 break; |
96 case 'v': 97 vflg = 1; 98 break; |
99 default: 100 usage(); 101 } 102 argc -= optind; 103 argv += optind; 104 105 if (argc < 2) 106 usage(); --- 80 unchanged lines hidden (view full) --- 187 while (ch != '\n' && ch != EOF) 188 ch = getchar(); 189 if (first != 'y' && first != 'Y') { 190 (void)fprintf(stderr, "not overwritten\n"); 191 return (0); 192 } 193 } 194 } |
195 if (!rename(from, to)) { 196 if (vflg) 197 printf("%s -> %s\n", from, to); |
198 return (0); |
199 } |
200 201 if (errno == EXDEV) { 202 struct statfs sfs; 203 char path[MAXPATHLEN]; 204 205 /* Can't mv(1) a mount point. */ 206 if (realpath(from, path) == NULL) { 207 warnx("cannot resolve %s: %s", from, path); --- 93 unchanged lines hidden (view full) --- 301 warn("%s", to); 302 return (1); 303 } 304 305 if (unlink(from)) { 306 warn("%s: remove", from); 307 return (1); 308 } |
309 if (vflg) 310 printf("%s -> %s\n", from, to); |
311 return (0); 312} 313 314int 315copy(from, to) 316 char *from, *to; 317{ 318 int pid, status; 319 320 if ((pid = fork()) == 0) { |
321 execl(_PATH_CP, "mv", vflg ? "-PRpv" : "-PRp", from, to, NULL); |
322 warn("%s", _PATH_CP); 323 _exit(1); 324 } 325 if (waitpid(pid, &status, 0) == -1) { 326 warn("%s: waitpid", _PATH_CP); 327 return (1); 328 } 329 if (!WIFEXITED(status)) { --- 24 unchanged lines hidden (view full) --- 354 return (1); 355 } 356 return (0); 357} 358 359void 360usage() 361{ |
362 |
363 (void)fprintf(stderr, "%s\n%s\n", |
364 "usage: mv [-f | -i] [-v] source target", 365 " mv [-f | -i] [-v] source ... directory"); 366 exit(EX_USAGE); |
367} |