diff options
author | ng0@n0.is <ng0@n0.is> | 2019-06-05 12:34:05 +0000 |
---|---|---|
committer | ng0@n0.is <ng0@n0.is> | 2019-06-05 12:34:05 +0000 |
commit | 4e2bdca5779f5b2207f3c1600c9104cb0236be7f (patch) | |
tree | 089a4a0e149aff0249a4618f8425327bdd570d89 | |
parent | 8a0df3963f08cd91012170376bbe0c519c76be86 (diff) | |
download | libmicrohttpd-gsoc2019-4e2bdca5779f5b2207f3c1600c9104cb0236be7f.tar.gz libmicrohttpd-gsoc2019-4e2bdca5779f5b2207f3c1600c9104cb0236be7f.zip |
Use existing file
-rw-r--r-- | .hgignore | 1 | ||||
-rw-r--r-- | a.txt | 1 | ||||
-rw-r--r-- | response_generation_sendfile.c | 31 |
3 files changed, 15 insertions, 18 deletions
@@ -1,7 +1,6 @@ | |||
1 | syntax: glob | 1 | syntax: glob |
2 | 2 | ||
3 | a.out | 3 | a.out |
4 | a.txt | ||
5 | 4 | ||
6 | build/ | 5 | build/ |
7 | 6 | ||
@@ -0,0 +1 @@ | |||
a \ No newline at end of file | |||
diff --git a/response_generation_sendfile.c b/response_generation_sendfile.c index 46e4389..c94ed96 100644 --- a/response_generation_sendfile.c +++ b/response_generation_sendfile.c | |||
@@ -25,29 +25,26 @@ answer_to_connection (void *cls, | |||
25 | struct MHD_Response *response; | 25 | struct MHD_Response *response; |
26 | int ret; | 26 | int ret; |
27 | int fd; | 27 | int fd; |
28 | static int aptr; | ||
29 | if ((0 != strcmp (method, MHD_HTTP_METHOD_GET)) && | 28 | if ((0 != strcmp (method, MHD_HTTP_METHOD_GET)) && |
30 | (0 != strcmp (method, MHD_HTTP_METHOD_HEAD))) | 29 | (0 != strcmp (method, MHD_HTTP_METHOD_HEAD))) |
31 | return MHD_NO; | 30 | return MHD_NO; |
32 | FILE *fp; | 31 | if ((-1 == (fd = open ("a.txt", O_RDONLY))) || (0 != fstat (fd, &buf))) |
33 | if ((fp = fopen ("a.txt", "w")) == NULL) | 32 | { |
34 | return 1; | 33 | if (fd != -1) |
35 | fprintf (fp, "a"); | 34 | close (fd); |
36 | fclose (fp); | 35 | return 1; // error |
37 | const char *file = "./a.txt"; | 36 | } |
38 | if ((fd = open (file, O_RDONLY)) == -1) | ||
39 | return 1; | ||
40 | response = MHD_create_response_from_fd64 (buf.st_size, fd); | 37 | response = MHD_create_response_from_fd64 (buf.st_size, fd); |
41 | //if (NULL == response) | 38 | if (NULL == response) |
42 | //{ | 39 | { |
43 | // if (0 != close (fd)) | 40 | if (0 != close (fd)) |
44 | // abort (); | 41 | abort (); |
45 | // return MHD_NO; | 42 | return MHD_NO; |
46 | //} | 43 | } |
47 | ret = MHD_queue_response (connection, MHD_HTTP_OK, response); | 44 | ret = MHD_queue_response (connection, MHD_HTTP_OK, response); |
48 | MHD_destroy_response (response); | 45 | MHD_destroy_response (response); |
49 | //if (MHD_NO == ret) | 46 | if (MHD_NO == ret) |
50 | // abort (); | 47 | abort (); |
51 | return ret; | 48 | return ret; |
52 | } | 49 | } |
53 | 50 | ||