Deleted Added
full compact
cp.c (90107) cp.c (91087)
1/*
2 * Copyright (c) 1988, 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 * David Hitz of Auspex Systems Inc.
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[] = "@(#)cp.c 8.2 (Berkeley) 4/1/94";
46#endif
47static const char rcsid[] =
1/*
2 * Copyright (c) 1988, 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 * David Hitz of Auspex Systems Inc.
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[] = "@(#)cp.c 8.2 (Berkeley) 4/1/94";
46#endif
47static const char rcsid[] =
48 "$FreeBSD: head/bin/cp/cp.c 90107 2002-02-02 06:15:22Z imp $";
48 "$FreeBSD: head/bin/cp/cp.c 91087 2002-02-22 21:24:14Z markm $";
49#endif /* not lint */
50
51/*
52 * Cp copies source files to target files.
53 *
54 * The global PATH_T structure "to" always contains the path to the
55 * current target file. Since fts(3) does not change directories,
56 * this path can be either absolute or dot-relative.

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

77
78#include "extern.h"
79
80#define STRIP_TRAILING_SLASH(p) { \
81 while ((p).p_end > (p).p_path + 1 && (p).p_end[-1] == '/') \
82 *--(p).p_end = 0; \
83}
84
49#endif /* not lint */
50
51/*
52 * Cp copies source files to target files.
53 *
54 * The global PATH_T structure "to" always contains the path to the
55 * current target file. Since fts(3) does not change directories,
56 * this path can be either absolute or dot-relative.

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

77
78#include "extern.h"
79
80#define STRIP_TRAILING_SLASH(p) { \
81 while ((p).p_end > (p).p_path + 1 && (p).p_end[-1] == '/') \
82 *--(p).p_end = 0; \
83}
84
85PATH_T to = { to.p_path, "", "" };
85static char emptystring[] = "";
86
86
87int Rflag, iflag, pflag, rflag, fflag, vflag;
87PATH_T to = { to.p_path, emptystring, "" };
88
88
89int iflag, pflag, fflag;
90static int Rflag, rflag, vflag;
91
89enum op { FILE_TO_FILE, FILE_TO_DIR, DIR_TO_DNE };
90
91int copy(char *[], enum op, int);
92int mastercmp(const FTSENT **, const FTSENT **);
93
94int
95main(int argc, char *argv[])
96{

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

236}
237
238int
239copy(char *argv[], enum op type, int fts_options)
240{
241 struct stat to_stat;
242 FTS *ftsp;
243 FTSENT *curr;
92enum op { FILE_TO_FILE, FILE_TO_DIR, DIR_TO_DNE };
93
94int copy(char *[], enum op, int);
95int mastercmp(const FTSENT **, const FTSENT **);
96
97int
98main(int argc, char *argv[])
99{

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

239}
240
241int
242copy(char *argv[], enum op type, int fts_options)
243{
244 struct stat to_stat;
245 FTS *ftsp;
246 FTSENT *curr;
244 int base = 0, dne, badcp, nlen, rval;
247 int base = 0, dne, badcp, rval;
248 size_t nlen;
245 char *p, *target_mid;
246 mode_t mask, mode;
247
248 /*
249 * Keep an inverted copy of the umask, for use in correcting
250 * permissions on created directories when not using -p.
251 */
252 mask = ~umask(0777);

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

262 warnx("%s: %s",
263 curr->fts_path, strerror(curr->fts_errno));
264 badcp = rval = 1;
265 continue;
266 case FTS_DC: /* Warn, continue. */
267 warnx("%s: directory causes a cycle", curr->fts_path);
268 badcp = rval = 1;
269 continue;
249 char *p, *target_mid;
250 mode_t mask, mode;
251
252 /*
253 * Keep an inverted copy of the umask, for use in correcting
254 * permissions on created directories when not using -p.
255 */
256 mask = ~umask(0777);

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

266 warnx("%s: %s",
267 curr->fts_path, strerror(curr->fts_errno));
268 badcp = rval = 1;
269 continue;
270 case FTS_DC: /* Warn, continue. */
271 warnx("%s: directory causes a cycle", curr->fts_path);
272 badcp = rval = 1;
273 continue;
274 default:
270 }
271
272 /*
273 * If we are in case (2) or (3) above, we need to append the
274 * source name to the target name.
275 */
276 if (type != FILE_TO_FILE) {
277 /*

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

365 to.p_path, curr->fts_path);
366 badcp = rval = 1;
367 if (S_ISDIR(curr->fts_statp->st_mode))
368 (void)fts_set(ftsp, curr, FTS_SKIP);
369 continue;
370 }
371 if (!S_ISDIR(curr->fts_statp->st_mode) &&
372 S_ISDIR(to_stat.st_mode)) {
275 }
276
277 /*
278 * If we are in case (2) or (3) above, we need to append the
279 * source name to the target name.
280 */
281 if (type != FILE_TO_FILE) {
282 /*

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

370 to.p_path, curr->fts_path);
371 badcp = rval = 1;
372 if (S_ISDIR(curr->fts_statp->st_mode))
373 (void)fts_set(ftsp, curr, FTS_SKIP);
374 continue;
375 }
376 if (!S_ISDIR(curr->fts_statp->st_mode) &&
377 S_ISDIR(to_stat.st_mode)) {
373 warnx("cannot overwrite directory %s with non-directory %s",
378 warnx("cannot overwrite directory %s with "
379 "non-directory %s",
374 to.p_path, curr->fts_path);
375 badcp = rval = 1;
376 continue;
377 }
378 dne = 0;
379 }
380
381 switch (curr->fts_statp->st_mode & S_IFMT) {

--- 92 unchanged lines hidden ---
380 to.p_path, curr->fts_path);
381 badcp = rval = 1;
382 continue;
383 }
384 dne = 0;
385 }
386
387 switch (curr->fts_statp->st_mode & S_IFMT) {

--- 92 unchanged lines hidden ---