CloexecFopenCheck.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132
  1. //===--- CloexecFopenCheck.cpp - clang-tidy--------------------------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. #include "CloexecFopenCheck.h"
  9. #include "clang/AST/ASTContext.h"
  10. #include "clang/AST/Type.h"
  11. #include "clang/ASTMatchers/ASTMatchFinder.h"
  12. #include "clang/Lex/Lexer.h"
  13. using namespace clang::ast_matchers;
  14. namespace clang::tidy::android {
  15. void CloexecFopenCheck::registerMatchers(MatchFinder *Finder) {
  16. auto CharPointerType = hasType(pointerType(pointee(isAnyCharacter())));
  17. registerMatchersImpl(Finder,
  18. functionDecl(isExternC(), returns(asString("FILE *")),
  19. hasName("fopen"),
  20. hasParameter(0, CharPointerType),
  21. hasParameter(1, CharPointerType)));
  22. }
  23. void CloexecFopenCheck::check(const MatchFinder::MatchResult &Result) {
  24. insertStringFlag(Result, /*Mode=*/'e', /*ArgPos=*/1);
  25. }
  26. } // namespace clang::tidy::android