| 98 | /* ── FD count (platform-specific) ──────────────────────────────────────── */ |
| 99 | |
| 100 | static int count_open_fds(void) { |
| 101 | #ifdef __linux__ |
| 102 | struct dirent **entries = NULL; |
| 103 | int n = scandir("/proc/self/fd", &entries, NULL, NULL); |
| 104 | if (n < 0) { |
| 105 | return CBM_NOT_FOUND; |
| 106 | } |
| 107 | for (int i = 0; i < n; i++) { |
| 108 | free(entries[i]); |
| 109 | } |
| 110 | free(entries); |
| 111 | return n - PAIR_LEN; |
| 112 | #elif defined(__APPLE__) |
| 113 | struct dirent **entries = NULL; |
| 114 | int n = scandir("/dev/fd", &entries, NULL, NULL); |
| 115 | if (n < 0) { |
| 116 | return CBM_NOT_FOUND; |
| 117 | } |
| 118 | for (int i = 0; i < n; i++) { |
| 119 | free(entries[i]); |
| 120 | } |
| 121 | free(entries); |
| 122 | return n - PAIR_LEN; |
| 123 | #else |
| 124 | return CBM_NOT_FOUND; |
| 125 | #endif |
| 126 | } |
| 127 | |
| 128 | /* ── Private output directory ────────────────────────────────────────────── */ |
| 129 | |