]> granicus.if.org Git - strace/blob - ioctlsort.c
Include <sys/uio.h> unconditionally
[strace] / ioctlsort.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <sys/types.h>
5 #include <stdint.h>
6
7 #include <asm/ioctl.h>
8 #include <linux/types.h>
9
10 #include "ioctldefs.h"
11 #include <linux/atmioc.h>
12
13 struct ioctlent {
14         const char*     header;
15         const char*     name;
16         unsigned long   code;
17 };
18
19 struct ioctlent ioctls[] = {
20 #include "ioctls.h"
21 };
22
23 int nioctls = sizeof(ioctls) / sizeof(ioctls[0]);
24
25 int compare(const void* a, const void* b) {
26         unsigned long code1 = ((struct ioctlent *) a)->code;
27         unsigned long code2 = ((struct ioctlent *) b)->code;
28         const char *name1 = ((struct ioctlent *) a)->name;
29         const char *name2 = ((struct ioctlent *) b)->name;
30         return (code1 > code2) ? 1 : (code1 < code2) ? -1 : strcmp(name1, name2);
31 }
32
33 static int is_not_prefix(const char *s1, const char *s2) {
34         size_t len = strlen(s1);
35
36         if (len > strlen(s2))
37                 return 1;
38         return memcmp(s1, s2, len);
39 }
40
41 int main(int argc, char** argv) {
42         int i;
43
44         /* ioctl_lookup() only looks at the NR and TYPE bits atm. */
45         for (i = 0; i < nioctls; i++)
46                 ioctls[i].code &= (_IOC_NRMASK << _IOC_NRSHIFT) |
47                                   (_IOC_TYPEMASK << _IOC_TYPESHIFT);
48
49         qsort(ioctls, nioctls, sizeof(ioctls[0]), compare);
50         puts("\t/* Generated by ioctlsort */");
51         for (i = 0; i < nioctls; i++)
52                 if (i == 0 || ioctls[i-1].code != ioctls[i].code ||
53                     is_not_prefix(ioctls[i-1].name, ioctls[i].name))
54                         printf("\t{\"%s\",\t\"%s\",\t%#06lx},\n",
55                                 ioctls[i].header, ioctls[i].name, ioctls[i].code);
56
57         return 0;
58 }