blob: ec4ff0acd85f887f521ed759a6142e286ae5843d [file] [log] [blame]
Chih-Hung Hsieh56650e72017-08-14 17:04:16 +00001//===--- CloexecDupCheck.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 "CloexecDupCheck.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 CloexecDupCheck::registerMatchers(MatchFinder *Finder) {
21 registerMatchersImpl(Finder,
22 functionDecl(returns(isInteger()), hasName("dup"),
23 hasParameter(0, hasType(isInteger()))));
24}
25
26void CloexecDupCheck::check(const MatchFinder::MatchResult &Result) {
27 const std::string &ReplacementText =
28 (Twine("fcntl(") + getSpellingArg(Result, 0) + ", F_DUPFD_CLOEXEC)")
29 .str();
30
31 replaceFunc(Result,
32 "prefer fcntl() to dup() because fcntl() allows F_DUPFD_CLOEXEC",
33 ReplacementText);
34}
35
36} // namespace android
37} // namespace tidy
38} // namespace clang