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 50471 1999-08-27 23:15:48Z peter $";
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 <unistd.h>
64
65#include "pathnames.h"
66
67int fflg, iflg;
68
69int copy __P((char *, char *));
70int do_move __P((char *, char *));
71int fastcopy __P((char *, char *, struct stat *));
72void usage __P((void));
73
74int
75main(argc, argv)
76 int argc;
77 char *argv[];
78{
79 register int baselen, len, rval;
80 register char *p, *endp;
81 struct stat sb;
82 int ch;
83 char path[MAXPATHLEN];
84
85 while ((ch = getopt(argc, argv, "fi")) != -1)
86 switch (ch) {
87 case 'i':
88 iflg = 1;
89 fflg = 0;
90 break;
91 case 'f':
92 fflg = 1;
93 iflg = 0;
94 break;
95 default:
96 usage();
97 }
98 argc -= optind;
99 argv += optind;
100
101 if (argc < 2)
102 usage();
--- 80 unchanged lines hidden (view full) ---
183 while (ch != '\n' && ch != EOF)
184 ch = getchar();
185 if (first != 'y' && first != 'Y') {
186 (void)fprintf(stderr, "not overwritten\n");
187 return (0);
188 }
189 }
190 }
191 if (!rename(from, to))
192 return (0);
193
194 if (errno == EXDEV) {
195 struct statfs sfs;
196 char path[MAXPATHLEN];
197
198 /* Can't mv(1) a mount point. */
199 if (realpath(from, path) == NULL) {
200 warnx("cannot resolve %s: %s", from, path);
--- 93 unchanged lines hidden (view full) ---
294 warn("%s", to);
295 return (1);
296 }
297
298 if (unlink(from)) {
299 warn("%s: remove", from);
300 return (1);
301 }
302 return (0);
303}
304
305int
306copy(from, to)
307 char *from, *to;
308{
309 int pid, status;
310
311 if ((pid = fork()) == 0) {
312 execl(_PATH_CP, "mv", "-PRp", from, to, NULL);
313 warn("%s", _PATH_CP);
314 _exit(1);
315 }
316 if (waitpid(pid, &status, 0) == -1) {
317 warn("%s: waitpid", _PATH_CP);
318 return (1);
319 }
320 if (!WIFEXITED(status)) {
--- 24 unchanged lines hidden (view full) ---
345 return (1);
346 }
347 return (0);
348}
349
350void
351usage()
352{
353 (void)fprintf(stderr, "%s\n%s\n",
354 "usage: mv [-f | -i] source target",
355 " mv [-f | -i] source ... directory");
356 exit(1);
357}
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 50471 1999-08-27 23:15:48Z peter $";
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 <unistd.h>
64
65#include "pathnames.h"
66
67int fflg, iflg;
68
69int copy __P((char *, char *));
70int do_move __P((char *, char *));
71int fastcopy __P((char *, char *, struct stat *));
72void usage __P((void));
73
74int
75main(argc, argv)
76 int argc;
77 char *argv[];
78{
79 register int baselen, len, rval;
80 register char *p, *endp;
81 struct stat sb;
82 int ch;
83 char path[MAXPATHLEN];
84
85 while ((ch = getopt(argc, argv, "fi")) != -1)
86 switch (ch) {
87 case 'i':
88 iflg = 1;
89 fflg = 0;
90 break;
91 case 'f':
92 fflg = 1;
93 iflg = 0;
94 break;
95 default:
96 usage();
97 }
98 argc -= optind;
99 argv += optind;
100
101 if (argc < 2)
102 usage();
--- 80 unchanged lines hidden (view full) ---
183 while (ch != '\n' && ch != EOF)
184 ch = getchar();
185 if (first != 'y' && first != 'Y') {
186 (void)fprintf(stderr, "not overwritten\n");
187 return (0);
188 }
189 }
190 }
191 if (!rename(from, to))
192 return (0);
193
194 if (errno == EXDEV) {
195 struct statfs sfs;
196 char path[MAXPATHLEN];
197
198 /* Can't mv(1) a mount point. */
199 if (realpath(from, path) == NULL) {
200 warnx("cannot resolve %s: %s", from, path);
--- 93 unchanged lines hidden (view full) ---
294 warn("%s", to);
295 return (1);
296 }
297
298 if (unlink(from)) {
299 warn("%s: remove", from);
300 return (1);
301 }
302 return (0);
303}
304
305int
306copy(from, to)
307 char *from, *to;
308{
309 int pid, status;
310
311 if ((pid = fork()) == 0) {
312 execl(_PATH_CP, "mv", "-PRp", from, to, NULL);
313 warn("%s", _PATH_CP);
314 _exit(1);
315 }
316 if (waitpid(pid, &status, 0) == -1) {
317 warn("%s: waitpid", _PATH_CP);
318 return (1);
319 }
320 if (!WIFEXITED(status)) {
--- 24 unchanged lines hidden (view full) ---
345 return (1);
346 }
347 return (0);
348}
349
350void
351usage()
352{
353 (void)fprintf(stderr, "%s\n%s\n",
354 "usage: mv [-f | -i] source target",
355 " mv [-f | -i] source ... directory");
356 exit(1);
357}