11#include <promeki/config.h>
12#if PROMEKI_ENABLE_CORE
28typedef struct cirf_file cirf_file_t;
30PROMEKI_NAMESPACE_BEGIN
53class File :
public BufferedIODevice {
54 PROMEKI_OBJECT(File, BufferedIODevice)
57 using UPtr = UniquePtr<File>;
85#if defined(PROMEKI_PLATFORM_WINDOWS)
87 using FileHandle = HANDLE;
89 static constexpr FileHandle FileHandleClosedValue =
nullptr;
92 using FileHandle = int;
94 static constexpr FileHandle FileHandleClosedValue = -1;
101 File(ObjectBase *parent =
nullptr);
108 File(
const String &fn, ObjectBase *parent =
nullptr);
115 File(
const char *fn, ObjectBase *parent =
nullptr);
122 File(
const FilePath &fp, ObjectBase *parent =
nullptr);
146 File(FileHandle handle, OpenMode mode,
bool ownsHandle =
true, ObjectBase *parent =
nullptr);
155 const String &filename()
const {
return _filename; }
163 void setFilename(
const String &fn) { _filename = fn; }
169 int flags()
const {
return _fileFlags; }
175 FileHandle handle()
const {
return _handle; }
182 Error open(OpenMode mode)
override;
190 Error open(OpenMode mode,
int fileFlags);
196 Error close()
override;
199 bool isOpen()
const override;
202 bool isSequential()
const override;
209 Error seek(int64_t offset)
override;
215 int64_t pos()
const override;
222 Result<int64_t> size()
const override;
228 bool atEnd()
const override;
235 Result<int64_t> seekFromCurrent(int64_t offset)
const;
242 Result<int64_t> seekFromEnd(int64_t offset)
const;
249 Error truncate(int64_t offset)
const;
265 int64_t writev(
const IOVec *iov,
int count);
278 Error preallocate(int64_t offset, int64_t length);
290 Result<size_t> directIOAlignment()
const;
344 Error readBulk(Buffer &buf, int64_t size);
380 int64_t writeBulk(
const void *data, int64_t size);
399 Error sync(
bool dataOnly =
true);
411 Error setDirectIO(
bool enable);
417 bool isDirectIO()
const {
return _directIO; }
427 Error setSynchronous(
bool enable);
433 bool isSynchronous()
const {
return _synchronous; }
443 Error setNonBlocking(
bool enable);
449 bool isNonBlocking()
const {
return _nonBlocking; }
460 bool isResource()
const {
return _resourceFile !=
nullptr; }
464 int64_t readFromDevice(
void *data, int64_t maxSize)
override;
467 int64_t writeToDevice(
const void *data, int64_t maxSize)
override;
470 int64_t deviceBytesAvailable()
const override;
473 bool _directIO =
false;
474 bool _synchronous =
false;
475 bool _nonBlocking =
false;
476 bool _ownsHandle =
true;
478 int _fileFlags = NoFlags;
479 FileHandle _handle = FileHandleClosedValue;
480 bool _savedUnbuffered =
false;
481 const cirf_file_t *_resourceFile =
nullptr;
482 int64_t _resourcePos = 0;