diff --git a/mongoose.c b/mongoose.c index 4f28969d..0c1df381 100644 --- a/mongoose.c +++ b/mongoose.c @@ -691,7 +691,7 @@ int mg_http_upload(struct mg_connection *c, struct mg_http_message *hm, snprintf(path, sizeof(path), "%s%c%s", dir, MG_DIRSEP, name); LOG(LL_DEBUG, ("%p %d bytes @ %d [%s]", c->fd, (int) hm->body.len, (int) oft, name)); - if ((fp = fopen(path, oft == 0 ? "wb" : "a")) == NULL) { + if ((fp = fopen(path, oft == 0 ? "wb" : "ab")) == NULL) { mg_http_reply(c, 400, "", "fopen(%s): %d", name, errno); return -2; } else { diff --git a/src/http.c b/src/http.c index b0a7258a..9d81fbc6 100644 --- a/src/http.c +++ b/src/http.c @@ -271,7 +271,7 @@ int mg_http_upload(struct mg_connection *c, struct mg_http_message *hm, snprintf(path, sizeof(path), "%s%c%s", dir, MG_DIRSEP, name); LOG(LL_DEBUG, ("%p %d bytes @ %d [%s]", c->fd, (int) hm->body.len, (int) oft, name)); - if ((fp = fopen(path, oft == 0 ? "wb" : "a")) == NULL) { + if ((fp = fopen(path, oft == 0 ? "wb" : "ab")) == NULL) { mg_http_reply(c, 400, "", "fopen(%s): %d", name, errno); return -2; } else { diff --git a/test/unit_test.c b/test/unit_test.c index 0a233d9e..c069a830 100644 --- a/test/unit_test.c +++ b/test/unit_test.c @@ -574,8 +574,12 @@ static void test_http_server(void) { "POST /upload?name=uploaded.txt HTTP/1.0\r\n" "Content-Length: 5\r\n" "\r\nhello") == 200); + ASSERT(fetch(&mgr, buf, url, + "POST /upload?name=uploaded.txt&offset=5 HTTP/1.0\r\n" + "Content-Length: 6\r\n" + "\r\n\nworld") == 200); ASSERT((p = mg_file_read("uploaded.txt")) != NULL); - ASSERT(strcmp(p, "hello") == 0); + ASSERT(strcmp(p, "hello\nworld") == 0); free(p); remove("uploaded.txt"); }