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