Debian Codegraph @

vendored-meson/meson/test cases/common/105 generatorcustom/gen.c

raw
1 /* SPDX-License-Identifier: Apache-2.0 */
2 /* Copyright © 2023 Intel Corporation */
3
4 #include <stdio.h>
5 #include <stdlib.h>
6
7 int main(int argc, const char ** argv) {
8 if (argc != 3) {
9 fprintf(stderr, "%s %i %s\n", "Got incorrect number of arguments, got ", argc - 1, ", but expected 2");
10 exit(1);
11 }
12
13 FILE * input, * output;
14
15 if ((input = fopen(argv[1], "rb")) == NULL) {
16 exit(1);
17 }
18 if ((output = fopen(argv[2], "wb")) == NULL) {
19 exit(1);
20 }
21
22 fprintf(output, "#pragma once\n");
23 fprintf(output, "#define ");
24
25 int bytes_copied = 0;
26 int c;
27 while((c = fgetc(input)) != EOF) {
28 if(fputc(c, output) == EOF) {
29 fprintf(stderr, "Writing to output file failed.\n");
30 return 1;
31 }
32 if(++bytes_copied > 10000) {
33 fprintf(stderr, "File copy stuck in an eternal loop!\n");
34 return 1;
35 }
36 }
37 fputc('\n', output);
38
39 fclose(input);
40 fclose(output);
41
42 return 0;
43 }