diff options
author | Nick White <hg@njw.me.uk> | 2011-07-16 15:05:01 +0100 |
---|---|---|
committer | Nick White <hg@njw.me.uk> | 2011-07-16 15:05:01 +0100 |
commit | c11e80d46df7cec80de52383db6cb7d8dc7d3ce0 (patch) | |
tree | 3e516f2e4d9f7faa6dfe06d17e0d369acc6e1ae4 /util.c | |
parent | 77f8c2afc7f6a9e3f28585810104be7f13cc3503 (diff) |
Simplify get() further
Diffstat (limited to 'util.c')
-rw-r--r-- | util.c | 12 |
1 files changed, 4 insertions, 8 deletions
@@ -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; } |