1 // RUN: %check_clang_tidy %s android-cloexec-creat %t
2
3 typedef int mode_t;
4
5 extern "C" int creat(const char *path, mode_t, ...);
6 extern "C" int create(const char *path, mode_t, ...);
7
f()8 void f() {
9 creat("filename", 0);
10 // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: prefer open() to creat() because open() allows O_CLOEXEC [android-cloexec-creat]
11 // CHECK-FIXES: open ("filename", O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, 0);
12 create("filename", 0);
13 // CHECK-MESSAGES-NOT: warning:
14 mode_t mode = 0755;
15 creat("filename", mode);
16 // CHECK-MESSAGES: :[[@LINE-1]]:3: warning:
17 // CHECK-FIXES: open ("filename", O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, mode);
18 }
19
20 namespace i {
21 int creat(const char *path, mode_t, ...);
g()22 void g() {
23 creat("filename", 0);
24 // CHECK-MESSAGES-NOT: warning:
25 }
26 } // namespace i
27
28 class C {
29 public:
30 int creat(const char *path, mode_t, ...);
h()31 void h() {
32 creat("filename", 0);
33 // CHECK-MESSAGES-NOT: warning:
34 }
35 };
36