aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorng0@n0.is <ng0@n0.is>2019-06-05 12:34:05 +0000
committerng0@n0.is <ng0@n0.is>2019-06-05 12:34:05 +0000
commit4e2bdca5779f5b2207f3c1600c9104cb0236be7f (patch)
tree089a4a0e149aff0249a4618f8425327bdd570d89
parent8a0df3963f08cd91012170376bbe0c519c76be86 (diff)
downloadlibmicrohttpd-gsoc2019-4e2bdca5779f5b2207f3c1600c9104cb0236be7f.tar.gz
libmicrohttpd-gsoc2019-4e2bdca5779f5b2207f3c1600c9104cb0236be7f.zip
Use existing file
-rw-r--r--.hgignore1
-rw-r--r--a.txt1
-rw-r--r--response_generation_sendfile.c31
3 files changed, 15 insertions, 18 deletions
diff --git a/.hgignore b/.hgignore
index 5c59a2f..d2b5499 100644
--- a/.hgignore
+++ b/.hgignore
@@ -1,7 +1,6 @@
1syntax: glob 1syntax: glob
2 2
3a.out 3a.out
4a.txt
5 4
6build/ 5build/
7 6
diff --git a/a.txt b/a.txt
new file mode 100644
index 0000000..2e65efe
--- /dev/null
+++ b/a.txt
@@ -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