DirIterator.h 882 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. bool has_error() const { return m_error != 0; }
  21. int error() const { return m_error; }
  22. const char* error_string() const { return strerror(m_error); }
  23. bool has_next();
  24. String next_path();
  25. String next_full_path();
  26. int fd() const;
  27. private:
  28. DIR* m_dir = nullptr;
  29. int m_error = 0;
  30. String m_next;
  31. String m_path;
  32. int m_flags;
  33. bool advance_next();
  34. };
  35. String find_executable_in_path(String filename);
  36. }