1// RUN: %check_clang_tidy %s android-cloexec-inotify-init1 %t
2
3#define IN_NONBLOCK 1
4#define __O_CLOEXEC 3
5#define IN_CLOEXEC __O_CLOEXEC
6#define TEMP_FAILURE_RETRY(exp) \
7 ({ \
8 int _rc; \
9 do { \
10 _rc = (exp); \
11 } while (_rc == -1); \
12 })
13
14extern "C" int inotify_init1(int flags);
15
16void a() {
17 inotify_init1(IN_NONBLOCK);
18 // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: 'inotify_init1' should use IN_CLOEXEC where possible [android-cloexec-inotify-init1]
19 // CHECK-FIXES: inotify_init1(IN_NONBLOCK | IN_CLOEXEC);
20 TEMP_FAILURE_RETRY(inotify_init1(IN_NONBLOCK));
21 // CHECK-MESSAGES: :[[@LINE-1]]:47: warning: 'inotify_init1'
22 // CHECK-FIXES: TEMP_FAILURE_RETRY(inotify_init1(IN_NONBLOCK | IN_CLOEXEC));
23}
24
25void f() {
26 inotify_init1(flags: 0);
27 // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: 'inotify_init1'
28 // CHECK-FIXES: inotify_init1(IN_CLOEXEC);
29 TEMP_FAILURE_RETRY(inotify_init1(0));
30 // CHECK-MESSAGES: :[[@LINE-1]]:37: warning: 'inotify_init1'
31 // CHECK-FIXES: TEMP_FAILURE_RETRY(inotify_init1(IN_CLOEXEC));
32
33 int flag = 1;
34 inotify_init1(flags: flag);
35 TEMP_FAILURE_RETRY(inotify_init1(flag));
36}
37
38namespace i {
39int inotify_init1(int flags);
40
41void d() {
42 inotify_init1(IN_NONBLOCK);
43 TEMP_FAILURE_RETRY(inotify_init1(IN_NONBLOCK));
44}
45
46} // namespace i
47
48void e() {
49 inotify_init1(IN_CLOEXEC);
50 TEMP_FAILURE_RETRY(inotify_init1(IN_CLOEXEC));
51 inotify_init1(IN_NONBLOCK | IN_CLOEXEC);
52 TEMP_FAILURE_RETRY(inotify_init1(IN_NONBLOCK | IN_CLOEXEC));
53}
54
55class G {
56public:
57 int inotify_init1(int flags);
58 void d() {
59 inotify_init1(IN_CLOEXEC);
60 TEMP_FAILURE_RETRY(inotify_init1(IN_CLOEXEC));
61 inotify_init1(IN_NONBLOCK | IN_CLOEXEC);
62 TEMP_FAILURE_RETRY(inotify_init1(IN_NONBLOCK | IN_CLOEXEC));
63 }
64};
65

source code of clang-tools-extra/test/clang-tidy/checkers/android/cloexec-inotify-init1.cpp