fetch.c (63067) | fetch.c (63235) |
---|---|
1/*- 2 * Copyright (c) 2000 Dag-Erling Co�dan Sm�rgrav 3 * 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 --- 11 unchanged lines hidden (view full) --- 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 * | 1/*- 2 * Copyright (c) 2000 Dag-Erling Co�dan Sm�rgrav 3 * 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 --- 11 unchanged lines hidden (view full) --- 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 * |
28 * $FreeBSD: head/usr.bin/fetch/fetch.c 63067 2000-07-13 08:37:39Z des $ | 28 * $FreeBSD: head/usr.bin/fetch/fetch.c 63235 2000-07-16 00:47:00Z des $ |
29 */ 30 31#include <sys/param.h> 32#include <sys/stat.h> 33#include <sys/socket.h> 34 35#include <ctype.h> 36#include <err.h> 37#include <errno.h> | 29 */ 30 31#include <sys/param.h> 32#include <sys/stat.h> 33#include <sys/socket.h> 34 35#include <ctype.h> 36#include <err.h> 37#include <errno.h> |
38#include <signal.h> |
|
38#include <stdio.h> 39#include <stdlib.h> 40#include <string.h> 41#include <sysexits.h> 42#include <unistd.h> 43 44#include <fetch.h> 45 --- 294 unchanged lines hidden (view full) --- 340 } 341 342 /* timed out or interrupted? */ 343 if (sigalrm) 344 warnx("transfer timed out"); 345 if (sigint) 346 warnx("transfer interrupted"); 347 | 39#include <stdio.h> 40#include <stdlib.h> 41#include <string.h> 42#include <sysexits.h> 43#include <unistd.h> 44 45#include <fetch.h> 46 --- 294 unchanged lines hidden (view full) --- 341 } 342 343 /* timed out or interrupted? */ 344 if (sigalrm) 345 warnx("transfer timed out"); 346 if (sigint) 347 warnx("transfer interrupted"); 348 |
348 /* check the status of our files */ 349 if (ferror(f)) 350 warn("%s", URL); 351 if (ferror(of)) 352 warn("%s", path); 353 if (ferror(f) || ferror(of)) 354 goto failure; | 349 if (!sigalrm && !sigint) { 350 /* check the status of our files */ 351 if (ferror(f)) 352 warn("%s", URL); 353 if (ferror(of)) 354 warn("%s", path); 355 if (ferror(f) || ferror(of)) 356 goto failure; 357 } |
355 356 /* did the transfer complete normally? */ 357 if (us.size != -1 && count < us.size) { 358 warnx("%s appears to be truncated: %lld/%lld bytes", 359 path, count, us.size); 360 goto failure_keep; 361 } 362 --- 44 unchanged lines hidden (view full) --- 407PARSENUM(parseint, u_int) 408PARSENUM(parsesize, size_t) 409PARSENUM(parseoff, off_t) 410 411int 412main(int argc, char *argv[]) 413{ 414 struct stat sb; | 358 359 /* did the transfer complete normally? */ 360 if (us.size != -1 && count < us.size) { 361 warnx("%s appears to be truncated: %lld/%lld bytes", 362 path, count, us.size); 363 goto failure_keep; 364 } 365 --- 44 unchanged lines hidden (view full) --- 410PARSENUM(parseint, u_int) 411PARSENUM(parsesize, size_t) 412PARSENUM(parseoff, off_t) 413 414int 415main(int argc, char *argv[]) 416{ 417 struct stat sb; |
418 struct sigaction sa; |
|
415 char *p, *q, *s; 416 int c, e, r; 417 418 while ((c = getopt(argc, argv, 419 "146AaB:bc:dFf:h:lHMmnPpo:qRrS:sT:tvw:")) != EOF) 420 switch (c) { 421 case '1': 422 once_flag = 1; --- 114 unchanged lines hidden (view full) --- 537 } 538 539 /* allocate buffer */ 540 if (B_size < MINBUFSIZE) 541 B_size = MINBUFSIZE; 542 if ((buf = malloc(B_size)) == NULL) 543 errx(1, strerror(ENOMEM)); 544 | 419 char *p, *q, *s; 420 int c, e, r; 421 422 while ((c = getopt(argc, argv, 423 "146AaB:bc:dFf:h:lHMmnPpo:qRrS:sT:tvw:")) != EOF) 424 switch (c) { 425 case '1': 426 once_flag = 1; --- 114 unchanged lines hidden (view full) --- 541 } 542 543 /* allocate buffer */ 544 if (B_size < MINBUFSIZE) 545 B_size = MINBUFSIZE; 546 if ((buf = malloc(B_size)) == NULL) 547 errx(1, strerror(ENOMEM)); 548 |
545 /* timeout handling */ 546 signal(SIGALRM, sig_handler); | 549 /* timeouts */ |
547 if ((s = getenv("FTP_TIMEOUT")) != NULL) { 548 if (parseint(s, &ftp_timeout) == -1) { 549 warnx("FTP_TIMEOUT is not a positive integer"); 550 ftp_timeout = 0; 551 } 552 } 553 if ((s = getenv("HTTP_TIMEOUT")) != NULL) { 554 if (parseint(s, &http_timeout) == -1) { 555 warnx("HTTP_TIMEOUT is not a positive integer"); 556 http_timeout = 0; 557 } 558 } 559 | 550 if ((s = getenv("FTP_TIMEOUT")) != NULL) { 551 if (parseint(s, &ftp_timeout) == -1) { 552 warnx("FTP_TIMEOUT is not a positive integer"); 553 ftp_timeout = 0; 554 } 555 } 556 if ((s = getenv("HTTP_TIMEOUT")) != NULL) { 557 if (parseint(s, &http_timeout) == -1) { 558 warnx("HTTP_TIMEOUT is not a positive integer"); 559 http_timeout = 0; 560 } 561 } 562 |
560 /* interrupt handling */ 561 signal(SIGINT, sig_handler); | 563 /* signal handling */ 564 sa.sa_flags = 0; 565 sa.sa_handler = sig_handler; 566 sigemptyset(&sa.sa_mask); 567 (void)sigaction(SIGALRM, &sa, NULL); 568 (void)sigaction(SIGINT, &sa, NULL); |
562 563 /* output file */ 564 if (o_flag) { 565 if (strcmp(o_filename, "-") == 0) { 566 o_stdout = 1; 567 } else if (stat(o_filename, &sb) == -1) { 568 if (errno == ENOENT) { 569 if (argc > 1) --- 69 unchanged lines hidden --- | 569 570 /* output file */ 571 if (o_flag) { 572 if (strcmp(o_filename, "-") == 0) { 573 o_stdout = 1; 574 } else if (stat(o_filename, &sb) == -1) { 575 if (errno == ENOENT) { 576 if (argc > 1) --- 69 unchanged lines hidden --- |