Deleted Added
full compact
mv.c (63680) mv.c (76878)
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[] =
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 63680 2000-07-20 18:30:00Z sada $";
48 "$FreeBSD: head/bin/mv/mv.c 76878 2001-05-20 05:00:16Z kris $";
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

--- 8 unchanged lines hidden (view full) ---

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 *));
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

--- 8 unchanged lines hidden (view full) ---

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 *));
73int main __P((int, char *[]));
73void usage __P((void));
74
75int
76main(argc, argv)
77 int argc;
78 char *argv[];
79{
80 register int baselen, len, rval;

--- 54 unchanged lines hidden (view full) ---

135 --p;
136 while (p != *argv && p[-1] != '/')
137 --p;
138
139 if ((baselen + (len = strlen(p))) >= MAXPATHLEN) {
140 warnx("%s: destination pathname too long", *argv);
141 rval = 1;
142 } else {
74void usage __P((void));
75
76int
77main(argc, argv)
78 int argc;
79 char *argv[];
80{
81 register int baselen, len, rval;

--- 54 unchanged lines hidden (view full) ---

136 --p;
137 while (p != *argv && p[-1] != '/')
138 --p;
139
140 if ((baselen + (len = strlen(p))) >= MAXPATHLEN) {
141 warnx("%s: destination pathname too long", *argv);
142 rval = 1;
143 } else {
143 memmove(endp, p, len + 1);
144 memmove(endp, p, (size_t)len + 1);
144 if (do_move(*argv, path))
145 rval = 1;
146 }
147 }
148 exit(rval);
149}
150
151int

--- 21 unchanged lines hidden (view full) ---

173 ask = 0;
174 if (iflg) {
175 (void)fprintf(stderr, "overwrite %s? %s", to, YESNO);
176 ask = 1;
177 } else if (access(to, W_OK) && !stat(to, &sb)) {
178 strmode(sb.st_mode, modep);
179 (void)fprintf(stderr, "override %s%s%s/%s for %s? %s",
180 modep + 1, modep[9] == ' ' ? "" : " ",
145 if (do_move(*argv, path))
146 rval = 1;
147 }
148 }
149 exit(rval);
150}
151
152int

--- 21 unchanged lines hidden (view full) ---

174 ask = 0;
175 if (iflg) {
176 (void)fprintf(stderr, "overwrite %s? %s", to, YESNO);
177 ask = 1;
178 } else if (access(to, W_OK) && !stat(to, &sb)) {
179 strmode(sb.st_mode, modep);
180 (void)fprintf(stderr, "override %s%s%s/%s for %s? %s",
181 modep + 1, modep[9] == ' ' ? "" : " ",
181 user_from_uid(sb.st_uid, 0),
182 group_from_gid(sb.st_gid, 0), to, YESNO);
182 user_from_uid((unsigned long)sb.st_uid, 0),
183 group_from_gid((unsigned long)sb.st_gid, 0), to, YESNO);
183 ask = 1;
184 }
185 if (ask) {
186 first = ch = getchar();
187 while (ch != '\n' && ch != EOF)
188 ch = getchar();
189 if (first != 'y' && first != 'Y') {
190 (void)fprintf(stderr, "not overwritten\n");

--- 51 unchanged lines hidden (view full) ---

242
243 if ((from_fd = open(from, O_RDONLY, 0)) < 0) {
244 warn("%s", from);
245 return (1);
246 }
247 if (blen < sbp->st_blksize) {
248 if (bp != NULL)
249 free(bp);
184 ask = 1;
185 }
186 if (ask) {
187 first = ch = getchar();
188 while (ch != '\n' && ch != EOF)
189 ch = getchar();
190 if (first != 'y' && first != 'Y') {
191 (void)fprintf(stderr, "not overwritten\n");

--- 51 unchanged lines hidden (view full) ---

243
244 if ((from_fd = open(from, O_RDONLY, 0)) < 0) {
245 warn("%s", from);
246 return (1);
247 }
248 if (blen < sbp->st_blksize) {
249 if (bp != NULL)
250 free(bp);
250 if ((bp = malloc(sbp->st_blksize)) == NULL) {
251 if ((bp = malloc((size_t)sbp->st_blksize)) == NULL) {
251 blen = 0;
252 warnx("malloc failed");
253 return (1);
254 }
255 blen = sbp->st_blksize;
256 }
257 while ((to_fd =
258 open(to, O_CREAT | O_EXCL | O_TRUNC | O_WRONLY, 0)) < 0) {
259 if (errno == EEXIST && unlink(to) == 0)
260 continue;
261 warn("%s", to);
262 (void)close(from_fd);
263 return (1);
264 }
252 blen = 0;
253 warnx("malloc failed");
254 return (1);
255 }
256 blen = sbp->st_blksize;
257 }
258 while ((to_fd =
259 open(to, O_CREAT | O_EXCL | O_TRUNC | O_WRONLY, 0)) < 0) {
260 if (errno == EEXIST && unlink(to) == 0)
261 continue;
262 warn("%s", to);
263 (void)close(from_fd);
264 return (1);
265 }
265 while ((nread = read(from_fd, bp, blen)) > 0)
266 if (write(to_fd, bp, nread) != nread) {
266 while ((nread = read(from_fd, bp, (size_t)blen)) > 0)
267 if (write(to_fd, bp, (size_t)nread) != nread) {
267 warn("%s", to);
268 goto err;
269 }
270 if (nread < 0) {
271 warn("%s", from);
272err: if (unlink(to))
273 warn("%s: remove", to);
274 (void)close(from_fd);

--- 18 unchanged lines hidden (view full) ---

293 /*
294 * XXX
295 * NFS doesn't support chflags; ignore errors unless there's reason
296 * to believe we're losing bits. (Note, this still won't be right
297 * if the server supports flags and we were trying to *remove* flags
298 * on a file that we copied, i.e., that we didn't create.)
299 */
300 errno = 0;
268 warn("%s", to);
269 goto err;
270 }
271 if (nread < 0) {
272 warn("%s", from);
273err: if (unlink(to))
274 warn("%s: remove", to);
275 (void)close(from_fd);

--- 18 unchanged lines hidden (view full) ---

294 /*
295 * XXX
296 * NFS doesn't support chflags; ignore errors unless there's reason
297 * to believe we're losing bits. (Note, this still won't be right
298 * if the server supports flags and we were trying to *remove* flags
299 * on a file that we copied, i.e., that we didn't create.)
300 */
301 errno = 0;
301 if (fchflags(to_fd, sbp->st_flags))
302 if (fchflags(to_fd, (u_long)sbp->st_flags))
302 if (errno != EOPNOTSUPP || sbp->st_flags != 0)
303 warn("%s: set flags (was: 0%07o)", to, sbp->st_flags);
304
305 tval[0].tv_sec = sbp->st_atime;
306 tval[1].tv_sec = sbp->st_mtime;
307 tval[0].tv_usec = tval[1].tv_usec = 0;
308 if (utimes(to, tval))
309 warn("%s: set times", to);

--- 69 unchanged lines hidden ---
303 if (errno != EOPNOTSUPP || sbp->st_flags != 0)
304 warn("%s: set flags (was: 0%07o)", to, sbp->st_flags);
305
306 tval[0].tv_sec = sbp->st_atime;
307 tval[1].tv_sec = sbp->st_mtime;
308 tval[0].tv_usec = tval[1].tv_usec = 0;
309 if (utimes(to, tval))
310 warn("%s: set times", to);

--- 69 unchanged lines hidden ---