4#include "../Foundation/Result.h"
5#include "../Foundation/Span.h"
6#include "../Foundation/StringViewData.h"
7#include "../Foundation/UniqueHandle.h"
16#if SC_PLATFORM_WINDOWS
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;
34 static Result releaseHandle(Handle& handle);
36 static constexpr Handle Invalid = -1;
59 FileOpen(Mode mode = Read) : mode(mode) {}
62 bool inheritable =
false;
65 bool exclusive =
false;
67#if !SC_PLATFORM_WINDOWS
68 int toPosixFlags()
const;
69 int toPosixAccess()
const;
76 using UniqueHandle::UniqueHandle;
#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
File Descriptor (use File to open and use it with strings and buffers).
Definition FileDescriptor.h:75
SeekMode
How the offset to FileDescriptor::seek is defined.
Definition FileDescriptor.h:154
@ SeekCurrent
Offset to FileDescriptor::seek is to be applied from current descriptor position.
Definition FileDescriptor.h:157
@ SeekEnd
Offset to FileDescriptor::seek is to be applied (backwards) from end of descriptor.
Definition FileDescriptor.h:156
@ SeekStart
Offset to FileDescriptor::seek is to be applied from start of descriptor.
Definition FileDescriptor.h:155
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 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 read(Span< uint8_t > data, Span< uint8_t > &actuallyRead, uint64_t offset)
Reads bytes at offset into user supplied span.
Result openNativeEncoding(StringViewData path, FileOpen mode)
Opens a file descriptor handle for a file path encoded in the native encoding of the current OS.
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 FileDescriptor.h:47
Mode
Indicates the mode in which the file should be opened (read, write, append, etc.)
Definition FileDescriptor.h:50
@ Append
a Open for appending. The file is created if it does not exist.
Definition FileDescriptor.h:53
@ WriteRead
w+ Open for reading and writing. The file is created (if it does not exist) or truncated.
Definition FileDescriptor.h:56
@ ReadWrite
r+ Open for reading and writing. An error occurs if the file does not exist.
Definition FileDescriptor.h:52
@ Write
w Open for writing. The file is created (if it does not exist) or truncated (if it exists).
Definition FileDescriptor.h:55
@ AppendRead
a+ Open for reading and appending. The file is created if it does not exist.
Definition FileDescriptor.h:54
Mode mode
Open mode (read, write, append, etc.). See FileOpen::Mode for more details.
Definition FileDescriptor.h:61
Wraps a SC::FileDescriptor to open it and use strings / buffers.
Definition File.h:18
Read / Write pipe (Process stdin/stdout and IPC communication)
Definition FileDescriptor.h:183
Result createPipe(InheritableReadFlag readFlag=ReadNonInheritable, InheritableWriteFlag writeFlag=WriteNonInheritable)
Creates a Pipe.
InheritableReadFlag
Specifies a flag for read side of the pipe.
Definition FileDescriptor.h:186
@ ReadInheritable
Requests read side of the pipe to be inheritable from child processes.
Definition FileDescriptor.h:187
FileDescriptor writePipe
The write side of the pipe.
Definition FileDescriptor.h:198
Result close()
Closes the pipe.
FileDescriptor readPipe
The read side of the pipe.
Definition FileDescriptor.h:197
InheritableWriteFlag
Specifies a flag for write side of the pipe.
Definition FileDescriptor.h:193
@ WriteInheritable
Requests write side of the pipe to be inheritable from child processes.
Definition FileDescriptor.h:194
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)
Definition StringViewData.h:31
Move only handle that has a special tag value flagging its invalid state.
Definition UniqueHandle.h:67