1// RUN: %check_clang_tidy %s android-cloexec-creat %t
2
3typedef int mode_t;
4
5extern "C" int creat(const char *path, mode_t, ...);
6extern "C" int create(const char *path, mode_t, ...);
7
8void f() {
9 creat(path: "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(path: "filename", 0);
13 // CHECK-MESSAGES-NOT: warning:
14 mode_t mode = 0755;
15 creat(path: "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
20namespace i {
21int creat(const char *path, mode_t, ...);
22void g() {
23 creat(path: "filename", 0);
24 // CHECK-MESSAGES-NOT: warning:
25}
26} // namespace i
27
28class C {
29public:
30 int creat(const char *path, mode_t, ...);
31 void h() {
32 creat(path: "filename", 0);
33 // CHECK-MESSAGES-NOT: warning:
34 }
35};
36

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