summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick White <nick.white@proporta.com>2011-08-18 15:26:09 +0100
committerNick White <nick.white@proporta.com>2011-08-18 15:26:09 +0100
commit4f88334bc8752c34ff5d3bd545a6dcb35fc5faee (patch)
treee6eff129c3f8864e7a81c2e4b1c80a0226aaa645
parentbcf32c0a39647db4ebd1689bb04150e9b366fc1c (diff)
Final windows fixes; working with mingw now
-rw-r--r--util.c21
1 files changed, 15 insertions, 6 deletions
diff --git a/util.c b/util.c
index 4fd2a8b..825a269 100644
--- a/util.c
+++ b/util.c
@@ -19,6 +19,14 @@ int dial(char *host, char *port) {
int srv;
struct addrinfo *res, *r;
+ #ifdef WINVER
+ WSADATA w;
+ if(WSAStartup(MAKEWORD(2,2), &w)!= 0) {
+ fprintf(stderr, "error: failed to start winsock\n");
+ return -1;
+ }
+ #endif
+
memset(&hints, 0, sizeof hints);
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
@@ -64,9 +72,10 @@ int get(char *host, char *path, char *sendcookie, char *savecookie, char **buf)
return 0;
if(savecookie != NULL && sscanf(t, "Set-Cookie: %s;", c))
strncat(savecookie, c, COOKIEMAX);
- if((t2 = strstr(t, "\r\n\r\n") + 4)) {
- *(t2-1) = '\0';
- l = res - strlen(t) - 1;
+ t2 = strstr(t, "\r\n\r\n");
+ if(t2) {
+ t2+=4;
+ l = res - (t2 - t);
*buf = malloc(sizeof(char *) * l);
memcpy(*buf, t2, l);
break;
@@ -89,13 +98,13 @@ int gettofile(char *host, char *url, char *sendcookie, char *savecookie, char *s
fprintf(stderr, "Could not download %s\n", url);
return 1;
}
- if((f = fopen(savepath, "w")) == NULL) {
+ if((f = fopen(savepath, "wb")) == NULL) {
fprintf(stderr, "Could not create file %s\n", savepath);
free(buf); return 1;
}
- for(i=0; i < l; i+=512)
- if(!fwrite(buf+i, l-i > 512 ? 512 : l-i, 1, f)) {
+ for(i=0; i < l; i+=BUFSIZ)
+ if(!fwrite(buf+i, l-i > BUFSIZ ? BUFSIZ : l-i, 1, f)) {
fprintf(stderr, "Error writing file %s\n", savepath);
free(buf); fclose(f); return 1;
}