Deleted Added
full compact
utils.c (76693) utils.c (78070)
1/*-
2 * Copyright (c) 1991, 1993, 1994
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

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

31 * SUCH DAMAGE.
32 */
33
34#ifndef lint
35#if 0
36static char sccsid[] = "@(#)utils.c 8.3 (Berkeley) 4/1/94";
37#endif
38static const char rcsid[] =
1/*-
2 * Copyright (c) 1991, 1993, 1994
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

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

31 * SUCH DAMAGE.
32 */
33
34#ifndef lint
35#if 0
36static char sccsid[] = "@(#)utils.c 8.3 (Berkeley) 4/1/94";
37#endif
38static const char rcsid[] =
39 "$FreeBSD: head/bin/cp/utils.c 76693 2001-05-16 19:10:40Z imp $";
39 "$FreeBSD: head/bin/cp/utils.c 78070 2001-06-11 13:57:54Z bde $";
40#endif /* not lint */
41
42#include <sys/param.h>
43#include <sys/stat.h>
44#include <sys/time.h>
45#ifdef VM_AND_BUFFER_CACHE_SYNCHRONIZED
46#include <sys/mman.h>
47#endif

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

58#include "extern.h"
59
60int
61copy_file(entp, dne)
62 FTSENT *entp;
63 int dne;
64{
65 static char buf[MAXBSIZE];
40#endif /* not lint */
41
42#include <sys/param.h>
43#include <sys/stat.h>
44#include <sys/time.h>
45#ifdef VM_AND_BUFFER_CACHE_SYNCHRONIZED
46#include <sys/mman.h>
47#endif

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

58#include "extern.h"
59
60int
61copy_file(entp, dne)
62 FTSENT *entp;
63 int dne;
64{
65 static char buf[MAXBSIZE];
66 struct stat to_stat, *fs;
66 struct stat *fs;
67 int ch, checkch, from_fd, rcount, rval, to_fd, wcount, wresid;
68 char *bufp;
69#ifdef VM_AND_BUFFER_CACHE_SYNCHRONIZED
70 char *p;
71#endif
72
73 if ((from_fd = open(entp->fts_path, O_RDONLY, 0)) == -1) {
74 warn("%s", entp->fts_path);

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

175 * Don't remove the target even after an error. The target might
176 * not be a regular file, or its attributes might be important,
177 * or its contents might be irreplaceable. It would only be safe
178 * to remove it if we created it and its length is 0.
179 */
180
181 if (pflag && setfile(fs, to_fd))
182 rval = 1;
67 int ch, checkch, from_fd, rcount, rval, to_fd, wcount, wresid;
68 char *bufp;
69#ifdef VM_AND_BUFFER_CACHE_SYNCHRONIZED
70 char *p;
71#endif
72
73 if ((from_fd = open(entp->fts_path, O_RDONLY, 0)) == -1) {
74 warn("%s", entp->fts_path);

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

175 * Don't remove the target even after an error. The target might
176 * not be a regular file, or its attributes might be important,
177 * or its contents might be irreplaceable. It would only be safe
178 * to remove it if we created it and its length is 0.
179 */
180
181 if (pflag && setfile(fs, to_fd))
182 rval = 1;
183 /*
184 * If the source was setuid or setgid, lose the bits unless the
185 * copy is owned by the same user and group.
186 */
187#define RETAINBITS \
188 (S_ISUID | S_ISGID | S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO)
189 else if (fs->st_mode & (S_ISUID | S_ISGID) && fs->st_uid == myuid) {
190 if (fstat(to_fd, &to_stat)) {
191 warn("%s", to.p_path);
192 rval = 1;
193 } else if (fs->st_gid == to_stat.st_gid &&
194 fchmod(to_fd, fs->st_mode & RETAINBITS & ~myumask)) {
195 warn("%s", to.p_path);
196 rval = 1;
197 }
198 }
199 (void)close(from_fd);
200 if (close(to_fd)) {
201 warn("%s", to.p_path);
202 rval = 1;
203 }
204 return (rval);
205}
206

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

255 }
256 if (mknod(to.p_path, from_stat->st_mode, from_stat->st_rdev)) {
257 warn("mknod: %s", to.p_path);
258 return (1);
259 }
260 return (pflag ? setfile(from_stat, 0) : 0);
261}
262
183 (void)close(from_fd);
184 if (close(to_fd)) {
185 warn("%s", to.p_path);
186 rval = 1;
187 }
188 return (rval);
189}
190

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

239 }
240 if (mknod(to.p_path, from_stat->st_mode, from_stat->st_rdev)) {
241 warn("mknod: %s", to.p_path);
242 return (1);
243 }
244 return (pflag ? setfile(from_stat, 0) : 0);
245}
246
247#define RETAINBITS \
248 (S_ISUID | S_ISGID | S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO)
263
264int
265setfile(fs, fd)
266 register struct stat *fs;
267 int fd;
268{
269 static struct timeval tv[2];
270 struct stat ts;

--- 61 unchanged lines hidden ---
249
250int
251setfile(fs, fd)
252 register struct stat *fs;
253 int fd;
254{
255 static struct timeval tv[2];
256 struct stat ts;

--- 61 unchanged lines hidden ---