Sane C++ Libraries
C++ Platform Abstraction Libraries
Loading...
Searching...
No Matches
File.h
1// Copyright (c) Stefano Cristiano
2// SPDX-License-Identifier: MIT
3#pragma once
4#include "../Strings/StringView.h"
5#include "FileDescriptor.h"
6
7namespace SC
8{
9struct Buffer;
10struct String;
11} // namespace SC
14
19{
21
22 File(FileDescriptor& descriptor) : fd(descriptor) {}
23
32
35 {
36 bool inheritable = false;
37 bool blocking = true;
38 };
39
44 [[nodiscard]] Result open(StringView path, OpenMode mode);
45
51 [[nodiscard]] Result open(StringView path, OpenMode mode, OpenOptions options);
52
57 [[nodiscard]] Result readUntilEOF(Buffer& destination);
58
63 [[nodiscard]] Result readUntilEOF(String& destination);
64
65 private:
66 struct Internal;
67 struct ReadResult;
68 Result readUntilEOFTemplate(Buffer& destination);
69};
70
An heap allocated byte buffer that can optionally use an inline buffer.
Definition Buffer.h:28
File Descriptor (use SC::File to open and use it with strings and buffers).
Definition FileDescriptor.h:52
Additional flags to be set when opening files.
Definition File.h:35
bool blocking
Set to false if file will be used for Async I/O (see Async)
Definition File.h:37
bool inheritable
Set to true to make the file visible to child processes.
Definition File.h:36
Wraps a SC::FileDescriptor to open it and use strings / buffers.
Definition File.h:19
Result readUntilEOF(String &destination)
Reads into a given string until End of File (EOF) is signaled It works also for non-seekable file des...
Result open(StringView path, OpenMode mode, OpenOptions options)
Opens file at path with a given mode
OpenMode
Define mode for opening the file (read, write etc.)
Definition File.h:26
@ ReadAndWrite
Opens file for read / write mode.
Definition File.h:30
@ WriteAppend
Opens write mode, appending to existing file that must exist at the same location.
Definition File.h:29
@ WriteCreateTruncate
Opens in write mode, creating or truncating it if another file exists at same location.
Definition File.h:28
@ ReadOnly
Opens in read-only mode.
Definition File.h:27
Result open(StringView path, OpenMode mode)
Opens file at path with a given mode
Result readUntilEOF(Buffer &destination)
Reads into a given dynamic buffer until End of File (EOF) is signaled.
An ascii string used as boolean result. SC_TRY macro forwards errors to caller.
Definition Result.h:12
Non-owning view over a range of characters with UTF Encoding.
Definition StringView.h:47
A non-modifiable owning string with associated encoding.
Definition String.h:29