Changeset 2330
- Timestamp:
- 12/14/11 01:38:28 (18 months ago)
- Files:
-
- 1 modified
-
trunk/ar/acpyacc.y (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ar/acpyacc.y
r2230 r2330 32 32 #include <sys/queue.h> 33 33 #include <sys/stat.h> 34 34 35 #include <archive.h> 35 36 #include <archive_entry.h> … … 42 43 #include <unistd.h> 43 44 45 #include "libelftc.h" 46 44 47 #include "ar.h" 45 48 … … 62 65 static void arscp_addmod(struct list *list); 63 66 static void arscp_clear(void); 64 static int arscp_copy(int ifd, int ofd);65 67 static void arscp_create(char *in, char *out); 66 68 static void arscp_delete(struct list *list); … … 296 298 * input archive. 297 299 */ 298 if ((ifd = open(in, O_RDONLY)) < 0) { 299 bsdar_warnc(bsdar, errno, "open failed"); 300 if ((ifd = open(in, O_RDONLY)) < 0 || 301 elftc_copyfile(ifd, ofd) < 0) { 302 bsdar_warnc(bsdar, errno, "'OPEN' failed"); 303 (void) close(ofd); 304 if (ifd != -1) 305 (void) close(ifd); 300 306 return; 301 307 } 302 if (arscp_copy(ifd, ofd)) { 303 bsdar_warnc(bsdar, 0, "arscp_copy failed"); 304 return; 305 } 306 close(ifd); 307 close(ofd); 308 (void) close(ifd); 309 (void) close(ofd); 308 310 } else { 309 311 /* … … 325 327 target = out; 326 328 bsdar->filename = tmpac; 327 }328 329 /*330 * A file copying implementation using mmap().331 */332 static int333 arscp_copy(int ifd, int ofd)334 {335 struct stat sb;336 char *buf, *p;337 ssize_t w;338 size_t bytes;339 340 if (fstat(ifd, &sb) < 0) {341 bsdar_warnc(bsdar, errno, "fstate failed");342 return (1);343 }344 if ((p = mmap(NULL, sb.st_size, PROT_READ, MAP_SHARED, ifd,345 (off_t)0)) == MAP_FAILED) {346 bsdar_warnc(bsdar, errno, "mmap failed");347 return (1);348 }349 for (buf = p, bytes = sb.st_size; bytes > 0; bytes -= w) {350 w = write(ofd, buf, bytes);351 if (w <= 0) {352 bsdar_warnc(bsdar, errno, "write failed");353 break;354 }355 }356 if (munmap(p, sb.st_size) < 0)357 bsdar_errc(bsdar, errno, "munmap failed");358 if (bytes > 0)359 return (1);360 361 return (0);362 329 } 363 330