aboutsummaryrefslogtreecommitdiff
path: root/src/testcurl/daemontest_get_sendfile.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/testcurl/daemontest_get_sendfile.c')
-rw-r--r--src/testcurl/daemontest_get_sendfile.c33
1 files changed, 28 insertions, 5 deletions
diff --git a/src/testcurl/daemontest_get_sendfile.c b/src/testcurl/daemontest_get_sendfile.c
index 48c543b2..5afc0a35 100644
--- a/src/testcurl/daemontest_get_sendfile.c
+++ b/src/testcurl/daemontest_get_sendfile.c
@@ -1,4 +1,3 @@
1/* DO NOT CHANGE THIS LINE */
2/* 1/*
3 This file is part of libmicrohttpd 2 This file is part of libmicrohttpd
4 (C) 2007, 2009 Christian Grothoff 3 (C) 2007, 2009 Christian Grothoff
@@ -40,7 +39,9 @@
40#include <unistd.h> 39#include <unistd.h>
41#endif 40#endif
42 41
43#define TESTSTR "/* DO NOT CHANGE THIS LINE */" 42#define TESTSTR "This is the content of the test file we are sending using sendfile (if available)"
43
44char *sourcefile;
44 45
45static int oneone; 46static int oneone;
46 47
@@ -87,11 +88,11 @@ ahc_echo (void *cls,
87 return MHD_YES; 88 return MHD_YES;
88 } 89 }
89 *unused = NULL; 90 *unused = NULL;
90 fd = open ("daemontest_get_sendfile.c", O_RDONLY); 91 fd = open (sourcefile, O_RDONLY);
91 if (fd == -1) 92 if (fd == -1)
92 { 93 {
93 fprintf (stderr, "Failed to open `%s': %s\n", 94 fprintf (stderr, "Failed to open `%s': %s\n",
94 "daemontest_get_sendfile.c", 95 sourcefile,
95 STRERROR (errno)); 96 STRERROR (errno));
96 exit (1); 97 exit (1);
97 } 98 }
@@ -452,7 +453,27 @@ int
452main (int argc, char *const *argv) 453main (int argc, char *const *argv)
453{ 454{
454 unsigned int errorCount = 0; 455 unsigned int errorCount = 0;
455 456 const char *tmp;
457 FILE *f;
458
459 if ( (NULL == (tmp = getenv ("TMPDIR"))) &&
460 (NULL == (tmp = getenv ("TMP"))) )
461 tmp = "/tmp";
462 sourcefile = malloc (strlen (tmp) + 32);
463 sprintf (sourcefile,
464 "%s%s%s",
465 tmp,
466 DIR_SEPARATOR_STR,
467 "test-mhd-sendfile");
468 f = fopen (sourcefile, "w");
469 if (NULL == f)
470 {
471 fprintf (stderr, "failed to write test file\n");
472 free (sourcefile);
473 return 1;
474 }
475 fwrite (TESTSTR, strlen (TESTSTR), 1, f);
476 fclose (f);
456 oneone = NULL != strstr (argv[0], "11"); 477 oneone = NULL != strstr (argv[0], "11");
457 if (0 != curl_global_init (CURL_GLOBAL_WIN32)) 478 if (0 != curl_global_init (CURL_GLOBAL_WIN32))
458 return 2; 479 return 2;
@@ -464,5 +485,7 @@ main (int argc, char *const *argv)
464 if (errorCount != 0) 485 if (errorCount != 0)
465 fprintf (stderr, "Error (code: %u)\n", errorCount); 486 fprintf (stderr, "Error (code: %u)\n", errorCount);
466 curl_global_cleanup (); 487 curl_global_cleanup ();
488 UNLINK (sourcefile);
489 free (sourcefile);
467 return errorCount != 0; /* 0 == pass */ 490 return errorCount != 0; /* 0 == pass */
468} 491}