Deleted Added
full compact
mv.c (174935) mv.c (180604)
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 174935 2007-12-27 11:33:42Z dds $");
45__FBSDID("$FreeBSD: head/bin/mv/mv.c 180604 2008-07-19 00:13:26Z delphij $");
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>

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

65#include <sysexits.h>
66#include <unistd.h>
67
68/* Exit code for a failed exec. */
69#define EXEC_FAILED 127
70
71int fflg, iflg, nflg, vflg;
72
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>

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

65#include <sysexits.h>
66#include <unistd.h>
67
68/* Exit code for a failed exec. */
69#define EXEC_FAILED 127
70
71int fflg, iflg, nflg, vflg;
72
73int copy(char *, char *);
74int do_move(char *, char *);
75int fastcopy(char *, char *, struct stat *);
76void usage(void);
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);
77
78int
79main(int argc, char *argv[])
80{
81 size_t baselen, len;
82 int rval;
83 char *p, *endp;
84 struct stat sb;

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

149 memmove(endp, p, (size_t)len + 1);
150 if (do_move(*argv, path))
151 rval = 1;
152 }
153 }
154 exit(rval);
155}
156
77
78int
79main(int argc, char *argv[])
80{
81 size_t baselen, len;
82 int rval;
83 char *p, *endp;
84 struct stat sb;

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

149 memmove(endp, p, (size_t)len + 1);
150 if (do_move(*argv, path))
151 rval = 1;
152 }
153 }
154 exit(rval);
155}
156
157int
158do_move(char *from, char *to)
157static int
158do_move(const char *from, const char *to)
159{
160 struct stat sb;
161 int ask, ch, first;
162 char modep[15];
163
164 /*
165 * Check access. If interactive and file exists, ask user if it
166 * should be replaced. Otherwise if file exists but isn't writable

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

249 if (lstat(from, &sb)) {
250 warn("%s", from);
251 return (1);
252 }
253 return (S_ISREG(sb.st_mode) ?
254 fastcopy(from, to, &sb) : copy(from, to));
255}
256
159{
160 struct stat sb;
161 int ask, ch, first;
162 char modep[15];
163
164 /*
165 * Check access. If interactive and file exists, ask user if it
166 * should be replaced. Otherwise if file exists but isn't writable

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

249 if (lstat(from, &sb)) {
250 warn("%s", from);
251 return (1);
252 }
253 return (S_ISREG(sb.st_mode) ?
254 fastcopy(from, to, &sb) : copy(from, to));
255}
256
257int
258fastcopy(char *from, char *to, struct stat *sbp)
257static int
258fastcopy(const char *from, const char *to, struct stat *sbp)
259{
260 struct timeval tval[2];
261 static u_int blen;
262 static char *bp;
263 acl_t acl;
264 mode_t oldmode;
265 int nread, from_fd, to_fd;
266

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

355 warn("%s: remove", from);
356 return (1);
357 }
358 if (vflg)
359 printf("%s -> %s\n", from, to);
360 return (0);
361}
362
259{
260 struct timeval tval[2];
261 static u_int blen;
262 static char *bp;
263 acl_t acl;
264 mode_t oldmode;
265 int nread, from_fd, to_fd;
266

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

355 warn("%s: remove", from);
356 return (1);
357 }
358 if (vflg)
359 printf("%s -> %s\n", from, to);
360 return (0);
361}
362
363int
364copy(char *from, char *to)
363static int
364copy(const char *from, const char *to)
365{
366 struct stat sb;
367 int pid, status;
368
369 if (lstat(to, &sb) == 0) {
370 /* Destination path exists. */
371 if (S_ISDIR(sb.st_mode)) {
372 if (rmdir(to) != 0) {

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

433 default:
434 warnx("%s %s: terminated with %d (non-zero) status",
435 _PATH_RM, from, WEXITSTATUS(status));
436 return (1);
437 }
438 return (0);
439}
440
365{
366 struct stat sb;
367 int pid, status;
368
369 if (lstat(to, &sb) == 0) {
370 /* Destination path exists. */
371 if (S_ISDIR(sb.st_mode)) {
372 if (rmdir(to) != 0) {

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

433 default:
434 warnx("%s %s: terminated with %d (non-zero) status",
435 _PATH_RM, from, WEXITSTATUS(status));
436 return (1);
437 }
438 return (0);
439}
440
441void
441static void
442usage(void)
443{
444
445 (void)fprintf(stderr, "%s\n%s\n",
446 "usage: mv [-f | -i | -n] [-v] source target",
447 " mv [-f | -i | -n] [-v] source ... directory");
448 exit(EX_USAGE);
449}
442usage(void)
443{
444
445 (void)fprintf(stderr, "%s\n%s\n",
446 "usage: mv [-f | -i | -n] [-v] source target",
447 " mv [-f | -i | -n] [-v] source ... directory");
448 exit(EX_USAGE);
449}