1 //===--- CloexecInotifyInitCheck.cpp - clang-tidy--------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #include "CloexecInotifyInitCheck.h" 11 #include "clang/AST/ASTContext.h" 12 #include "clang/ASTMatchers/ASTMatchFinder.h" 13 14 using namespace clang::ast_matchers; 15 16 namespace clang { 17 namespace tidy { 18 namespace android { 19 20 void CloexecInotifyInitCheck::registerMatchers(MatchFinder *Finder) { 21 registerMatchersImpl( 22 Finder, functionDecl(returns(isInteger()), hasName("inotify_init"))); 23 } 24 25 void CloexecInotifyInitCheck::check(const MatchFinder::MatchResult &Result) { 26 replaceFunc(Result, /*WarningMsg=*/ 27 "prefer inotify_init() to inotify_init1() " 28 "because inotify_init1() allows IN_CLOEXEC", 29 /*FixMsg=*/"inotify_init1(IN_CLOEXEC)"); 30 } 31 32 } // namespace android 33 } // namespace tidy 34 } // namespace clang 35