brintos

brintos / llvm-project-archived public Read only

0
0
Text · 959 B · df57b10 Raw
36 lines · cpp
1// RUN: %check_clang_tidy %s android-cloexec-creat %t2 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("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 20namespace i {21int creat(const char *path, mode_t, ...);22void g() {23  creat("filename", 0);24  // CHECK-MESSAGES-NOT: warning:25}26} // namespace i27 28class C {29public:30  int creat(const char *path, mode_t, ...);31  void h() {32    creat("filename", 0);33    // CHECK-MESSAGES-NOT: warning:34  }35};36