4#include "../Foundation/Internal/IGrowableBuffer.h"
5#include "../Foundation/PrimitiveTypes.h"
6#include "../Foundation/Result.h"
7#include "../Foundation/Span.h"
8#include "../Foundation/StringPath.h"
9#include "../Foundation/StringSpan.h"
10#include "../Foundation/UniqueHandle.h"
19#if SC_PLATFORM_WINDOWS
20struct SC_COMPILER_EXPORT FileDescriptorDefinition
23 static Result releaseHandle(Handle& handle);
25 static constexpr void* Invalid = __builtin_constant_p(-1) ? (
void*)-1 : (void*)-1;
27 static constexpr void* Invalid = (
void*)-1;
35struct SC_COMPILER_EXPORT FileDescriptorDefinition
38 static Result releaseHandle(Handle& handle);
40 static constexpr Handle Invalid = -1;
105 FileOpen(Mode mode = Read) : mode(mode) {}
108 bool inheritable =
false;
109 bool blocking =
true;
111 bool exclusive =
false;
113#if !SC_PLATFORM_WINDOWS
114 int toPosixFlags()
const;
115 int toPosixAccess()
const;
123 using UniqueHandle::UniqueHandle;
187 template <
typename T>
190 return readUntilEOF(GrowableBuffer<T>{destination});
287 bool readInheritable =
false;
288 bool writeInheritable =
false;
289 bool blocking =
true;
330 bool removeEndpointOnClose =
true;
331 bool removeEndpointBeforeCreate =
false;
369#if SC_PLATFORM_WINDOWS
371 bool firstInstance =
true;
375 bool created =
false;
@ Read
Check if path is readable.
FileDescriptorEntryType
A structure to describe metadata associated with an open descriptor.
Definition File.h:51
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
unsigned int uint32_t
Platform independent (4) bytes unsigned int.
Definition PrimitiveTypes.h:38
long long int64_t
Platform independent (8) bytes signed int.
Definition PrimitiveTypes.h:50
A structure to describe file stats queried through a file descriptor.
Definition File.h:61
uint32_t reparseTag
Windows reparse tag.
Definition File.h:85
uint32_t uid
POSIX st_uid.
Definition File.h:73
uint32_t mode
POSIX st_mode.
Definition File.h:72
uint64_t blockSize
POSIX st_blksize.
Definition File.h:79
uint64_t fileIndex
Windows file index.
Definition File.h:87
uint32_t attributes
Windows file attributes.
Definition File.h:84
FileDescriptorEntryType entryType
Type of entry associated with descriptor.
Definition File.h:62
TimeMs accessedTime
Time when file was last accessed when available.
Definition File.h:67
size_t hardLinkCount
Number of hard links to the entry.
Definition File.h:65
uint64_t device
POSIX st_dev.
Definition File.h:76
uint64_t specialDevice
POSIX st_rdev.
Definition File.h:77
TimeMs modifiedTime
Time when file was last modified.
Definition File.h:68
uint64_t blocks
POSIX st_blocks.
Definition File.h:78
size_t fileSize
Size of the file in bytes.
Definition File.h:64
uint32_t volumeSerialNumber
Windows volume serial number.
Definition File.h:86
uint32_t gid
POSIX st_gid.
Definition File.h:74
TimeMs creationTime
Time when file was created when available.
Definition File.h:66
uint64_t inode
POSIX st_ino.
Definition File.h:75
[UniqueHandleDeclaration2Snippet]
Definition File.h:122
SeekMode
How the offset to FileDescriptor::seek is defined.
Definition File.h:228
@ SeekCurrent
Offset to FileDescriptor::seek is to be applied from current descriptor position.
Definition File.h:231
@ SeekEnd
Offset to FileDescriptor::seek is to be applied (backwards) from end of descriptor.
Definition File.h:230
@ SeekStart
Offset to FileDescriptor::seek is to be applied from start of descriptor.
Definition File.h:229
Result syncData()
Flush file data to stable storage.
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 chmod(uint32_t mode)
Change file permission bits for the currently open descriptor.
Result readUntilEOF(T &destination)
Reads into a given dynamic buffer until End of File (EOF) is signaled.
Definition File.h:188
Result readUntilEOF(IGrowableBuffer &&buffer)
Reads into a given dynamic buffer until End of File (EOF) is signaled.
Result seek(SeekMode seekMode, int64_t offset)
Changes the current position in the file descriptor, if seekable.
Result stat(FileDescriptorStat &fileStat) const
Obtains richer metadata associated with the currently open descriptor.
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 truncate(uint64_t sizeInBytes)
Resize the underlying file to the specified size in bytes.
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 readUntilFullOrEOF(Span< char > data, Span< char > &actuallyRead)
Reads bytes from current position (FileDescriptor::seek) into Span, until full or EOF is reached.
Result chown(uint32_t uid, uint32_t gid)
Change owner and group for the currently open descriptor.
Result sync()
Flush file data and metadata to stable storage.
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.
Options used to open a file descriptor.
Definition File.h:93
Mode
Indicates the mode in which the file should be opened (read, write, append, etc.)
Definition File.h:96
@ Append
a Open for appending. The file is created if it does not exist.
Definition File.h:99
@ WriteRead
w+ Open for reading and writing. The file is created (if it does not exist) or truncated.
Definition File.h:102
@ ReadWrite
r+ Open for reading and writing. An error occurs if the file does not exist.
Definition File.h:98
@ Write
w Open for writing. The file is created (if it does not exist) or truncated (if it exists).
Definition File.h:101
@ AppendRead
a+ Open for reading and appending. The file is created if it does not exist.
Definition File.h:100
Mode mode
Open mode (read, write, append, etc.). See FileOpen::Mode for more details.
Definition File.h:107
Named pipe client endpoint creator.
Definition File.h:380
static Result connect(StringSpan name, PipeDescriptor &outConnection, NamedPipeClientOptions options={})
Connects to an existing named pipe server endpoint.
Utility for building platform-native named pipe endpoint names from logical names.
Definition File.h:314
static Result build(StringSpan logicalName, StringPath &outName, NamedPipeNameOptions options={})
Builds a platform-native named pipe endpoint path.
Named pipe server endpoint.
Definition File.h:349
Result close()
Closes the listening endpoint.
Result create(StringSpan name, NamedPipeServerOptions options={})
Creates a named pipe server endpoint.
Result accept(PipeDescriptor &outConnection)
Accept one client connection and return it as a connected PipeDescriptor.
Read / Write pipe (Process stdin/stdout and IPC communication)
Definition File.h:294
Result createPipe(PipeOptions options={})
Creates a Pipe.
FileDescriptor writePipe
The write side of the pipe.
Definition File.h:296
Result close()
Closes the pipe.
FileDescriptor readPipe
The read side of the pipe.
Definition File.h:295
An ascii string used as boolean result. SC_TRY macro forwards errors to caller.
Definition Result.h:13
View over a contiguous sequence of items (pointer + size in elements).
Definition Span.h:29
Pre-sized char array holding enough space to represent a file system path.
Definition StringPath.h:42
An read-only view over a string (to avoid including Strings library when parsing is not needed).
Definition StringSpan.h:37
A vocabulary type representing a time interval in milliseconds since epoch.
Definition PrimitiveTypes.h:63
Move only handle that has a special tag value flagging its invalid state.
Definition UniqueHandle.h:27