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

source code of clang-tools-extra/test/clang-tidy/checkers/android/cloexec-epoll-create1.cpp