1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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;
}
|