utils.c (90107) | utils.c (91087) |
---|---|
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 90107 2002-02-02 06:15:22Z imp $"; | 39 "$FreeBSD: head/bin/cp/utils.c 91087 2002-02-22 21:24:14Z markm $"; |
40#endif /* not lint */ 41 42#include <sys/param.h> 43#include <sys/stat.h> | 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 48 49#include <err.h> 50#include <errno.h> 51#include <fcntl.h> 52#include <fts.h> --- 57 unchanged lines hidden (view full) --- 110 to_fd = open(to.p_path, O_WRONLY | O_TRUNC, 0); 111 } else 112 to_fd = open(to.p_path, O_WRONLY | O_TRUNC | O_CREAT, 113 fs->st_mode & ~(S_ISUID | S_ISGID)); 114 115 if (to_fd == -1) { 116 warn("%s", to.p_path); 117 (void)close(from_fd); | 44#ifdef VM_AND_BUFFER_CACHE_SYNCHRONIZED 45#include <sys/mman.h> 46#endif 47 48#include <err.h> 49#include <errno.h> 50#include <fcntl.h> 51#include <fts.h> --- 57 unchanged lines hidden (view full) --- 109 to_fd = open(to.p_path, O_WRONLY | O_TRUNC, 0); 110 } else 111 to_fd = open(to.p_path, O_WRONLY | O_TRUNC | O_CREAT, 112 fs->st_mode & ~(S_ISUID | S_ISGID)); 113 114 if (to_fd == -1) { 115 warn("%s", to.p_path); 116 (void)close(from_fd); |
118 return (1);; | 117 return (1); |
119 } 120 121 rval = 0; 122 123 /* 124 * Mmap and write if less than 8M (the limit is so we don't totally 125 * trash memory on big files. This is really a minor hack, but it 126 * wins some CPU back. --- 59 unchanged lines hidden (view full) --- 186 } 187 return (rval); 188} 189 190int 191copy_link(FTSENT *p, int exists) 192{ 193 int len; | 118 } 119 120 rval = 0; 121 122 /* 123 * Mmap and write if less than 8M (the limit is so we don't totally 124 * trash memory on big files. This is really a minor hack, but it 125 * wins some CPU back. --- 59 unchanged lines hidden (view full) --- 185 } 186 return (rval); 187} 188 189int 190copy_link(FTSENT *p, int exists) 191{ 192 int len; |
194 char link[PATH_MAX]; | 193 char llink[PATH_MAX]; |
195 | 194 |
196 if ((len = readlink(p->fts_path, link, sizeof(link) - 1)) == -1) { | 195 if ((len = readlink(p->fts_path, llink, sizeof(llink) - 1)) == -1) { |
197 warn("readlink: %s", p->fts_path); 198 return (1); 199 } | 196 warn("readlink: %s", p->fts_path); 197 return (1); 198 } |
200 link[len] = '\0'; | 199 llink[len] = '\0'; |
201 if (exists && unlink(to.p_path)) { 202 warn("unlink: %s", to.p_path); 203 return (1); 204 } | 200 if (exists && unlink(to.p_path)) { 201 warn("unlink: %s", to.p_path); 202 return (1); 203 } |
205 if (symlink(link, to.p_path)) { 206 warn("symlink: %s", link); | 204 if (symlink(llink, to.p_path)) { 205 warn("symlink: %s", llink); |
207 return (1); 208 } 209 return (0); 210} 211 212int 213copy_fifo(struct stat *from_stat, int exists) 214{ --- 17 unchanged lines hidden (view full) --- 232 } 233 if (mknod(to.p_path, from_stat->st_mode, from_stat->st_rdev)) { 234 warn("mknod: %s", to.p_path); 235 return (1); 236 } 237 return (pflag ? setfile(from_stat, 0) : 0); 238} 239 | 206 return (1); 207 } 208 return (0); 209} 210 211int 212copy_fifo(struct stat *from_stat, int exists) 213{ --- 17 unchanged lines hidden (view full) --- 231 } 232 if (mknod(to.p_path, from_stat->st_mode, from_stat->st_rdev)) { 233 warn("mknod: %s", to.p_path); 234 return (1); 235 } 236 return (pflag ? setfile(from_stat, 0) : 0); 237} 238 |
240#define RETAINBITS \ 241 (S_ISUID | S_ISGID | S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO) 242 | |
243int 244setfile(struct stat *fs, int fd) 245{ 246 static struct timeval tv[2]; 247 struct stat ts; 248 int rval; 249 int gotstat; 250 --- 58 unchanged lines hidden --- | 239int 240setfile(struct stat *fs, int fd) 241{ 242 static struct timeval tv[2]; 243 struct stat ts; 244 int rval; 245 int gotstat; 246 --- 58 unchanged lines hidden --- |