2 * Copyright (c) 2000-2004 Dag-Erling Coïdan Smørgrav
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer
10 * in this position and unchanged.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
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.
32 #if !defined(NETBSD) && !defined(__minix)
37 #include <sys/param.h>
40 #include <sys/ioctl.h>
43 #include <sys/socket.h>
85 #define MINBUFSIZE 4096
88 int A_flag
; /* -A: do not follow 302 redirects */
89 int a_flag
; /* -a: auto retry */
90 off_t B_size
; /* -B: buffer size */
91 int d_flag
; /* -d: direct connection */
92 int F_flag
; /* -F: restart without checking mtime */
93 int i_flag
; /* -i: fetch file if modified */
94 int l_flag
; /* -l: link rather than copy file: URLs */
95 int m_flag
; /* -[Mm]: mirror mode */
96 char *N_filename
; /* -N: netrc file name */
97 int n_flag
; /* -n: do not preserve modification time */
98 int o_flag
; /* -o: specify output file */
99 int o_directory
; /* output file is a directory */
100 char *o_filename
; /* name of output file */
101 int o_stdout
; /* output file is stdout */
102 int once_flag
; /* -1: stop at first successful file */
103 int R_flag
; /* -R: don't delete partially transferred files */
104 int r_flag
; /* -r: restart previously interrupted transfer */
105 off_t S_size
; /* -S: require size to match */
106 int s_flag
; /* -s: show size, don't fetch */
107 long T_secs
= 120; /* -T: transfer timeout in seconds */
108 int U_flag
; /* -U: do not use high ports */
109 int v_level
= 1; /* -v: verbosity level */
110 int v_tty
; /* stdout is a tty */
111 pid_t pgrp
; /* our process group */
112 long w_secs
; /* -w: retry delay */
113 int family
= PF_UNSPEC
; /* -[46]: address family to use */
115 volatile int sigalrm
; /* SIGALRM received */
117 volatile int siginfo
; /* SIGINFO received */
119 volatile int sigint
; /* SIGINT received */
121 long ftp_timeout
; /* default timeout for FTP transfers */
122 long http_timeout
; /* default timeout for HTTP transfers */
123 char *buf
; /* transfer buffer */
134 fetchRestartCalls
= 0;
143 fetchRestartCalls
= 0;
151 struct timeval start
;
159 * Compute and display ETA
162 stat_eta(struct xferstat
*xs
)
166 off_t received
, expected
;
168 elapsed
= xs
->last
.tv_sec
- xs
->start
.tv_sec
;
169 received
= xs
->rcvd
- xs
->offset
;
170 expected
= xs
->size
- xs
->rcvd
;
171 eta
= (long)((double)elapsed
* expected
/ received
);
173 snprintf(str
, sizeof str
, "%02ldh%02ldm",
174 eta
/ 3600, (eta
% 3600) / 60);
176 snprintf(str
, sizeof str
, "%02ldm%02lds",
182 * Format a number as "xxxx YB" where Y is ' ', 'k', 'M'...
184 static const char *prefixes
= " kMGTP";
186 stat_bytes(off_t bytes
)
189 const char *prefix
= prefixes
;
191 while (bytes
> 9999 && prefix
[1] != '\0') {
195 snprintf(str
, sizeof str
, "%4jd %cB", (intmax_t)bytes
, *prefix
);
200 * Compute and display transfer rate
203 stat_bps(struct xferstat
*xs
)
208 delta
= (xs
->last
.tv_sec
+ (xs
->last
.tv_usec
/ 1.e6
))
209 - (xs
->start
.tv_sec
+ (xs
->start
.tv_usec
/ 1.e6
));
211 snprintf(str
, sizeof str
, "?? Bps");
213 bps
= (xs
->rcvd
- xs
->offset
) / delta
;
214 snprintf(str
, sizeof str
, "%sps", stat_bytes((off_t
)bps
));
220 * Update the stats display
223 stat_display(struct xferstat
*xs
, int force
)
228 /* Minix returns "Not a typewriter error" */
229 #if defined(TIOCGPGRP) && !defined(__minix)
230 /* check if we're the foreground process */
231 if (ioctl(STDERR_FILENO
, TIOCGPGRP
, &ctty_pgrp
) == -1 ||
232 (pid_t
)ctty_pgrp
!= pgrp
)
236 gettimeofday(&now
, NULL
);
237 if (!force
&& now
.tv_sec
<= xs
->last
.tv_sec
)
241 fprintf(stderr
, "\r%-46.46s", xs
->name
);
243 #if HAVE_SETPROCTITLE
244 setproctitle("%s [%s]", xs
->name
, stat_bytes(xs
->rcvd
));
246 fprintf(stderr
, " %s", stat_bytes(xs
->rcvd
));
248 #if HAVE_SETPROCTITLE
249 setproctitle("%s [%d%% of %s]", xs
->name
,
250 (int)((100.0 * xs
->rcvd
) / xs
->size
),
251 stat_bytes(xs
->size
));
253 fprintf(stderr
, "%3d%% of %s",
254 (int)((100.0 * xs
->rcvd
) / xs
->size
),
255 stat_bytes(xs
->size
));
257 fprintf(stderr
, " %s", stat_bps(xs
));
258 if (xs
->size
> 0 && xs
->rcvd
> 0 &&
259 xs
->last
.tv_sec
>= xs
->start
.tv_sec
+ 10)
260 fprintf(stderr
, " %s", stat_eta(xs
));
265 * Initialize the transfer statistics
268 stat_start(struct xferstat
*xs
, const char *name
, off_t size
, off_t offset
)
270 snprintf(xs
->name
, sizeof xs
->name
, "%s", name
);
271 gettimeofday(&xs
->start
, NULL
);
272 xs
->last
.tv_sec
= xs
->last
.tv_usec
= 0;
276 if (v_tty
&& v_level
> 0)
278 else if (v_level
> 0)
279 fprintf(stderr
, "%-46s", xs
->name
);
283 * Update the transfer statistics
286 stat_update(struct xferstat
*xs
, off_t rcvd
)
289 if (v_tty
&& v_level
> 0)
294 * Finalize the transfer statistics
297 stat_end(struct xferstat
*xs
)
299 gettimeofday(&xs
->last
, NULL
);
300 if (v_tty
&& v_level
> 0) {
303 } else if (v_level
> 0) {
304 fprintf(stderr
, " %s %s\n",
305 stat_bytes(xs
->size
), stat_bps(xs
));
309 #if HAVE_TERMIOS_H && !defined(PREFER_GETPASS)
311 read_password(const char *prompt
, char *pwbuf
, size_t pwbuf_len
)
314 tcflag_t saved_flags
;
317 fprintf(stderr
, prompt
);
318 if (tcgetattr(STDIN_FILENO
, &tios
) != 0)
319 return (fgets(pwbuf
, pwbuf_len
, stdin
) == NULL
);
321 saved_flags
= tios
.c_lflag
;
322 tios
.c_lflag
&= ~ECHO
;
323 tios
.c_lflag
|= ECHONL
|ICANON
;
325 tcsetattr(STDIN_FILENO
, TCSAFLUSH
|TCSASOFT
, &tios
);
327 tcsetattr(STDIN_FILENO
, TCSAFLUSH
, &tios
);
329 nopwd
= (fgets(pwbuf
, pwbuf_len
, stdin
) == NULL
);
330 tios
.c_lflag
= saved_flags
;
332 tcsetattr(STDIN_FILENO
, TCSANOW
|TCSASOFT
, &tios
);
334 tcsetattr(STDIN_FILENO
, TCSANOW
, &tios
);
339 #elif HAVE_GETPASSPHRASE || HAVE_GETPASS
341 read_password(const char *prompt
, char *pwbuf
, size_t pwbuf_len
)
345 #if HAVE_GETPASSPHRASE && !defined(PREFER_GETPASS)
346 pass
= getpassphrase(prompt
);
348 pass
= getpass(prompt
);
350 if (pass
== NULL
|| strlen(pass
) >= pwbuf_len
)
357 read_password(const char *prompt
, char *pwbuf
, size_t pwbuf_len
)
360 fprintf(stderr
, prompt
);
361 return (fgets(pwbuf
, pwbuf_len
, stdin
) == NULL
);
366 * Ask the user for authentication details
369 query_auth(struct url
*URL
)
373 fprintf(stderr
, "Authentication required for <%s://%s:%d/>!\n",
374 URL
->scheme
, URL
->host
, URL
->port
);
376 fprintf(stderr
, "Login: ");
377 if (fgets(URL
->user
, sizeof URL
->user
, stdin
) == NULL
)
379 for (i
= strlen(URL
->user
); i
>= 0; --i
)
380 if (URL
->user
[i
] == '\r' || URL
->user
[i
] == '\n')
383 nopwd
= read_password("Password: ", URL
->pwd
, sizeof(URL
->pwd
));
387 for (i
= strlen(URL
->pwd
); i
>= 0; --i
)
388 if (URL
->pwd
[i
] == '\r' || URL
->pwd
[i
] == '\n')
398 fetch(char *URL
, const char *path
)
423 /* set verbosity level */
430 if ((url
= fetchParseURL(URL
)) == NULL
) {
431 warnx("%s: parse error", URL
);
435 /* if no scheme was specified, take a guess */
438 strcpy(url
->scheme
, SCHEME_FILE
);
439 else if (strncasecmp(url
->host
, "ftp.", 4) == 0)
440 strcpy(url
->scheme
, SCHEME_FTP
);
441 else if (strncasecmp(url
->host
, "www.", 4) == 0)
442 strcpy(url
->scheme
, SCHEME_HTTP
);
457 /* Protocol independent flags */
459 if (stat(path
, &sb
) == 0) {
460 url
->last_modified
= sb
.st_mtime
;
462 } else if (errno
!= ENOENT
) {
463 warn("%s: stat()", path
);
468 /* FTP specific flags */
469 if (strcmp(url
->scheme
, SCHEME_FTP
) == 0) {
474 timeout
= T_secs
? T_secs
: ftp_timeout
;
477 /* HTTP specific flags */
478 if (strcmp(url
->scheme
, SCHEME_HTTP
) == 0) {
483 timeout
= T_secs
? T_secs
: http_timeout
;
486 /* set the protocol timeout. */
487 fetchTimeout
= timeout
;
489 /* just print size */
493 r
= fetchStat(url
, &us
, flags
);
496 if (sigalrm
|| sigint
)
499 warnx("%s", fetchLastErrString
);
505 printf("%jd\n", (intmax_t)us
.size
);
510 * If the -r flag was specified, we have to compare the local
511 * and remote files, so we should really do a fetchStat()
512 * first, but I know of at least one HTTP server that only
513 * sends the content size in response to GET requests, and
514 * leaves it out of replies to HEAD requests. Also, in the
515 * (frequent) case that the local and remote files match but
516 * the local file is truncated, we have sufficient information
517 * before the compare to issue a correct request. Therefore,
518 * we always issue a GET request as if we were sure the local
519 * file was a truncated copy of the remote file; we can drop
520 * the connection later if we change our minds.
525 if (r
== 0 && r_flag
&& S_ISREG(sb
.st_mode
)) {
526 url
->offset
= sb
.st_size
;
527 } else if (r
== -1 || !S_ISREG(sb
.st_mode
)) {
529 * Whatever value sb.st_size has now is either
530 * wrong (if stat(2) failed) or irrelevant (if the
531 * path does not refer to a regular file)
535 if (r
== -1 && errno
!= ENOENT
) {
536 warnx("%s: stat()", path
);
541 /* start the transfer */
544 f
= fetchXGet(url
, &us
, flags
);
547 if (sigalrm
|| sigint
)
549 if (f
== NULL
&& i_flag
&& fetchLastErrCode
== FETCH_UNCHANGED
) {
550 /* URL was not modified, return OK. */
551 printf("%s: not modified\n", URL
);
556 warnx("%s: %s", URL
, fetchLastErrString
);
562 /* check that size is as expected */
565 warnx("%s: size unknown", URL
);
566 } else if (us
.size
!= S_size
) {
567 warnx("%s: size mismatch: expected %jd, actual %jd",
568 URL
, (intmax_t)S_size
, (intmax_t)us
.size
);
573 /* symlink instead of copy */
574 if (l_flag
&& strcmp(url
->scheme
, "file") == 0 && !o_stdout
) {
575 char *name
= fetchUnquotePath(url
);
577 warnx("Can't unquote URL");
580 if (symlink(name
, path
) == -1) {
581 warn("%s: symlink()", path
);
589 if (us
.size
== -1 && !o_stdout
&& v_level
> 0)
590 warnx("%s: size of remote file is not known", URL
);
592 if (sb
.st_size
!= -1)
593 fprintf(stderr
, "local size / mtime: %jd / %ld\n",
594 (intmax_t)sb
.st_size
, (long)sb
.st_mtime
);
596 fprintf(stderr
, "remote size / mtime: %jd / %ld\n",
597 (intmax_t)us
.size
, (long)us
.mtime
);
600 /* open output file */
602 /* output to stdout */
604 } else if (r_flag
&& sb
.st_size
!= -1) {
605 /* resume mode, local file exists */
606 if (!F_flag
&& us
.mtime
&& sb
.st_mtime
!= us
.mtime
) {
607 /* no match! have to refetch */
609 /* if precious, warn the user and give up */
611 warnx("%s: local modification time "
612 "does not match remote", path
);
615 } else if (us
.size
!= -1) {
616 if (us
.size
== sb
.st_size
)
619 if (sb
.st_size
> us
.size
) {
620 /* local file too long! */
621 warnx("%s: local file (%jd bytes) is longer "
622 "than remote file (%jd bytes)", path
,
623 (intmax_t)sb
.st_size
, (intmax_t)us
.size
);
626 /* we got it, open local file */
627 if ((of
= fopen(path
, "a")) == NULL
) {
628 warn("%s: fopen()", path
);
631 /* check that it didn't move under our feet */
632 if (fstat(fileno(of
), &nsb
) == -1) {
634 warn("%s: fstat()", path
);
637 if (nsb
.st_dev
!= sb
.st_dev
||
638 nsb
.st_ino
!= nsb
.st_ino
||
639 nsb
.st_size
!= sb
.st_size
) {
640 warnx("%s: file has changed", URL
);
646 } else if (m_flag
&& sb
.st_size
!= -1) {
647 /* mirror mode, local file exists */
648 if (sb
.st_size
== us
.size
&& sb
.st_mtime
== us
.mtime
)
654 * We don't yet have an output file; either this is a
655 * vanilla run with no special flags, or the local and
656 * remote files didn't match.
659 if (url
->offset
> 0) {
661 * We tried to restart a transfer, but for
662 * some reason gave up - so we have to restart
663 * from scratch if we want the whole file
666 if ((f
= fetchXGet(url
, &us
, flags
)) == NULL
) {
667 warnx("%s: %s", URL
, fetchLastErrString
);
674 /* construct a temp file name */
675 if (sb
.st_size
!= -1 && S_ISREG(sb
.st_mode
)) {
677 asprintf(&tmppath
, "%s.fetch.XXXXXX", path
);
681 if((tmppath
= malloc(sizeof(char)*MINBUFSIZE
)) != NULL
) {
682 len
= snprintf(tmppath
, MINBUFSIZE
, "%s.fetch.XXXXXX", path
);
683 if(len
>= MINBUFSIZE
) {
691 if (tmppath
!= NULL
) {
694 fd
= mkstemp(tmppath
);
696 warn("%s: mkstemp failed", tmppath
);
699 fchown(fd
, sb
.st_uid
, sb
.st_gid
);
700 fchmod(fd
, sb
.st_mode
& ALLPERMS
);
701 of
= fdopen(fd
, "w");
711 of
= fopen(path
, "w");
713 warn("%s: open()", path
);
719 /* start the counter */
720 stat_start(&xs
, path
, us
.size
, count
);
722 sigalrm
= sigint
= 0;
724 /* suck in the data */
727 signal(SIGINFO
, sig_handler
);
730 if (us
.size
!= -1 && us
.size
- count
< B_size
&&
731 us
.size
- count
>= 0)
732 size
= us
.size
- count
;
737 stat_display(&xs
, 1);
741 /* Constant info is better than none. */
743 stat_display(&xs
, 1);
746 if ((ssize
= fetchIO_read(f
, buf
, B_size
)) == 0)
748 if (ssize
== -1 && errno
== EINTR
)
753 stat_update(&xs
, count
+= size
);
754 for (ptr
= buf
; size
> 0; ptr
+= wr
, size
-= wr
) {
755 if ((wr
= fwrite(ptr
, 1, size
, of
)) < size
) {
756 if (ferror(of
) && errno
== EINTR
&& !sigint
)
768 signal(SIGINFO
, SIG_DFL
);
774 * If the transfer timed out or was interrupted, we still want to
775 * set the mtime in case the file is not removed (-r or -R) and
776 * the user later restarts the transfer.
779 /* set mtime of local file */
781 if (!n_flag
&& us
.mtime
&& !o_stdout
&& of
!= NULL
&&
782 (stat(path
, &sb
) != -1) && sb
.st_mode
& S_IFREG
) {
783 struct timeval tv
[2];
786 tv
[0].tv_sec
= (long)(us
.atime
? us
.atime
: us
.mtime
);
787 tv
[1].tv_sec
= (long)us
.mtime
;
788 tv
[0].tv_usec
= tv
[1].tv_usec
= 0;
789 if (utimes(tmppath
? tmppath
: path
, tv
))
790 warn("%s: utimes()", tmppath
? tmppath
: path
);
793 if (!n_flag
&& us
.mtime
&& !o_stdout
&& of
!= NULL
&&
794 (stat(path
, &sb
) != -1) && sb
.st_mode
& S_IFREG
) {
798 ut
.actime
= (us
.atime
? us
.atime
: us
.mtime
);
799 ut
.modtime
= us
.mtime
;
801 if (utime(tmppath
? tmppath
: path
, &ut
))
802 warn("%s: utime()", tmppath
? tmppath
: path
);
806 /* timed out or interrupted? */
807 if (fetchLastErrCode
== FETCH_TIMEOUT
)
810 warnx("transfer timed out");
812 warnx("transfer interrupted");
816 /* timeout / interrupt before connection completley established? */
820 if (!sigalrm
&& ferror(of
)) {
821 /* check the status of our files */
822 warn("writing to %s failed", path
);
826 /* did the transfer complete normally? */
827 if (us
.size
!= -1 && count
< us
.size
) {
828 warnx("%s appears to be truncated: %jd/%jd bytes",
829 path
, (intmax_t)count
, (intmax_t)us
.size
);
834 * If the transfer timed out and we didn't know how much to
835 * expect, assume the worst (i.e. we didn't get all of it)
837 if (sigalrm
&& us
.size
== -1) {
838 warnx("%s may be truncated", path
);
844 if (tmppath
!= NULL
&& rename(tmppath
, path
) == -1) {
845 warn("%s: rename()", path
);
850 if (of
&& of
!= stdout
&& !R_flag
&& !r_flag
)
851 if (stat(path
, &sb
) != -1 && (sb
.st_mode
& S_IFREG
))
852 unlink(tmppath
? tmppath
: path
);
853 if (R_flag
&& tmppath
!= NULL
&& sb
.st_size
== -1)
854 rename(tmppath
, path
); /* ignore errors here */
861 if (of
&& of
!= stdout
)
874 fprintf(stderr
, "%s\n%s\n%s\n",
875 "usage: fetch [-146AFMPRUadilmnpqrsv] [-N netrc] [-o outputfile]",
876 " [-S bytes] [-B bytes] [-T seconds] [-w seconds]",
877 " [-h host -f file [-c dir] | URL ...]");
879 fprintf(stderr
, "%s\n%s\n%s\n",
880 "usage: fetch [-146AFMPRUadilmnpqrsv] [-N netrc] [-o outputfile]",
881 " [-S bytes] [-B bytes] [-T seconds] [-w seconds]",
882 " [-h host -f file [-c dir] | URL ...]");
891 main(int argc
, char *argv
[])
899 while ((c
= getopt(argc
, argv
,
900 "14AaB:dFilMmN:no:qRrS:sT:Uvw:")) != -1)
902 while ((c
= getopt(argc
, argv
,
903 "146AaB:dFilMmN:no:qRrS:sT:Uvw:")) != -1)
924 B_size
= (off_t
)strtol(optarg
, &end
, 10);
925 if (*optarg
== '\0' || *end
!= '\0')
926 errx(1, "invalid buffer size (%s)", optarg
);
947 errx(1, "the -m and -r flags "
948 "are mutually exclusive");
965 errx(1, "the -m and -r flags "
966 "are mutually exclusive");
970 S_size
= (off_t
)strtol(optarg
, &end
, 10);
971 if (*optarg
== '\0' || *end
!= '\0')
972 errx(1, "invalid size (%s)", optarg
);
978 T_secs
= strtol(optarg
, &end
, 10);
979 if (*optarg
== '\0' || *end
!= '\0')
980 errx(1, "invalid timeout (%s)", optarg
);
990 w_secs
= strtol(optarg
, &end
, 10);
991 if (*optarg
== '\0' || *end
!= '\0')
992 errx(1, "invalid delay (%s)", optarg
);
1007 fetchConnectionCacheInit(10, 1);
1009 /* allocate buffer */
1010 if (B_size
< MINBUFSIZE
)
1011 B_size
= MINBUFSIZE
;
1012 if ((buf
= malloc(B_size
)) == NULL
)
1013 errx(1, "%s", strerror(ENOMEM
));
1016 if ((s
= getenv("FTP_TIMEOUT")) != NULL
) {
1017 ftp_timeout
= strtol(s
, &end
, 10);
1018 if (*s
== '\0' || *end
!= '\0' || ftp_timeout
< 0) {
1019 warnx("FTP_TIMEOUT (%s) is not a positive integer", s
);
1023 if ((s
= getenv("HTTP_TIMEOUT")) != NULL
) {
1024 http_timeout
= strtol(s
, &end
, 10);
1025 if (*s
== '\0' || *end
!= '\0' || http_timeout
< 0) {
1026 warnx("HTTP_TIMEOUT (%s) is not a positive integer", s
);
1031 /* signal handling */
1033 sa
.sa_handler
= sig_handler
;
1034 sigemptyset(&sa
.sa_mask
);
1035 sigaction(SIGALRM
, &sa
, NULL
);
1036 sa
.sa_flags
= SA_RESETHAND
;
1037 sigaction(SIGINT
, &sa
, NULL
);
1041 if (strcmp(o_filename
, "-") == 0) {
1044 warnx("-i and -o - are incompatible, dropping -i");
1047 } else if (stat(o_filename
, &sb
) == -1) {
1048 if (errno
== ENOENT
) {
1050 errx(EX_USAGE
, "%s is not a directory",
1053 err(EX_IOERR
, "%s", o_filename
);
1056 if (sb
.st_mode
& S_IFDIR
)
1061 /* check if output is to a tty (for progress report) */
1062 v_tty
= isatty(STDERR_FILENO
);
1068 /* authentication */
1070 fetchAuthMethod
= query_auth
;
1071 if (N_filename
!= NULL
)
1072 setenv("NETRC", N_filename
, 1);
1075 if ((p
= strrchr(*argv
, '/')) == NULL
)
1083 fetchLastErrCode
= 0;
1087 e
= fetch(*argv
, "-");
1088 } else if (o_directory
) {
1090 asprintf(&q
, "%s/%s", o_filename
, p
);
1095 if ((q
= malloc(sizeof(char)*MINBUFSIZE
)) != NULL
) {
1096 len
= snprintf(q
, MINBUFSIZE
, "%s/%s", o_filename
, p
);
1097 if (len
>= MINBUFSIZE
) {
1102 err(1, "Unable to allocate memory");
1106 e
= fetch(*argv
, q
);
1109 e
= fetch(*argv
, o_filename
);
1112 e
= fetch(*argv
, p
);
1116 kill(getpid(), SIGINT
);
1118 if (e
== 0 && once_flag
)
1123 if ((fetchLastErrCode
1124 && fetchLastErrCode
!= FETCH_UNAVAIL
1125 && fetchLastErrCode
!= FETCH_MOVED
1126 && fetchLastErrCode
!= FETCH_URL
1127 && fetchLastErrCode
!= FETCH_RESOLV
1128 && fetchLastErrCode
!= FETCH_UNKNOWN
)) {
1129 if (w_secs
&& v_level
)
1130 fprintf(stderr
, "Waiting %ld seconds "
1131 "before retrying\n", w_secs
);