MCPcopy Create free account
hub / github.com/deathkiller/jazz2-native / RedirectFileDescriptorToNull

Function RedirectFileDescriptorToNull

Sources/Shared/IO/FileSystem.cpp:398–424  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

396
397# if defined(DEATH_TARGET_UNIX)
398 static bool RedirectFileDescriptorToNull(std::int32_t fd)
399 {
400 if (fd < 0) {
401 return false;
402 }
403
404 std::int32_t tempfd;
405 do {
406 tempfd = ::open("/dev/null", O_RDWR | O_NOCTTY);
407 } while (tempfd == -1 && errno == EINTR);
408
409 if (tempfd == -1) {
410 return false;
411 }
412
413 if (tempfd != fd) {
414 if (::dup2(tempfd, fd) == -1) {
415 ::close(tempfd);
416 return false;
417 }
418 if (::close(tempfd) == -1) {
419 return false;
420 }
421 }
422
423 return true;
424 }
425
426 static void TryCloseAllFileDescriptors()
427 {

Callers 1

LaunchDirectoryAsyncMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected