diff options
| author | Oskari Timperi <oskari.timperi@iki.fi> | 2022-09-15 22:46:34 +0300 |
|---|---|---|
| committer | Oskari Timperi <oskari.timperi@iki.fi> | 2022-09-15 22:46:34 +0300 |
| commit | b0d3002af8bedbf7fb6a5993ac40809ec638072e (patch) | |
| tree | f0d441e18664744850c3b38b93bf7cf98099d41a | |
| parent | b28c94de104eaf984058d021cd6f2ab5f5036790 (diff) | |
| download | sqlite-http-c-b0d3002af8bedbf7fb6a5993ac40809ec638072e.tar.gz sqlite-http-c-b0d3002af8bedbf7fb6a5993ac40809ec638072e.zip | |
Remove http.h includes from amalgamation
| -rw-r--r-- | http.c | 4 | ||||
| -rw-r--r-- | src/amalgamate.c | 25 |
2 files changed, 11 insertions, 18 deletions
@@ -70,7 +70,6 @@ void separate_status_and_headers(char** ppStatus, char* zHeaders); /********** src/http.c **********/ -#include "http.h" SQLITE_EXTENSION_INIT1 @@ -866,7 +865,6 @@ __declspec(dllexport) #ifdef HTTP_BACKEND_CURL -#include "http.h" #include <assert.h> #include <string.h> @@ -1347,7 +1345,6 @@ done: #ifdef HTTP_BACKEND_DUMMY -#include "http.h" #include <assert.h> @@ -1412,7 +1409,6 @@ int http_do_request(http_request* req, http_response* resp, char** ppErrMsg) { #ifdef HTTP_BACKEND_WINHTTP -#include "http.h" #include <windows.h> #include <winhttp.h> diff --git a/src/amalgamate.c b/src/amalgamate.c index f2fdc1e..6064e91 100644 --- a/src/amalgamate.c +++ b/src/amalgamate.c @@ -1,4 +1,5 @@ #include <stdio.h> +#include <stdlib.h> #include <string.h> int main(int argc, char const* argv[]) { @@ -19,31 +20,27 @@ int main(int argc, char const* argv[]) { return 1; } + static const int bufsize = 16*1024; + char* buffer = malloc(bufsize); + for (int i = 0; i < nFilenames; ++i) { FILE* fp = fopen(aFilenames[i], "rb"); if (!fp) { fprintf(stderr, "error opening %s: %s\n", aFilenames[i], strerror(errno)); return 1; } - char buffer[512]; - size_t nread = - snprintf(buffer, sizeof(buffer), "\n/********** %s **********/\n\n", aFilenames[i]); - if (fwrite(buffer, 1, nread, fout) != nread) { + snprintf(buffer, bufsize, "\n/********** %s **********/\n\n", aFilenames[i]); + if (fwrite(buffer, 1, strlen(buffer), fout) != strlen(buffer)) { fprintf(stderr, "error writing http.c: %s\n", strerror(errno)); return 1; } - while (1) { - nread = fread(buffer, 1, sizeof(buffer), fp); - if (!nread) { - if (ferror(fp)) { - fprintf(stderr, "error reading %s: %s\n", aFilenames[i], strerror(errno)); + while (fgets(buffer, bufsize, fp)) { + size_t l = strlen(buffer); + if (strncmp(buffer, "#include \"http.h\"", 17) != 0) { + if (fwrite(buffer, 1, l, fout) != l) { + fprintf(stderr, "error writing http.c: %s\n", strerror(errno)); return 1; } - break; - } - if (fwrite(buffer, 1, nread, fout) != nread) { - fprintf(stderr, "error writing http.c: %s\n", strerror(errno)); - return 1; } } fclose(fp); |
