17# define WIN32_LEAN_AND_MEAN
60 return reinterpret_cast<HANDLE
>(_get_osfhandle(fd));
69std::string readFile(Descriptor fd);
82size_t read(Descriptor fd, std::span<std::byte> buffer);
95size_t write(Descriptor fd, std::span<const std::byte> buffer,
bool allowInterrupts);
106std::make_unsigned_t<off_t> getFileSize(Descriptor fd);
120size_t readOffset(Descriptor fd, off_t offset, std::span<std::byte> buffer);
131void copyFdRange(Descriptor fd, off_t offset,
size_t nbytes, Sink & sink,
bool tryCoW =
false);
137void readFull(Descriptor fd,
char * buf,
size_t count);
139void writeFull(Descriptor fd, std::string_view s,
bool allowInterrupts =
true);
151std::string readLine(Descriptor fd,
bool eofOk =
false,
char terminator =
'\n');
156void writeLine(Descriptor fd, std::string s);
161void syncDescriptor(Descriptor fd);
190 std::make_unsigned_t<off_t>
size = 0;
220void drainFD(Descriptor fd, Sink & sink, DrainFdSinkOpts opts = {});
225[[gnu::always_inline]]
231 return GetStdHandle(STD_INPUT_HANDLE);
238[[gnu::always_inline]]
242 return STDOUT_FILENO;
244 return GetStdHandle(STD_OUTPUT_HANDLE);
251[[gnu::always_inline]]
255 return STDERR_FILENO;
257 return GetStdHandle(STD_ERROR_HANDLE);
268 AutoCloseFD() noexcept
269 : fd(INVALID_DESCRIPTOR)
278 AutoCloseFD(
const AutoCloseFD & fd) =
delete;
279 AutoCloseFD(AutoCloseFD && fd)
noexcept;
281 AutoCloseFD & operator=(
const AutoCloseFD & fd) =
delete;
283 AutoCloseFD & operator=(AutoCloseFD && fd);
290 explicit operator bool()
const noexcept
292 return fd != INVALID_DESCRIPTOR;
303 if (fd != INVALID_DESCRIPTOR)
321AutoCloseFD dupDescriptor(Descriptor fd);
328AutoCloseFD openNullFD();
337 bool nonBlocking =
false
370void closeExtraFDs(std::span<const Descriptor> keepExtra);
404void setHandleInheritability(
Descriptor fd,
bool inherit);
409MakeError(EndOfFile, Error);
421Result<off_t, NativeError> seek(Descriptor fd, off_t offset,
int whence);
Definition file-descriptor.hh:265
void startFsync() const
Definition file-descriptor.cc:289
void fsync() const
Definition file-descriptor.hh:301
Definition file-descriptor.hh:331
This file defines two main structs/classes used in nix error handling.
Descriptor getStandardError()
Definition file-descriptor.hh:252
int Descriptor
Definition file-descriptor.hh:36
Descriptor getStandardOutput()
Definition file-descriptor.hh:239
void syncDescriptor(Descriptor fd)
Definition file-descriptor.cc:243
Descriptor getStandardInput()
Definition file-descriptor.hh:226
void closeOnExec(Descriptor fd)
Definition file-descriptor.cc:228
Definition file-descriptor.hh:185
bool expected
Definition file-descriptor.hh:195
bool block
Definition file-descriptor.hh:201
std::make_unsigned_t< off_t > size
Definition file-descriptor.hh:190
Definition file-descriptor.hh:167
std::optional< std::make_unsigned_t< off_t > > expectedSize
Definition file-descriptor.hh:171
bool block
Definition file-descriptor.hh:177
Definition serialise.hh:18
Definition serialise.hh:95
Definition file-descriptor.hh:377
void notify()
Definition file-descriptor.cc:261
void drain()
Definition file-descriptor.cc:273
Errors from the operating system: SystemError, and its subclasses for the native error codes,...