• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 1997-8 Andrew G. Morgan <morgan@kernel.org>
3  *
4  * This is a file to make the capability <-> string mappings for
5  * libcap.
6  */
7 
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <sys/capability.h>
11 
12 /*
13  * #include 'sed' generated array
14  */
15 
16 struct {
17     const char *name;
18     int index;
19 } const list[] = {
20 #include "cap_names.list.h"
21     {NULL, -1}
22 };
23 
24 /* this should be more than big enough (factor of three at least) */
25 const char *pointers[8*sizeof(struct __user_cap_data_struct)];
26 
main(void)27 int main(void)
28 {
29     int i, maxcaps=0;
30 
31     for ( i=0; list[i].index >= 0 && list[i].name; ++i ) {
32 	if (maxcaps <= list[i].index) {
33 	    maxcaps = list[i].index + 1;
34 	}
35 	pointers[list[i].index] = list[i].name;
36     }
37 
38     printf("/*\n"
39 	   " * DO NOT EDIT: this file is generated automatically from\n"
40 	   " *\n"
41 	   " *     <linux/capability.h>\n"
42 	   " */\n"
43 	   "#define __CAP_BITS   %d\n"
44 	   "\n"
45 	   "#ifdef LIBCAP_PLEASE_INCLUDE_ARRAY\n"
46 	   "  char const *_cap_names[__CAP_BITS] = {\n", maxcaps);
47 
48     for (i=0; i<maxcaps; ++i) {
49 	if (pointers[i])
50 	    printf("      /* %d */\t\"%s\",\n", i, pointers[i]);
51 	else
52 	    printf("      /* %d */\tNULL,\t\t/* - presently unused */\n", i);
53     }
54 
55     printf("  };\n"
56 	   "#endif /* LIBCAP_PLEASE_INCLUDE_ARRAY */\n"
57 	   "\n"
58 	   "/* END OF FILE */\n");
59 
60     exit(0);
61 }
62