Changeset 370 for trunk/src/gmake/kmkbuiltin/cp_utils.c
- Timestamp:
- Dec 18, 2005, 4:48:02 AM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/gmake/kmkbuiltin/cp_utils.c
r347 r370 31 31 #if 0 32 32 static char sccsid[] = "@(#)utils.c 8.3 (Berkeley) 4/1/94"; 33 #include <sys/cdefs.h> 34 __FBSDID("$FreeBSD: src/bin/cp/utils.c,v 1.43 2004/04/06 20:06:44 markm Exp $"); 33 35 #endif 34 36 #endif /* not lint */ 35 #include <sys/cdefs.h> 36 //__FBSDID("$FreeBSD: src/bin/cp/utils.c,v 1.43 2004/04/06 20:06:44 markm Exp $"); 37 37 38 #ifndef _MSC_VER 38 39 #include <sys/param.h> 40 #endif 39 41 #include <sys/stat.h> 40 42 #ifdef VM_AND_BUFFER_CACHE_SYNCHRONIZED … … 42 44 #endif 43 45 44 #include <err.h>46 #include "err.h" 45 47 #include <errno.h> 46 48 #include <fcntl.h> 49 #ifndef _MSC_VER 47 50 #include <fts.h> 51 #endif 48 52 #include <limits.h> 49 53 #include <stdio.h> 50 54 #include <stdlib.h> 55 #include <signal.h> 56 #ifndef _MSC_VER 51 57 #include <sysexits.h> 52 58 #include <unistd.h> 53 #include <signal.h> 59 #else 60 #include "mscfakes.h" 61 #include "ftsfake.h" 62 #endif 54 63 55 64 #include "cp_extern.h" … … 57 66 58 67 #ifndef MAXBSIZE 59 # define MAXBSIZE (128*1024)68 # define MAXBSIZE 16384 60 69 #endif 61 70 #ifndef O_BINARY 62 71 # define O_BINARY 0 63 72 #endif 73 74 #ifndef S_ISVTX 75 # define S_ISVTX 0 76 #endif 64 77 65 78 int … … 78 91 79 92 if ((from_fd = open(entp->fts_path, O_RDONLY | O_BINARY, 0)) == -1) { 80 fprintf(stderr, "%s: %s: %s\n", argv0, entp->fts_path, strerror(errno));93 warn("%s", entp->fts_path); 81 94 return (1); 82 95 } … … 125 138 126 139 if (to_fd == -1) { 127 fprintf(stderr, "%s: %s: %s\n", argv0, to.p_path, strerror(errno));140 warn("%s", to.p_path); 128 141 (void)close(from_fd); 129 142 return (1); … … 142 155 if ((p = mmap(NULL, (size_t)fs->st_size, PROT_READ, 143 156 MAP_SHARED, from_fd, (off_t)0)) == MAP_FAILED) { 144 fprintf(stderr, "%s: %s: %s\n", argv0, entp->fts_path, strerror(errno));157 warn("%s", entp->fts_path); 145 158 rval = 1; 146 159 } else { … … 162 175 } 163 176 if (wcount != (ssize_t)wresid) { 164 fprintf(stderr, "%s: %s: %s\n", argv0, to.p_path, strerror(errno));177 warn("%s", to.p_path); 165 178 rval = 1; 166 179 } 167 180 /* Some systems don't unmap on close(2). */ 168 181 if (munmap(p, fs->st_size) < 0) { 169 fprintf(stderr, "%s: %s: %s\n", entp->fts_path, strerror(errno));182 warn("%s", entp->fts_path); 170 183 rval = 1; 171 184 } … … 192 205 } 193 206 if (wcount != (ssize_t)wresid) { 194 fprintf(stderr, "%s: %s: %s\n", argv0, to.p_path, strerror(errno));207 warn("%s", to.p_path); 195 208 rval = 1; 196 209 break; … … 198 211 } 199 212 if (rcount < 0) { 200 fprintf(stderr, "%s: %s: %s\n", argv0, entp->fts_path, strerror(errno));213 warn("%s", entp->fts_path); 201 214 rval = 1; 202 215 } … … 214 227 (void)close(from_fd); 215 228 if (close(to_fd)) { 216 fprintf(stderr, "%s: %s: %s\n", argv0, to.p_path, strerror(errno));229 warn("%s", to.p_path); 217 230 rval = 1; 218 231 } … … 227 240 228 241 if ((len = readlink(p->fts_path, llink, sizeof(llink) - 1)) == -1) { 229 fprintf(stderr, "%s: readlink: %s: %s\n", argv0, p->fts_path, strerror(errno));242 warn("readlink: %s", p->fts_path); 230 243 return (1); 231 244 } 232 245 llink[len] = '\0'; 233 246 if (exists && unlink(to.p_path)) { 234 fprintf(stderr, "%s: unlink: %s: %s\n", argv0, to.p_path, strerror(errno));247 warn("unlink: %s", to.p_path); 235 248 return (1); 236 249 } 237 250 if (symlink(llink, to.p_path)) { 238 fprintf(stderr, "%s: symlink: %s: %s\n", argv0, llink, strerror(errno));251 warn("symlink: %s", llink); 239 252 return (1); 240 253 } … … 246 259 { 247 260 if (exists && unlink(to.p_path)) { 248 fprintf(stderr, "%s: unlink: %s: %s\n", argv0, to.p_path, strerror(errno));261 warn("unlink: %s", to.p_path); 249 262 return (1); 250 263 } 251 264 if (mkfifo(to.p_path, from_stat->st_mode)) { 252 fprintf(stderr, "%s: mkfifo: %s\n", argv0, to.p_path, strerror(errno));265 warn("mkfifo: %s", to.p_path); 253 266 return (1); 254 267 } … … 260 273 { 261 274 if (exists && unlink(to.p_path)) { 262 fprintf(stderr, "%s: unlink: %s: %s\n", argv0, to.p_path, strerror(errno));275 warn("unlink: %s", to.p_path); 263 276 return (1); 264 277 } 265 278 if (mknod(to.p_path, from_stat->st_mode, from_stat->st_rdev)) { 266 fprintf(stderr, "%s: mknod: %s: %s\n", argv0, to.p_path, strerror(errno));279 warn("mknod: %s", to.p_path); 267 280 return (1); 268 281 } … … 292 305 #endif 293 306 if (islink ? lutimes(to.p_path, tv) : utimes(to.p_path, tv)) { 294 fprintf(stderr, "%s: %sutimes: %s: %s\n", argv0, islink ? "l" : "", to.p_path, strerror(errno));307 warn("%sutimes: %s", islink ? "l" : "", to.p_path); 295 308 rval = 1; 296 309 } … … 314 327 chown(to.p_path, fs->st_uid, fs->st_gid))) { 315 328 if (errno != EPERM) { 316 fprintf(stderr, "%s: chown: %s: %s\n", argv0, to.p_path, strerror(errno));329 warn("chown: %s", to.p_path); 317 330 rval = 1; 318 331 } … … 324 337 (islink ? lchmod(to.p_path, fs->st_mode) : 325 338 chmod(to.p_path, fs->st_mode))) { 326 fprintf(stderr, "%s: chmod: %s: %s\n", to.p_path, strerror(errno));339 warn("chmod: %s", to.p_path); 327 340 rval = 1; 328 341 } … … 334 347 (islink ? (errno = ENOSYS) : 335 348 chflags(to.p_path, fs->st_flags))) { 336 fprintf(stderr, "%s: chflags: %s: %s", argv0, to.p_path, strerror(errno));349 warn("chflags: %s", to.p_path); 337 350 rval = 1; 338 351 } … … 342 355 } 343 356 344 void 357 int 345 358 usage(void) 346 359 { … … 349 362 "usage: cp [-R [-H | -L | -P]] [-f | -i | -n] [-pv] src target", 350 363 " cp [-R [-H | -L | -P]] [-f | -i | -n] [-pv] src1 ... srcN directory"); 351 exit(EX_USAGE);352 } 364 return EX_USAGE; 365 }
Note:
See TracChangeset
for help on using the changeset viewer.