Preliminary. ThinkMeta ConcurrentTasks and this documentation are preliminary; everything is subject to change.

API reference / POSIX

File class

Owns one file descriptor and closes it on destruction.

On this page
Use
import ThinkMeta.ConcurrentTasks.Posix.File;
Namespace
ThinkMeta::ConcurrentTasks::Posix
Platforms
Linux

Syntax

class File

Remarks

Holds -1 when no file is open. All members report failures as an errno (ErrorCode, Error::Success on success). Members that use the descriptor require one to be held (asserted in Debug builds). Plain blocking calls: called from a task they block the scheduler thread. No member is synchronized; one object is used by one caller at a time.

See also

AsyncIo::AsyncFile

Constructors

File

Takes ownership of a descriptor.

Syntax

explicit File(int fd = -1) noexcept;

Parameters

fdint
The descriptor to own; default: none.Default: -1

Takes over another object's descriptor.

Syntax

File(File&& other) noexcept;

Parameters

otherFile&&
The object to take the descriptor from; holds none afterwards.

~File

Closes the descriptor.

Syntax

~File() noexcept;

Remarks

A failure is ignored.

Methods

operator=

Takes over another object's descriptor.

Syntax

File& operator=(File&& other) noexcept;

Parameters

otherFile&&
The object to take the descriptor from; holds none afterwards.

Return value

Type: File&

This object.

Remarks

Closes the own descriptor first (ignoring a failure). A self-move changes nothing.

IsValid

true if a descriptor is held.

Syntax

bool IsValid() const noexcept;

Return value

Type: bool

true if a descriptor is held; otherwise false.

GetHandle

The descriptor, still owned by this object.

Syntax

int GetHandle() const noexcept;

Return value

Type: int

The descriptor, or -1 if none is held; do not close it.

Create

Opens or creates a file (open, with O_CLOEXEC).

Syntax

ErrorCode Create(FileName fileName, int flags, mode_t mode = 0666) noexcept;

Parameters

fileNameFileName
Path of the file; must not be nullptr.
flagsint
The O_* flags.
modemode_t
The permissions of a file that is created, before the umask.Default: 0666

Return value

Type: ErrorCode

Error::Success, or the errno of open.

Remarks

Precondition: no descriptor is held. On failure none is held.

Opens or creates a file as options says.

Syntax

ErrorCode Create(FileName fileName, const Platform::FileOptions& options) noexcept;

Parameters

fileNameFileName
Path of the file; must not be nullptr.
optionsconst Platform::FileOptions&
How to open it; the share modes have no meaning here.

Return value

Type: ErrorCode

Error::Success, or the errno of open.

Remarks

Precondition: no descriptor is held. On failure none is held.

Close

Closes the descriptor (close).

Syntax

ErrorCode Close() noexcept;

Return value

Type: ErrorCode

Error::Success if it was closed or none was held; otherwise the errno of close.

Remarks

The object holds no descriptor afterwards, also when close failed: Linux has released it then.

GetSize

The size of the file (fstat).

Syntax

ErrorCode GetSize(FileSize& size) const noexcept;

Parameters

sizeFileSize&
Receives the size in bytes; unchanged on failure.

Return value

Type: ErrorCode

Error::Success, or the errno of fstat.

SetEndOfFile

Sets the size of the file (ftruncate).

Syntax

ErrorCode SetEndOfFile(FileSize size) const noexcept;

Parameters

sizeFileSize
The new size in bytes; a larger file is cut, a smaller one grows with zeros.

Return value

Type: ErrorCode

Error::Success, or the errno of ftruncate.

Flush

Writes the file's data to the device (fdatasync); blocks until it is there.

Syntax

ErrorCode Flush() const noexcept;

Return value

Type: ErrorCode

Error::Success, or the errno of fdatasync.

Remarks

The data and what is needed to read it back (the size), not the times of last access and change; FlushFileBuffers on Windows writes those too. Cheaper, and all a reader needs.

WriteAt

Writes at an offset and blocks until done (pwrite).

Syntax

ErrorCode WriteAt(
    const void* buffer,
    std::size_t bytes,
    FileSize offset,
    std::size_t& written
) const noexcept;

Parameters

bufferconst void*
The data.
bytesstd::size_t
Number of bytes to write.
offsetFileSize
Where in the file.
writtenstd::size_t&
Receives the number of bytes written; may be less than asked.

Return value

Type: ErrorCode

Error::Success, or the errno of pwrite.

Delete

Removes a file (unlink).

Syntax

static ErrorCode Delete(FileName fileName) noexcept;

Parameters

fileNameFileName
Path of the file; must not be nullptr.

Return value

Type: ErrorCode

Error::Success, or the errno of unlink.

FlagsOf

The O_* flags that options stands for, without O_CLOEXEC.

Syntax

static int FlagsOf(const Platform::FileOptions& options) noexcept;

Parameters

optionsconst Platform::FileOptions&
How to open a file.

Return value

Type: int

The flags for open.

Types

FileName

Null-terminated path in UTF-8, as the system calls take it.

Syntax

using FileName = const char*;

FileSize

File size or offset in bytes.

Syntax

using FileSize = unsigned long long;

Generated from ThinkMeta.ConcurrentTasks.API @ da816bc (2026-11-06).