MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / count_open_fds

Function count_open_fds

src/foundation/diagnostics.c:64–91  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

62/* ── FD count (platform-specific) ────────────────────────────────── */
63
64static int count_open_fds(void) {
65#ifdef __linux__
66 struct dirent **entries = NULL;
67 int n = scandir("/proc/self/fd", &entries, NULL, NULL);
68 if (n < 0) {
69 return CBM_NOT_FOUND;
70 }
71 for (int i = 0; i < n; i++) {
72 free(entries[i]);
73 }
74 free(entries);
75 return n - PAIR_LEN; /* . and .. */
76#elif defined(__APPLE__)
77 /* Count via /dev/fd using scandir (MT-safe) */
78 struct dirent **entries = NULL;
79 int n = scandir("/dev/fd", &entries, NULL, NULL);
80 if (n < 0) {
81 return CBM_NOT_FOUND;
82 }
83 for (int i = 0; i < n; i++) {
84 free(entries[i]);
85 }
86 free(entries);
87 return n - PAIR_LEN; /* . and .. */
88#else
89 return CBM_NOT_FOUND; /* Not available on Windows */
90#endif
91}
92
93/* ── Writer ──────────────────────────────────────────────────────── */
94

Callers 1

write_diagnosticsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected