]> granicus.if.org Git - strace/blob - tests/ioctl.c
Replace "(unsigned long) -1L" with -1UL
[strace] / tests / ioctl.c
1 /*
2  * Copyright (c) 2015-2016 Dmitry V. Levin <ldv@altlinux.org>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. The name of the author may not be used to endorse or promote products
14  *    derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27
28 #include "tests.h"
29 #include <fcntl.h>
30 #include <stdio.h>
31 #include <stdint.h>
32 #include <unistd.h>
33 #include <termios.h>
34 #include <sys/ioctl.h>
35
36 #ifdef HAVE_LINUX_MMTIMER_H
37 # include <linux/mmtimer.h>
38 #endif
39 #ifdef HAVE_LINUX_HIDDEV_H
40 # include <linux/hiddev.h>
41 #endif
42 #ifdef HAVE_LINUX_INPUT_H
43 # include <linux/input.h>
44 #endif
45
46 #include <linux/videodev2.h>
47
48 #if defined MMTIMER_GETRES \
49  && defined VIDIOC_ENUMINPUT \
50  && defined HIDIOCGVERSION \
51  && defined HIDIOCGPHYS \
52  && defined EVIOCGBIT \
53  && defined EV_KEY
54
55 int
56 main(void )
57 {
58         uint64_t data = 0;
59
60 #ifndef POWERPC
61         struct termios tty;
62         (void) ioctl(-1, TCGETS, &tty);
63         printf("ioctl(-1, TCGETS, %p)"
64                " = -1 EBADF (%m)\n", &tty);
65 #endif
66
67         (void) ioctl(-1, MMTIMER_GETRES, &data);
68         printf("ioctl(-1, MMTIMER_GETRES, %p)"
69                " = -1 EBADF (%m)\n", &data);
70
71         (void) ioctl(-1, VIDIOC_ENUMINPUT, 0);
72         printf("ioctl(-1, VIDIOC_ENUMINPUT, NULL)"
73                " = -1 EBADF (%m)\n");
74
75         (void) ioctl(-1, HIDIOCGVERSION, &data);
76         printf("ioctl(-1, HIDIOCGRDESCSIZE or HIDIOCGVERSION, %p)"
77                " = -1 EBADF (%m)\n", &data);
78
79         (void) ioctl(-1, HIDIOCGPHYS(8), &data);
80         printf("ioctl(-1, HIDIOCGPHYS(8), %p)"
81                " = -1 EBADF (%m)\n", &data);
82
83         (void) ioctl(-1, EVIOCGBIT(EV_KEY, 8), &data);
84         printf("ioctl(-1, EVIOCGBIT(EV_KEY, 8), %p)"
85                " = -1 EBADF (%m)\n", &data);
86
87         (void) ioctl(-1, _IOR('M', 13, int), &data);
88         printf("ioctl(-1, MIXER_READ(13) or OTPSELECT, [MTD_OTP_OFF])"
89                " = -1 EBADF (%m)\n");
90
91         (void) ioctl(-1, _IOR(0xde, 0xad, data), &data);
92         printf("ioctl(-1, _IOC(_IOC_READ, 0xde, 0xad, 0x08), %p)"
93                " = -1 EBADF (%m)\n", &data);
94
95         puts("+++ exited with 0 +++");
96         return 0;
97 }
98
99 #else
100
101 SKIP_MAIN_UNDEFINED("MMTIMER_GETRES && VIDIOC_ENUMINPUT"
102                     " && HIDIOCGVERSION && HIDIOCGPHYS"
103                     " && EVIOCGBIT && EV_KEY")
104
105 #endif