123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- #ifndef RTC_BASE_SYSTEM_FILE_WRAPPER_H_
- #define RTC_BASE_SYSTEM_FILE_WRAPPER_H_
- #include <stddef.h>
- #include <stdio.h>
- #include "rtc_base/critical_section.h"
- namespace webrtc {
- class FileWrapper final {
- public:
-
-
-
-
- static FileWrapper OpenReadOnly(const char* file_name_utf8);
- static FileWrapper OpenReadOnly(const std::string& file_name_utf8);
- static FileWrapper OpenWriteOnly(const char* file_name_utf8,
- int* error = nullptr);
- static FileWrapper OpenWriteOnly(const std::string& file_name_utf8,
- int* error = nullptr);
- FileWrapper() = default;
-
-
- explicit FileWrapper(FILE* file) : file_(file) {}
- ~FileWrapper() { Close(); }
-
- FileWrapper(const FileWrapper&) = delete;
- FileWrapper& operator=(const FileWrapper&) = delete;
-
- FileWrapper(FileWrapper&&);
- FileWrapper& operator=(FileWrapper&&);
-
-
- bool is_open() const { return file_ != nullptr; }
-
-
-
- bool Close();
-
-
-
-
- FILE* Release();
-
-
- bool Flush();
-
-
- bool Rewind() { return SeekTo(0); }
-
-
-
-
- bool SeekRelative(int64_t offset);
-
- bool SeekTo(int64_t position);
-
- size_t Read(void* buf, size_t length);
-
-
-
- bool ReadEof() const;
-
-
-
- bool Write(const void* buf, size_t length);
- private:
- FILE* file_ = nullptr;
- };
- }
- #endif
|