Nix 2.93.3
Lix: A modern, delicious implementation of the Nix package manager; unstable internal interfaces
Loading...
Searching...
No Matches
file-descriptor.hh
Go to the documentation of this file.
1#pragma once
3
6
7namespace nix {
8
9struct Sink;
10struct Source;
11
15std::string readLine(int fd);
16
20void writeLine(int fd, std::string s);
21
25std::string readFile(int fd);
26
31void readFull(int fd, char * buf, size_t count);
32void writeFull(int fd, std::string_view s, bool allowInterrupts = true);
33
37std::string drainFD(int fd, bool block = true, const size_t reserveSize=0);
38
39
40/*
41 * Will attempt to guess *A* path associated that might lead to the same file as used by this
42 * file descriptor.
43 *
44 * The returned string should NEVER be used as a valid path.
45 */
46std::string guessOrInventPathFromFD(int fd);
47
48Generator<Bytes> drainFDSource(int fd, bool block = true);
49
50class AutoCloseFD
51{
52 int fd;
53public:
54 AutoCloseFD();
55 explicit AutoCloseFD(int fd);
56 AutoCloseFD(const AutoCloseFD & fd) = delete;
57 AutoCloseFD(AutoCloseFD&& fd);
58 ~AutoCloseFD();
59 AutoCloseFD& operator =(const AutoCloseFD & fd) = delete;
60 AutoCloseFD& operator =(AutoCloseFD&& fd) noexcept(false);
61 int get() const;
62
63 /*
64 * Will attempt to guess *A* path associated that might lead to the same file as used by this
65 * file descriptor.
66 *
67 * The returned string should NEVER be used as a valid path.
68 */
69 std::string guessOrInventPath() const { return guessOrInventPathFromFD(fd); }
70
71 explicit operator bool() const;
72 int release();
73 void close();
74 void fsync();
75 void reset() { *this = {}; }
76};
77
78class Pipe
79{
80public:
81 AutoCloseFD readSide, writeSide;
82 void create();
83 void close();
84};
85
90void closeExtraFDs();
91
95void closeOnExec(int fd);
96
97MakeError(EndOfFile, Error);
98
99}
Definition file-descriptor.hh:51
Definition file-descriptor.hh:79
This file defines two main structs/classes used in nix error handling.
Definition generator.hh:236
Definition serialise.hh:18
Definition serialise.hh:66