strace/ioctlsort.c
Dmitry V. Levin 00119f63fa ioctlsort: rewrite build rules using noinst_PROGRAMS
* linux/ioctlsort.c: Rename to ioctlsort.c
* Makefile.am (EXTRA_DIST): Rename linux/ioctlsort.c to ioctlsort.c.
[MAINTAINER_MODE] (noinst_PROGRAMS): Add ioctlsort.
(ioctlsort_SOURCES): Add ioctlsort.c.
(nodist_ioctlsort_SOURCES): Add ioctls.h and ioctldefs.h.
(CLEANFILES): Add $(nodist_ioctlsort_SOURCES).
(ioctlsort.$(OBJEXT)): Likewise.
(ioctlsort): Remove.
2014-11-11 15:30:00 +00:00

59 lines
1.4 KiB
C

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <stdint.h>
#include <asm/ioctl.h>
#include <linux/types.h>
#include "ioctldefs.h"
#include <linux/atmioc.h>
struct ioctlent {
const char* header;
const char* name;
unsigned long code;
};
struct ioctlent ioctls[] = {
#include "ioctls.h"
};
int nioctls = sizeof(ioctls) / sizeof(ioctls[0]);
int compare(const void* a, const void* b) {
unsigned long code1 = ((struct ioctlent *) a)->code;
unsigned long code2 = ((struct ioctlent *) b)->code;
const char *name1 = ((struct ioctlent *) a)->name;
const char *name2 = ((struct ioctlent *) b)->name;
return (code1 > code2) ? 1 : (code1 < code2) ? -1 : strcmp(name1, name2);
}
static int is_not_prefix(const char *s1, const char *s2) {
size_t len = strlen(s1);
if (len > strlen(s2))
return 1;
return memcmp(s1, s2, len);
}
int main(int argc, char** argv) {
int i;
/* ioctl_lookup() only looks at the NR and TYPE bits atm. */
for (i = 0; i < nioctls; i++)
ioctls[i].code &= (_IOC_NRMASK << _IOC_NRSHIFT) |
(_IOC_TYPEMASK << _IOC_TYPESHIFT);
qsort(ioctls, nioctls, sizeof(ioctls[0]), compare);
puts("\t/* Generated by ioctlsort */");
for (i = 0; i < nioctls; i++)
if (i == 0 || ioctls[i-1].code != ioctls[i].code ||
is_not_prefix(ioctls[i-1].name, ioctls[i].name))
printf("\t{\"%s\",\t\"%s\",\t%#06lx},\n",
ioctls[i].header, ioctls[i].name, ioctls[i].code);
return 0;
}