]> granicus.if.org Git - strace/blob - tests/ioctl.c
ioctl: fix ioctl command number decoding in case of conflicts
[strace] / tests / ioctl.c
1 #ifdef HAVE_CONFIG_H
2 # include "config.h"
3 #endif
4
5 #include <fcntl.h>
6 #include <stdio.h>
7 #include <stdint.h>
8 #include <unistd.h>
9 #include <termios.h>
10 #include <sys/ioctl.h>
11
12 #ifdef HAVE_LINUX_MMTIMER_H
13 # include <linux/mmtimer.h>
14 #endif
15 #ifdef HAVE_LINUX_HIDDEV_H
16 # include <linux/hiddev.h>
17 #endif
18 #ifdef HAVE_LINUX_INPUT_H
19 # include <linux/input.h>
20 #endif
21
22 #include <linux/videodev2.h>
23
24 #if defined MMTIMER_GETRES \
25  && defined VIDIOC_ENUMINPUT \
26  && defined HIDIOCGVERSION \
27  && defined HIDIOCGPHYS \
28  && defined EVIOCGBIT \
29  && defined EV_KEY
30
31 int
32 main(void )
33 {
34         struct termios tty;
35         uint64_t data = 0;
36
37         (void) ioctl(-1, TCGETS, &tty);
38         printf("ioctl(-1, TCGETS, %p)"
39                " = -1 EBADF (Bad file descriptor)\n", &tty);
40
41         (void) ioctl(-1, MMTIMER_GETRES, &data);
42         printf("ioctl(-1, MMTIMER_GETRES, %p)"
43                " = -1 EBADF (Bad file descriptor)\n", &data);
44
45         (void) ioctl(-1, VIDIOC_ENUMINPUT, 0);
46         printf("ioctl(-1, VIDIOC_ENUMINPUT, 0)"
47                " = -1 EBADF (Bad file descriptor)\n");
48
49         (void) ioctl(-1, HIDIOCGVERSION, &data);
50         printf("ioctl(-1, HIDIOCGRDESCSIZE or HIDIOCGVERSION, %p)"
51                " = -1 EBADF (Bad file descriptor)\n", &data);
52
53         (void) ioctl(-1, HIDIOCGPHYS(8), &data);
54         printf("ioctl(-1, HIDIOCGPHYS(8), %p)"
55                " = -1 EBADF (Bad file descriptor)\n", &data);
56
57         (void) ioctl(-1, EVIOCGBIT(EV_KEY, 8), &data);
58         printf("ioctl(-1, EVIOCGBIT(EV_KEY, 8), %p)"
59                " = -1 EBADF (Bad file descriptor)\n", &data);
60
61         (void) ioctl(-1, _IOR('M', 13, int), &data);
62         printf("ioctl(-1, MIXER_READ(13) or OTPSELECT, [MTD_OTP_OFF])"
63                " = -1 EBADF (Bad file descriptor)\n");
64
65         (void) ioctl(-1, _IOR(0xde, 0xad, data), &data);
66         printf("ioctl(-1, _IOC(_IOC_READ, 0xde, 0xad, 0x08), %p)"
67                " = -1 EBADF (Bad file descriptor)\n", &data);
68
69         puts("+++ exited with 0 +++");
70         return 0;
71 }
72
73 #else
74
75 int
76 main(void )
77 {
78         return 77;
79 }
80
81 #endif