DirIterator.h 961 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/String.h>
  8. #include <dirent.h>
  9. #include <string.h>
  10. namespace Core {
  11. class DirIterator {
  12. public:
  13. enum Flags {
  14. NoFlags = 0x0,
  15. SkipDots = 0x1,
  16. SkipParentAndBaseDir = 0x2,
  17. };
  18. explicit DirIterator(String path, Flags = Flags::NoFlags);
  19. ~DirIterator();
  20. DirIterator(DirIterator&&);
  21. DirIterator(DirIterator const&) = delete;
  22. bool has_error() const { return m_error != 0; }
  23. int error() const { return m_error; }
  24. char const* error_string() const { return strerror(m_error); }
  25. bool has_next();
  26. String next_path();
  27. String next_full_path();
  28. int fd() const;
  29. private:
  30. DIR* m_dir = nullptr;
  31. int m_error = 0;
  32. String m_next;
  33. String m_path;
  34. int m_flags;
  35. bool advance_next();
  36. };
  37. String find_executable_in_path(String filename);
  38. }