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

Function TryCloseAllFileDescriptors

Sources/Shared/IO/FileSystem.cpp:426–454  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

424 }
425
426 static void TryCloseAllFileDescriptors()
427 {
428 DIR* d = ::opendir("/proc/self/fd/");
429 if (d == nullptr) {
430 const long fd_max = ::sysconf(_SC_OPEN_MAX);
431 long fd;
432 for (fd = 0; fd <= fd_max; fd++) {
433 ::close(fd);
434 }
435 return;
436 }
437
438 std::int32_t dfd = ::dirfd(d);
439 struct dirent* ent;
440 while ((ent = ::readdir(d)) != nullptr) {
441 if (ent->d_name[0] >= '0' && ent->d_name[0] <= '9') {
442 const char* p = &ent->d_name[1];
443 std::int32_t fd = ent->d_name[0] - '0';
444 while (*p >= '0' && *p <= '9') {
445 fd = (10 * fd) + *(p++) - '0';
446 }
447 if (*p || fd == dfd) {
448 continue;
449 }
450 ::close(fd);
451 }
452 }
453 ::closedir(d);
454 }
455# endif
456#endif
457

Callers 1

LaunchDirectoryAsyncMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected