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