4#include "../Foundation/Internal/IGrowableBuffer.h"
5#include "../Foundation/Result.h"
6#include "../Foundation/Span.h"
7#include "../Foundation/StringSpan.h"
8#include "../Foundation/UniqueHandle.h"
17#if SC_PLATFORM_WINDOWS
22 static Result releaseHandle(Handle& handle);
24 static constexpr void* Invalid = __builtin_constant_p(-1) ? (
void*)-1 : (void*)-1;
26 static constexpr void* Invalid = (
void*)-1;
35 static Result releaseHandle(Handle& handle);
37 static constexpr Handle Invalid = -1;
60 FileOpen(Mode mode = Read) : mode(mode) {}
63 bool inheritable =
false;
66 bool exclusive =
false;
68#if !SC_PLATFORM_WINDOWS
69 int toPosixFlags()
const;
70 int toPosixAccess()
const;
77 using UniqueHandle::UniqueHandle;
135 template <
typename T>
138 return readUntilEOFGrowable(GrowableBuffer<T>{destination});
190 Result readUntilEOFGrowable(IGrowableBuffer&& buffer);
#define SC_COMPILER_EXPORT
Macro for symbol visibility in non-MSVC compilers.
Definition Compiler.h:78
unsigned char uint8_t
Platform independent (1) byte unsigned int.
Definition PrimitiveTypes.h:36
unsigned long long uint64_t
Platform independent (8) bytes unsigned int.
Definition PrimitiveTypes.h:42
Open, read and write to/from a file descriptor (like a file or pipe).
Definition File.h:76
SeekMode
How the offset to FileDescriptor::seek is defined.
Definition File.h:165
@ SeekCurrent
Offset to FileDescriptor::seek is to be applied from current descriptor position.
Definition File.h:168
@ SeekEnd
Offset to FileDescriptor::seek is to be applied (backwards) from end of descriptor.
Definition File.h:167
@ SeekStart
Offset to FileDescriptor::seek is to be applied from start of descriptor.
Definition File.h:166
Result read(Span< uint8_t > data, Span< uint8_t > &actuallyRead)
Reads bytes from current position (FileDescriptor::seek) into user supplied Span.
Result openForWriteToDevNull()
Opens a file descriptor handle for writing to /dev/null or equivalent on current OS.
Result write(Span< const uint8_t > data, uint64_t offset)
Writes bytes at offset from start of the file descriptor.
Result readUntilEOF(T &destination)
Reads into a given dynamic buffer until End of File (EOF) is signaled.
Definition File.h:136
Result setInheritable(bool inheritable)
Set inheritable flag (visibility to child processes).
Result read(Span< char > data, Span< char > &actuallyRead)
Reads bytes from current position (FileDescriptor::seek) into user supplied Span.
Result currentPosition(size_t &position) const
Gets current descriptor position (if seekable)
Result write(Span< const uint8_t > data)
Writes bytes from current position (FileDescriptor::seek) of the file descriptor.
Result write(Span< const char > data, uint64_t offset)
Writes bytes at offset from start of the file descriptor.
Result sizeInBytes(size_t &sizeInBytes) const
Gets total file size in bytes (if seekable)
Result read(Span< char > data, Span< char > &actuallyRead, uint64_t offset)
Reads bytes at offset into user supplied span.
Result setBlocking(bool blocking)
Set blocking mode (read / write waiting for I/O).
Result isInheritable(bool &hasValue) const
Queries the inheritable state of this descriptor.
Result open(StringSpan path, FileOpen mode)
Opens a file descriptor handle from a file system path.
Result read(Span< uint8_t > data, Span< uint8_t > &actuallyRead, uint64_t offset)
Reads bytes at offset into user supplied span.
Result write(Span< const char > data)
Writes bytes from current position (FileDescriptor::seek) of the file descriptor.
Result seek(SeekMode seekMode, uint64_t offset)
Changes the current position in the file descriptor, if seekable.
Options used to open a file descriptor.
Definition File.h:48
Mode
Indicates the mode in which the file should be opened (read, write, append, etc.)
Definition File.h:51
@ Append
a Open for appending. The file is created if it does not exist.
Definition File.h:54
@ WriteRead
w+ Open for reading and writing. The file is created (if it does not exist) or truncated.
Definition File.h:57
@ ReadWrite
r+ Open for reading and writing. An error occurs if the file does not exist.
Definition File.h:53
@ Write
w Open for writing. The file is created (if it does not exist) or truncated (if it exists).
Definition File.h:56
@ AppendRead
a+ Open for reading and appending. The file is created if it does not exist.
Definition File.h:55
Mode mode
Open mode (read, write, append, etc.). See FileOpen::Mode for more details.
Definition File.h:62
Read / Write pipe (Process stdin/stdout and IPC communication)
Definition File.h:195
Result createPipe(InheritableReadFlag readFlag=ReadNonInheritable, InheritableWriteFlag writeFlag=WriteNonInheritable)
Creates a Pipe.
InheritableReadFlag
Specifies a flag for read side of the pipe.
Definition File.h:198
@ ReadInheritable
Requests read side of the pipe to be inheritable from child processes.
Definition File.h:199
FileDescriptor writePipe
The write side of the pipe.
Definition File.h:210
Result close()
Closes the pipe.
FileDescriptor readPipe
The read side of the pipe.
Definition File.h:209
InheritableWriteFlag
Specifies a flag for write side of the pipe.
Definition File.h:205
@ WriteInheritable
Requests write side of the pipe to be inheritable from child processes.
Definition File.h:206
An ascii string used as boolean result. SC_TRY macro forwards errors to caller.
Definition Result.h:12
View over a contiguous sequence of items (pointer + size in elements).
Definition Span.h:29
An read-only view over a string (to avoid including Strings library when parsing is not needed).
Definition StringSpan.h:31
Move only handle that has a special tag value flagging its invalid state.
Definition UniqueHandle.h:67