]> granicus.if.org Git - strace/blob - tests/inotify_init1.c
Update copyright headers
[strace] / tests / inotify_init1.c
1 /*
2  * Check decoding of inotify_init1 syscall.
3  *
4  * Copyright (c) 2016 Eugene Syromyatnikov <evgsyr@gmail.com>
5  * Copyright (c) 2016-2018 The strace developers.
6  * All rights reserved.
7  *
8  * SPDX-License-Identifier: GPL-2.0-or-later
9  */
10
11 #include "tests.h"
12
13 #include <asm/unistd.h>
14
15 #if defined(__NR_inotify_init1)
16
17 # include <fcntl.h>
18 # include <stdio.h>
19 # include <unistd.h>
20
21 # ifdef O_CLOEXEC
22 #  define cloexec_flag O_CLOEXEC
23 # else
24 #  define cloexec_flag 0
25 # endif
26 # define all_flags (O_NONBLOCK | cloexec_flag)
27
28 int
29 main(void)
30 {
31         static const kernel_ulong_t bogus_flags1 =
32                 (kernel_ulong_t) 0xfacefeeddeadbeefULL | O_NONBLOCK;
33         static const kernel_ulong_t bogus_flags2 =
34                 (kernel_ulong_t) 0x55555550ff96b77bULL & ~all_flags;
35
36         long rc;
37
38         rc = syscall(__NR_inotify_init1, bogus_flags1);
39         printf("inotify_init1(IN_NONBLOCK|%s%#x) = %s\n",
40                bogus_flags1 & cloexec_flag  ? "IN_CLOEXEC|" : "",
41                (unsigned int) (bogus_flags1 & ~all_flags),
42                sprintrc(rc));
43
44         rc = syscall(__NR_inotify_init1, bogus_flags2);
45         printf("inotify_init1(%#x /* IN_??? */) = %s\n",
46                (unsigned int) bogus_flags2, sprintrc(rc));
47
48         rc = syscall(__NR_inotify_init1, all_flags);
49         printf("inotify_init1(IN_NONBLOCK%s) = %s\n",
50                all_flags & cloexec_flag ? "|IN_CLOEXEC" : "", sprintrc(rc));
51
52         puts("+++ exited with 0 +++");
53
54         return 0;
55 }
56
57 #else
58
59 SKIP_MAIN_UNDEFINED("__NR_inotify_init1");
60
61 #endif