]> granicus.if.org Git - strace/blobdiff - ioctl.c
Convert ioctl_next_match() to new-style C function definition
[strace] / ioctl.c
diff --git a/ioctl.c b/ioctl.c
index 2af2743e125aaa784962779cf1d3578f676d05ce..122f31ab7c269dbb298642edcd604f867d6010fd 100644 (file)
--- a/ioctl.c
+++ b/ioctl.c
 
 #include "defs.h"
 
-struct ioctlent ioctlent0[] = {
-/*
- * `ioctlent.h' may be generated from `ioctlent.raw' by the auxiliary
- * program `ioctlsort', such that the list is sorted by the `code' field.
- * This has the side-effect of resolving the _IO.. macros into
- * plain integers, eliminating the need to include here everything
- * in "/usr/include" .
- */
-#include "ioctlent.h"
-};
-
 #ifdef LINUX
 #include <asm/ioctl.h>
 #endif
 
-int nioctlents0 = sizeof ioctlent0 / sizeof ioctlent0[0];
-
-#if SUPPORTED_PERSONALITIES >= 2
-struct ioctlent ioctlent1[] = {
-#include "ioctlent1.h"
-};
-
-int nioctlents1 = sizeof ioctlent1 / sizeof ioctlent1[0];
-#endif /* SUPPORTED_PERSONALITIES >= 2 */
-
-#if SUPPORTED_PERSONALITIES >= 3
-struct ioctlent ioctlent2[] = {
-#include "ioctlent2.h"
-};
-
-int nioctlents1 = sizeof ioctlent2 / sizeof ioctlent2[0];
-#endif /* SUPPORTED_PERSONALITIES >= 3 */
-
-struct ioctlent *ioctlent;
-int nioctlents;
-
 static int
-compare(a, b)
-const void *a;
-const void *b;
+compare(const void *a, const void *b)
 {
        unsigned long code1 = ((struct ioctlent *) a)->code;
        unsigned long code2 = ((struct ioctlent *) b)->code;
        return (code1 > code2) ? 1 : (code1 < code2) ? -1 : 0;
 }
 
-char *
-ioctl_lookup(code)
-long code;
+const struct ioctlent *
+ioctl_lookup(long code)
 {
        struct ioctlent *iop, ioent;
 
@@ -90,17 +55,31 @@ long code;
 #endif
        iop = (struct ioctlent *) bsearch((char *) &ioent, (char *) ioctlent,
                        nioctlents, sizeof(struct ioctlent), compare);
-       return iop ? iop->symbol : NULL;
+       while (iop > ioctlent)
+               if ((--iop)->code != ioent.code) {
+                       iop++;
+                       break;
+               }
+       return iop;
+}
+
+const struct ioctlent *
+ioctl_next_match(const struct ioctlent *iop)
+{
+       long code;
+
+       code = (iop++)->code;
+       if (iop < ioctlent + nioctlents && iop->code == code)
+               return iop;
+       return NULL;
 }
 
 int
-ioctl_decode(tcp, code, arg)
-struct tcb *tcp;
-long code, arg;
+ioctl_decode(struct tcb *tcp, long code, long arg)
 {
        switch ((code >> 8) & 0xff) {
 #ifdef LINUX
-#ifdef ALPHA
+#if defined(ALPHA) || defined(POWERPC)
        case 'f': case 't': case 'T':
 #else /* !ALPHA */
        case 0x54:
@@ -113,9 +92,9 @@ long code, arg;
        case 0x89:
 #else /* !LINUX */
        case 'r': case 's': case 'i':
-#ifndef FREEBSD                
+#ifndef FREEBSD
        case 'p':
-#endif         
+#endif
 #endif /* !LINUX */
                return sock_ioctl(tcp, code, arg);
 #ifdef USE_PROCFS
@@ -124,7 +103,7 @@ long code, arg;
        case 'q':
 #else
        case 'p':
-#endif         
+#endif
                return proc_ioctl(tcp, code, arg);
 #endif
 #endif /* USE_PROCFS */
@@ -132,6 +111,15 @@ long code, arg;
        case 'S':
                return stream_ioctl(tcp, code, arg);
 #endif /* HAVE_SYS_STREAM_H */
+#ifdef LINUX
+       case 'p':
+               return rtc_ioctl(tcp, code, arg);
+       case 0x03:
+       case 0x12:
+               return block_ioctl(tcp, code, arg);
+       case 0x22:
+               return scsi_ioctl(tcp, code, arg);
+#endif
        default:
                break;
        }
@@ -185,4 +173,3 @@ long code, arg;
  *
  * End of Registry
  */
-