Cleaned up error message handling.
This commit is contained in:
parent
324a778f31
commit
97d2612566
@ -98,7 +98,7 @@ int wget_main(int argc, char **argv)
|
|||||||
|
|
||||||
|
|
||||||
if (do_continue && !fname_out)
|
if (do_continue && !fname_out)
|
||||||
fatalError("wget: cannot specify continue (-c) without a filename (-O)\n");
|
fatalError("cannot specify continue (-c) without a filename (-O)\n");
|
||||||
/*
|
/*
|
||||||
* Parse url into components.
|
* Parse url into components.
|
||||||
*/
|
*/
|
||||||
@ -115,7 +115,7 @@ int wget_main(int argc, char **argv)
|
|||||||
if (fname_out != NULL) {
|
if (fname_out != NULL) {
|
||||||
if ( (output=fopen(fname_out, (do_continue ? "a" : "w")))
|
if ( (output=fopen(fname_out, (do_continue ? "a" : "w")))
|
||||||
== NULL)
|
== NULL)
|
||||||
fatalError("wget: freopen(%s): %s\n", fname_out, strerror(errno));
|
fatalPerror("fopen(%s)", fname_out);
|
||||||
} else {
|
} else {
|
||||||
output=stdout;
|
output=stdout;
|
||||||
}
|
}
|
||||||
@ -126,7 +126,7 @@ int wget_main(int argc, char **argv)
|
|||||||
if (do_continue) {
|
if (do_continue) {
|
||||||
struct stat sbuf;
|
struct stat sbuf;
|
||||||
if (fstat(fileno(output), &sbuf) < 0)
|
if (fstat(fileno(output), &sbuf) < 0)
|
||||||
fatalError("wget: fstat(): %s\n", strerror(errno));
|
fatalError("fstat()");
|
||||||
if (sbuf.st_size > 0)
|
if (sbuf.st_size > 0)
|
||||||
beg_range = sbuf.st_size;
|
beg_range = sbuf.st_size;
|
||||||
else
|
else
|
||||||
@ -145,7 +145,7 @@ int wget_main(int argc, char **argv)
|
|||||||
* Retrieve HTTP response line and check for "200" status code.
|
* Retrieve HTTP response line and check for "200" status code.
|
||||||
*/
|
*/
|
||||||
if (fgets(buf, sizeof(buf), sfp) == NULL)
|
if (fgets(buf, sizeof(buf), sfp) == NULL)
|
||||||
fatalError("wget: no response from server\n");
|
fatalError("no response from server\n");
|
||||||
for (s = buf ; *s != '\0' && !isspace(*s) ; ++s)
|
for (s = buf ; *s != '\0' && !isspace(*s) ; ++s)
|
||||||
;
|
;
|
||||||
for ( ; isspace(*s) ; ++s)
|
for ( ; isspace(*s) ; ++s)
|
||||||
@ -154,13 +154,13 @@ int wget_main(int argc, char **argv)
|
|||||||
case 200:
|
case 200:
|
||||||
if (!do_continue)
|
if (!do_continue)
|
||||||
break;
|
break;
|
||||||
fatalError("wget: server does not support ranges\n");
|
fatalError("server does not support ranges\n");
|
||||||
case 206:
|
case 206:
|
||||||
if (do_continue)
|
if (do_continue)
|
||||||
break;
|
break;
|
||||||
/*FALLTHRU*/
|
/*FALLTHRU*/
|
||||||
default:
|
default:
|
||||||
fatalError("wget: server returned error: %s", buf);
|
fatalError("server returned error: %s", buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -173,7 +173,7 @@ int wget_main(int argc, char **argv)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (strcmp(buf, "transfer-encoding") == 0) {
|
if (strcmp(buf, "transfer-encoding") == 0) {
|
||||||
fatalError("wget: server wants to do %s transfer encoding\n", s);
|
fatalError("server wants to do %s transfer encoding\n", s);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -195,7 +195,7 @@ int wget_main(int argc, char **argv)
|
|||||||
filesize -= n;
|
filesize -= n;
|
||||||
}
|
}
|
||||||
if (n == 0 && ferror(sfp))
|
if (n == 0 && ferror(sfp))
|
||||||
fatalError("wget: network read error: %s", strerror(errno));
|
fatalPerror("network read error");
|
||||||
|
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
@ -208,12 +208,12 @@ void parse_url(char *url, char **uri_host, int *uri_port, char **uri_path)
|
|||||||
*uri_port = 80;
|
*uri_port = 80;
|
||||||
|
|
||||||
if (strncmp(url, "http://", 7) != 0)
|
if (strncmp(url, "http://", 7) != 0)
|
||||||
fatalError("wget: not an http url: %s\n", url);
|
fatalError("not an http url: %s\n", url);
|
||||||
|
|
||||||
/* pull the host portion to the front of the buffer */
|
/* pull the host portion to the front of the buffer */
|
||||||
for (s = url, h = url+7 ; *h != '/' ; ++h) {
|
for (s = url, h = url+7 ; *h != '/' ; ++h) {
|
||||||
if (*h == '\0')
|
if (*h == '\0')
|
||||||
fatalError("wget: cannot parse url: %s\n", url);
|
fatalError("cannot parse url: %s\n", url);
|
||||||
if (*h == ':') {
|
if (*h == ':') {
|
||||||
*uri_port = atoi(h+1);
|
*uri_port = atoi(h+1);
|
||||||
*h = '\0';
|
*h = '\0';
|
||||||
@ -236,7 +236,7 @@ FILE *open_socket(char *host, int port)
|
|||||||
memzero(&sin, sizeof(sin));
|
memzero(&sin, sizeof(sin));
|
||||||
sin.sin_family = AF_INET;
|
sin.sin_family = AF_INET;
|
||||||
if ((hp = (struct hostent *) gethostbyname(host)) == NULL)
|
if ((hp = (struct hostent *) gethostbyname(host)) == NULL)
|
||||||
fatalError("wget: cannot resolve %s\n", host);
|
fatalError("cannot resolve %s\n", host);
|
||||||
memcpy(&sin.sin_addr, hp->h_addr_list[0], hp->h_length);
|
memcpy(&sin.sin_addr, hp->h_addr_list[0], hp->h_length);
|
||||||
sin.sin_port = htons(port);
|
sin.sin_port = htons(port);
|
||||||
|
|
||||||
@ -244,11 +244,11 @@ FILE *open_socket(char *host, int port)
|
|||||||
* Get the server onto a stdio stream.
|
* Get the server onto a stdio stream.
|
||||||
*/
|
*/
|
||||||
if ((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0)
|
if ((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0)
|
||||||
fatalError("wget: socket(): %s\n", strerror(errno));
|
fatalPerror("socket()");
|
||||||
if (connect(fd, (struct sockaddr *) &sin, sizeof(sin)) < 0)
|
if (connect(fd, (struct sockaddr *) &sin, sizeof(sin)) < 0)
|
||||||
fatalError("wget: connect(%s): %s\n", host, strerror(errno));
|
fatalPerror("connect(%s)", host);
|
||||||
if ((fp = fdopen(fd, "r+")) == NULL)
|
if ((fp = fdopen(fd, "r+")) == NULL)
|
||||||
fatalError("wget: fdopen(): %s\n", strerror(errno));
|
fatalPerror("fdopen()");
|
||||||
|
|
||||||
return fp;
|
return fp;
|
||||||
}
|
}
|
||||||
@ -277,7 +277,7 @@ char *gethdr(char *buf, size_t bufsiz, FILE *fp, int *istrunc)
|
|||||||
|
|
||||||
/* verify we are at the end of the header name */
|
/* verify we are at the end of the header name */
|
||||||
if (*s != ':')
|
if (*s != ':')
|
||||||
fatalError("wget: bad header line: %s\n", buf);
|
fatalError("bad header line: %s\n", buf);
|
||||||
|
|
||||||
/* locate the start of the header value */
|
/* locate the start of the header value */
|
||||||
for (*s++ = '\0' ; *s == ' ' || *s == '\t' ; ++s)
|
for (*s++ = '\0' ; *s == ' ' || *s == '\t' ; ++s)
|
||||||
@ -336,7 +336,7 @@ char *gethdr(char *buf, size_t bufsiz, FILE *fp, int *istrunc)
|
|||||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
* $Id: wget.c,v 1.5 2000/10/03 00:21:45 andersen Exp $
|
* $Id: wget.c,v 1.6 2000/10/25 16:25:50 kraai Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
32
wget.c
32
wget.c
@ -98,7 +98,7 @@ int wget_main(int argc, char **argv)
|
|||||||
|
|
||||||
|
|
||||||
if (do_continue && !fname_out)
|
if (do_continue && !fname_out)
|
||||||
fatalError("wget: cannot specify continue (-c) without a filename (-O)\n");
|
fatalError("cannot specify continue (-c) without a filename (-O)\n");
|
||||||
/*
|
/*
|
||||||
* Parse url into components.
|
* Parse url into components.
|
||||||
*/
|
*/
|
||||||
@ -115,7 +115,7 @@ int wget_main(int argc, char **argv)
|
|||||||
if (fname_out != NULL) {
|
if (fname_out != NULL) {
|
||||||
if ( (output=fopen(fname_out, (do_continue ? "a" : "w")))
|
if ( (output=fopen(fname_out, (do_continue ? "a" : "w")))
|
||||||
== NULL)
|
== NULL)
|
||||||
fatalError("wget: freopen(%s): %s\n", fname_out, strerror(errno));
|
fatalPerror("fopen(%s)", fname_out);
|
||||||
} else {
|
} else {
|
||||||
output=stdout;
|
output=stdout;
|
||||||
}
|
}
|
||||||
@ -126,7 +126,7 @@ int wget_main(int argc, char **argv)
|
|||||||
if (do_continue) {
|
if (do_continue) {
|
||||||
struct stat sbuf;
|
struct stat sbuf;
|
||||||
if (fstat(fileno(output), &sbuf) < 0)
|
if (fstat(fileno(output), &sbuf) < 0)
|
||||||
fatalError("wget: fstat(): %s\n", strerror(errno));
|
fatalError("fstat()");
|
||||||
if (sbuf.st_size > 0)
|
if (sbuf.st_size > 0)
|
||||||
beg_range = sbuf.st_size;
|
beg_range = sbuf.st_size;
|
||||||
else
|
else
|
||||||
@ -145,7 +145,7 @@ int wget_main(int argc, char **argv)
|
|||||||
* Retrieve HTTP response line and check for "200" status code.
|
* Retrieve HTTP response line and check for "200" status code.
|
||||||
*/
|
*/
|
||||||
if (fgets(buf, sizeof(buf), sfp) == NULL)
|
if (fgets(buf, sizeof(buf), sfp) == NULL)
|
||||||
fatalError("wget: no response from server\n");
|
fatalError("no response from server\n");
|
||||||
for (s = buf ; *s != '\0' && !isspace(*s) ; ++s)
|
for (s = buf ; *s != '\0' && !isspace(*s) ; ++s)
|
||||||
;
|
;
|
||||||
for ( ; isspace(*s) ; ++s)
|
for ( ; isspace(*s) ; ++s)
|
||||||
@ -154,13 +154,13 @@ int wget_main(int argc, char **argv)
|
|||||||
case 200:
|
case 200:
|
||||||
if (!do_continue)
|
if (!do_continue)
|
||||||
break;
|
break;
|
||||||
fatalError("wget: server does not support ranges\n");
|
fatalError("server does not support ranges\n");
|
||||||
case 206:
|
case 206:
|
||||||
if (do_continue)
|
if (do_continue)
|
||||||
break;
|
break;
|
||||||
/*FALLTHRU*/
|
/*FALLTHRU*/
|
||||||
default:
|
default:
|
||||||
fatalError("wget: server returned error: %s", buf);
|
fatalError("server returned error: %s", buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -173,7 +173,7 @@ int wget_main(int argc, char **argv)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (strcmp(buf, "transfer-encoding") == 0) {
|
if (strcmp(buf, "transfer-encoding") == 0) {
|
||||||
fatalError("wget: server wants to do %s transfer encoding\n", s);
|
fatalError("server wants to do %s transfer encoding\n", s);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -195,7 +195,7 @@ int wget_main(int argc, char **argv)
|
|||||||
filesize -= n;
|
filesize -= n;
|
||||||
}
|
}
|
||||||
if (n == 0 && ferror(sfp))
|
if (n == 0 && ferror(sfp))
|
||||||
fatalError("wget: network read error: %s", strerror(errno));
|
fatalPerror("network read error");
|
||||||
|
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
@ -208,12 +208,12 @@ void parse_url(char *url, char **uri_host, int *uri_port, char **uri_path)
|
|||||||
*uri_port = 80;
|
*uri_port = 80;
|
||||||
|
|
||||||
if (strncmp(url, "http://", 7) != 0)
|
if (strncmp(url, "http://", 7) != 0)
|
||||||
fatalError("wget: not an http url: %s\n", url);
|
fatalError("not an http url: %s\n", url);
|
||||||
|
|
||||||
/* pull the host portion to the front of the buffer */
|
/* pull the host portion to the front of the buffer */
|
||||||
for (s = url, h = url+7 ; *h != '/' ; ++h) {
|
for (s = url, h = url+7 ; *h != '/' ; ++h) {
|
||||||
if (*h == '\0')
|
if (*h == '\0')
|
||||||
fatalError("wget: cannot parse url: %s\n", url);
|
fatalError("cannot parse url: %s\n", url);
|
||||||
if (*h == ':') {
|
if (*h == ':') {
|
||||||
*uri_port = atoi(h+1);
|
*uri_port = atoi(h+1);
|
||||||
*h = '\0';
|
*h = '\0';
|
||||||
@ -236,7 +236,7 @@ FILE *open_socket(char *host, int port)
|
|||||||
memzero(&sin, sizeof(sin));
|
memzero(&sin, sizeof(sin));
|
||||||
sin.sin_family = AF_INET;
|
sin.sin_family = AF_INET;
|
||||||
if ((hp = (struct hostent *) gethostbyname(host)) == NULL)
|
if ((hp = (struct hostent *) gethostbyname(host)) == NULL)
|
||||||
fatalError("wget: cannot resolve %s\n", host);
|
fatalError("cannot resolve %s\n", host);
|
||||||
memcpy(&sin.sin_addr, hp->h_addr_list[0], hp->h_length);
|
memcpy(&sin.sin_addr, hp->h_addr_list[0], hp->h_length);
|
||||||
sin.sin_port = htons(port);
|
sin.sin_port = htons(port);
|
||||||
|
|
||||||
@ -244,11 +244,11 @@ FILE *open_socket(char *host, int port)
|
|||||||
* Get the server onto a stdio stream.
|
* Get the server onto a stdio stream.
|
||||||
*/
|
*/
|
||||||
if ((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0)
|
if ((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0)
|
||||||
fatalError("wget: socket(): %s\n", strerror(errno));
|
fatalPerror("socket()");
|
||||||
if (connect(fd, (struct sockaddr *) &sin, sizeof(sin)) < 0)
|
if (connect(fd, (struct sockaddr *) &sin, sizeof(sin)) < 0)
|
||||||
fatalError("wget: connect(%s): %s\n", host, strerror(errno));
|
fatalPerror("connect(%s)", host);
|
||||||
if ((fp = fdopen(fd, "r+")) == NULL)
|
if ((fp = fdopen(fd, "r+")) == NULL)
|
||||||
fatalError("wget: fdopen(): %s\n", strerror(errno));
|
fatalPerror("fdopen()");
|
||||||
|
|
||||||
return fp;
|
return fp;
|
||||||
}
|
}
|
||||||
@ -277,7 +277,7 @@ char *gethdr(char *buf, size_t bufsiz, FILE *fp, int *istrunc)
|
|||||||
|
|
||||||
/* verify we are at the end of the header name */
|
/* verify we are at the end of the header name */
|
||||||
if (*s != ':')
|
if (*s != ':')
|
||||||
fatalError("wget: bad header line: %s\n", buf);
|
fatalError("bad header line: %s\n", buf);
|
||||||
|
|
||||||
/* locate the start of the header value */
|
/* locate the start of the header value */
|
||||||
for (*s++ = '\0' ; *s == ' ' || *s == '\t' ; ++s)
|
for (*s++ = '\0' ; *s == ' ' || *s == '\t' ; ++s)
|
||||||
@ -336,7 +336,7 @@ char *gethdr(char *buf, size_t bufsiz, FILE *fp, int *istrunc)
|
|||||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
* $Id: wget.c,v 1.5 2000/10/03 00:21:45 andersen Exp $
|
* $Id: wget.c,v 1.6 2000/10/25 16:25:50 kraai Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user