• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //! A small C program which prints out ioctl codes to generate a header file
2 //! that bindgen can generate bindings from.
3 
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <string.h>
7 
8 void list(void);
9 
10 static FILE *generated;
11 
entry(const char * s)12 void entry(const char *s) {
13     if (fprintf(generated, "%s\n", s) != strlen(s) + 1) {
14 	fprintf(stderr, "can't write to generated.txt: %m\n");
15 	exit(1);
16     }
17 }
18 
main(void)19 int main(void) {
20     generated = fopen("generated.txt", "w");
21     if (generated == NULL) {
22 	fprintf(stderr, "can't open generated.txt: %m\n");
23 	exit(EXIT_FAILURE);
24     }
25 
26 #if defined(__i386__)
27     printf("#ifdef __i386__\n");
28 #elif defined(__x86_64__)
29     printf("#ifdef __x86_64__\n");
30 #elif defined(__arm__)
31     printf("#ifdef __arm__\n");
32 #elif defined(__aarch64__)
33     printf("#ifdef __aarch64__\n");
34 #elif defined(__powerpc__)
35     printf("#ifdef __powerpc__\n");
36 #elif defined(__powerpc64__)
37     printf("#ifdef __powerpc64__\n");
38 #elif __mips == 32
39     printf("#if __mips == 32\n");
40 #elif __mips == 64
41     printf("#if __mips == 64\n");
42 #elif defined(__riscv) && __riscv_xlen == 64
43     printf("#if defined(__riscv) && __riscv_xlen == 64\n");
44 #else
45 #error "unimplemented architecture"
46 #endif
47 
48     list();
49 
50     int r = printf("#endif\n");
51     return r != 7;
52 }
53