CloexecInotifyInitCheck.cpp 1.0 KB

1234567891011121314151617181920212223242526272829
  1. //===--- CloexecInotifyInitCheck.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 "CloexecInotifyInitCheck.h"
  9. #include "clang/AST/ASTContext.h"
  10. #include "clang/ASTMatchers/ASTMatchFinder.h"
  11. using namespace clang::ast_matchers;
  12. namespace clang::tidy::android {
  13. void CloexecInotifyInitCheck::registerMatchers(MatchFinder *Finder) {
  14. registerMatchersImpl(
  15. Finder, functionDecl(returns(isInteger()), hasName("inotify_init")));
  16. }
  17. void CloexecInotifyInitCheck::check(const MatchFinder::MatchResult &Result) {
  18. replaceFunc(Result, /*WarningMsg=*/
  19. "prefer inotify_init() to inotify_init1() "
  20. "because inotify_init1() allows IN_CLOEXEC",
  21. /*FixMsg=*/"inotify_init1(IN_CLOEXEC)");
  22. }
  23. } // namespace clang::tidy::android