diff options
| author | Oskari Timperi <oskari.timperi@iki.fi> | 2022-09-15 19:35:27 +0300 |
|---|---|---|
| committer | Oskari Timperi <oskari.timperi@iki.fi> | 2022-09-15 19:39:50 +0300 |
| commit | ff34cebaa50ebac63643a5e58989e416e09de4b9 (patch) | |
| tree | 5118bf17a9ca08cad49388b8847c2c0e0f3d035e /src/amalgamate.c | |
| download | sqlite-http-c-ff34cebaa50ebac63643a5e58989e416e09de4b9.tar.gz sqlite-http-c-ff34cebaa50ebac63643a5e58989e416e09de4b9.zip | |
Initial commit
Diffstat (limited to 'src/amalgamate.c')
| -rw-r--r-- | src/amalgamate.c | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/src/amalgamate.c b/src/amalgamate.c new file mode 100644 index 0000000..f2fdc1e --- /dev/null +++ b/src/amalgamate.c @@ -0,0 +1,55 @@ +#include <stdio.h> +#include <string.h> + +int main(int argc, char const* argv[]) { + static const char* aFilenames[] = { + "src/http.h", + "src/http.c", + "src/http_backend_curl.c", + "src/http_backend_dummy.c", + "src/http_backend_winhttp.c", + "src/http_next_header.c", + }; + + static const int nFilenames = sizeof(aFilenames) / sizeof(aFilenames[0]); + + FILE* fout = fopen("http.c", "wb"); + if (!fout) { + fprintf(stderr, "error opening http.c: %s\n", strerror(errno)); + return 1; + } + + 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) { + 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)); + return 1; + } + break; + } + if (fwrite(buffer, 1, nread, fout) != nread) { + fprintf(stderr, "error writing http.c: %s\n", strerror(errno)); + return 1; + } + } + fclose(fp); + } + + fclose(fout); + + return 0; +}
\ No newline at end of file |
