blob: 0d5a56daaf5d4e117d4951833f367202f6721a59 [file] [log] [blame]
Chih-Hung Hsieh2e6f9a12017-08-14 17:25:41 +00001//===--- 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
14using namespace clang::ast_matchers;
15
16namespace clang {
17namespace tidy {
18namespace android {
19
20void CloexecInotifyInitCheck::registerMatchers(MatchFinder *Finder) {
21 registerMatchersImpl(
22 Finder, functionDecl(returns(isInteger()), hasName("inotify_init")));
23}
24
25void 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