summaryrefslogtreecommitdiff
path: root/util.c
diff options
context:
space:
mode:
authorNick White <hg@njw.me.uk>2011-07-16 15:05:01 +0100
committerNick White <hg@njw.me.uk>2011-07-16 15:05:01 +0100
commitc11e80d46df7cec80de52383db6cb7d8dc7d3ce0 (patch)
tree3e516f2e4d9f7faa6dfe06d17e0d369acc6e1ae4 /util.c
parent77f8c2afc7f6a9e3f28585810104be7f13cc3503 (diff)
Simplify get() further
Diffstat (limited to 'util.c')
-rw-r--r--util.c12
1 files changed, 4 insertions, 8 deletions
diff --git a/util.c b/util.c
index ab84663..5d4e004 100644
--- a/util.c
+++ b/util.c
@@ -34,10 +34,9 @@ static int dial(char *host, char *port) {
return srv;
}
-int get(char *host, char *path, char **gotbuf) {
+int get(char *host, char *path, char **buf) {
size_t l, res;
int fd, i;
- char *buf;
char h[1024] = "\0";
FILE *srv;
@@ -48,18 +47,15 @@ int get(char *host, char *path, char **gotbuf) {
" (not mozilla)\r\nHost: %s\r\n\r\n", path, host);
fflush(srv);
- /* process headers */
while(h[0] != '\r') {
fgets(h, 1024, srv);
if(sscanf(h, "HTTP/%d.%d %d", &i, &i, &l) == 3 && l != 200)
return 1;
}
- buf = malloc(sizeof(char *) * 4096);
- for(i=0, l=0; (res = fread(buf+l, 1, 4096, srv)) > 0; l+=res, i++)
- buf = realloc(buf, sizeof(char *) * (l+4096));
-
- *gotbuf = buf;
+ *buf = malloc(sizeof(char *) * 4096);
+ for(i=0, l=0; (res = fread(*buf+l, 1, 4096, srv)) > 0; l+=res, i++)
+ *buf = realloc(*buf, sizeof(char *) * (l+4096));
return l;
}