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