DeprecatedFile.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/DeprecatedString.h>
  8. #include <AK/Error.h>
  9. #include <LibCore/IODevice.h>
  10. #include <sys/stat.h>
  11. namespace Core {
  12. ///
  13. /// Use of Core::File for reading/writing data is deprecated.
  14. /// Please use Core::File and Core::InputBufferedFile instead.
  15. ///
  16. class DeprecatedFile final : public IODevice {
  17. C_OBJECT(DeprecatedFile)
  18. public:
  19. virtual ~DeprecatedFile() override;
  20. static ErrorOr<NonnullRefPtr<DeprecatedFile>> open(DeprecatedString filename, OpenMode, mode_t = 0644);
  21. DeprecatedString filename() const { return m_filename; }
  22. bool is_directory() const;
  23. bool is_device() const;
  24. bool is_block_device() const;
  25. bool is_char_device() const;
  26. bool is_link() const;
  27. static DeprecatedString current_working_directory();
  28. static DeprecatedString absolute_path(DeprecatedString const& path);
  29. static DeprecatedString real_path_for(DeprecatedString const& filename);
  30. virtual bool open(OpenMode) override;
  31. enum class ShouldCloseFileDescriptor {
  32. No = 0,
  33. Yes
  34. };
  35. bool open(int fd, OpenMode, ShouldCloseFileDescriptor);
  36. [[nodiscard]] int leak_fd();
  37. static Optional<DeprecatedString> resolve_executable_from_environment(StringView filename);
  38. private:
  39. DeprecatedFile(Object* parent = nullptr)
  40. : IODevice(parent)
  41. {
  42. }
  43. explicit DeprecatedFile(DeprecatedString filename, Object* parent = nullptr);
  44. bool open_impl(OpenMode, mode_t);
  45. DeprecatedString m_filename;
  46. ShouldCloseFileDescriptor m_should_close_file_descriptor { ShouldCloseFileDescriptor::Yes };
  47. };
  48. }