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
18struct SC_COMPILER_EXPORT FileDescriptorDefinition
21 static Result releaseHandle(Handle& handle);
23 static constexpr void* Invalid = __builtin_constant_p(-1) ? (
void*)-1 : (void*)-1;
25 static constexpr void* Invalid = (
void*)-1;
33struct SC_COMPILER_EXPORT FileDescriptorDefinition
36 static Result releaseHandle(Handle& handle);
38 static constexpr Handle Invalid = -1;
61 FileOpen(Mode mode = Read) : mode(mode) {}
64 bool inheritable =
false;
67 bool exclusive =
false;
69#if !SC_PLATFORM_WINDOWS
70 int toPosixFlags()
const;
71 int toPosixAccess()
const;
79 using UniqueHandle::UniqueHandle;
137 template <
typename T>
140 return readUntilEOF(GrowableBuffer<T>{destination});
208 bool readInheritable =
false;
209 bool writeInheritable =
false;
210 bool blocking =
true;
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
[UniqueHandleDeclaration2Snippet]
Definition File.h:78
SeekMode
How the offset to FileDescriptor::seek is defined.
Definition File.h:178
@ SeekCurrent
Offset to FileDescriptor::seek is to be applied from current descriptor position.
Definition File.h:181
@ SeekEnd
Offset to FileDescriptor::seek is to be applied (backwards) from end of descriptor.
Definition File.h:180
@ SeekStart
Offset to FileDescriptor::seek is to be applied from start of descriptor.
Definition File.h:179
Result read(Span< uint8_t > data, Span< uint8_t > &actuallyRead)
Reads bytes from current position (FileDescriptor::seek) into user supplied Span.
Result openForWriteToDevNull()
... [UniqueHandleDeclaration2Snippet]
Result write(Span< const uint8_t > data, uint64_t offset)
Writes bytes at offset from start of the file descriptor.
Result openStdErrDuplicate()
Opens a duplicated file descriptor handle for reading from stderr.
Result readUntilEOF(T &destination)
Reads into a given dynamic buffer until End of File (EOF) is signaled.
Definition File.h:138
Result readUntilEOF(IGrowableBuffer &&buffer)
Reads into a given dynamic buffer until End of File (EOF) is signaled.
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 openStdOutDuplicate()
Opens a duplicated file descriptor handle for reading from stdout.
Result read(Span< char > data, Span< char > &actuallyRead, uint64_t offset)
Reads bytes at offset into user supplied span.
Result openStdInDuplicate()
Opens a duplicated file descriptor handle for reading from stdin.
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 writeString(StringSpan data)
Writes a string to the file descriptor.
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:49
Mode
Indicates the mode in which the file should be opened (read, write, append, etc.)
Definition File.h:52
@ Append
a Open for appending. The file is created if it does not exist.
Definition File.h:55
@ WriteRead
w+ Open for reading and writing. The file is created (if it does not exist) or truncated.
Definition File.h:58
@ ReadWrite
r+ Open for reading and writing. An error occurs if the file does not exist.
Definition File.h:54
@ Write
w Open for writing. The file is created (if it does not exist) or truncated (if it exists).
Definition File.h:57
@ AppendRead
a+ Open for reading and appending. The file is created if it does not exist.
Definition File.h:56
Mode mode
Open mode (read, write, append, etc.). See FileOpen::Mode for more details.
Definition File.h:63
Read / Write pipe (Process stdin/stdout and IPC communication)
Definition File.h:215
Result createPipe(PipeOptions options={})
Creates a Pipe.
FileDescriptor writePipe
The write side of the pipe.
Definition File.h:217
Result close()
Closes the pipe.
FileDescriptor readPipe
The read side of the pipe.
Definition File.h:216
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:37
Move only handle that has a special tag value flagging its invalid state.
Definition UniqueHandle.h:27