MCPcopy Create free account
hub / github.com/3rdparty/libprocess / FD

Method FD

src/subprocess.cpp:197–252  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

195
196
197Subprocess::IO Subprocess::FD(int_fd fd, IO::FDType type)
198{
199 return Subprocess::IO(
200 [fd, type]() -> Try<InputFileDescriptors> {
201 int_fd prepared_fd = -1;
202 switch (type) {
203 case IO::DUPLICATED: {
204 Try<int_fd> dup = os::dup(fd);
205 if (dup.isError()) {
206 return Error(dup.error());
207 }
208
209 prepared_fd = dup.get();
210 break;
211 }
212 case IO::OWNED: {
213 prepared_fd = fd;
214 break;
215 }
216
217 // NOTE: By not setting a default we leverage the compiler
218 // errors when the enumeration is augmented to find all
219 // the cases we need to provide. Same for below.
220 }
221
222 InputFileDescriptors fds;
223 fds.read = prepared_fd;
224 return fds;
225 },
226 [fd, type]() -> Try<OutputFileDescriptors> {
227 int_fd prepared_fd = -1;
228 switch (type) {
229 case IO::DUPLICATED: {
230 Try<int_fd> dup = os::dup(fd);
231 if (dup.isError()) {
232 return Error(dup.error());
233 }
234
235 prepared_fd = dup.get();
236 break;
237 }
238 case IO::OWNED: {
239 prepared_fd = fd;
240 break;
241 }
242
243 // NOTE: By not setting a default we leverage the compiler
244 // errors when the enumeration is augmented to find all
245 // the cases we need to provide. Same for below.
246 }
247
248 OutputFileDescriptors fds;
249 fds.write = prepared_fd;
250 return fds;
251 });
252}
253
254

Callers

nothing calls this directly

Calls 2

IOClass · 0.85
getMethod · 0.45

Tested by

no test coverage detected