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

Function application_read_suspects

src/daemon/application.c:955–1045  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

953 size_t *active_jobs_out);
954
955static char **application_read_suspects(cbm_daemon_application_job_t *job, const char *path,
956 int *count_out, bool *cancelled_out) {
957 *count_out = 0;
958 *cancelled_out = false;
959 int64_t marker_size = cbm_file_size(path);
960 if (marker_size < 0 || marker_size > APPLICATION_MARKER_MAX_BYTES) {
961 return NULL;
962 }
963 FILE *file = cbm_fopen(path, "rb");
964 if (!file) {
965 return NULL;
966 }
967 char **open_paths = NULL;
968 int open_count = 0;
969 int open_capacity = 0;
970 bool allocation_failed = false;
971 size_t lines_read = 0;
972 char line[APPLICATION_PATH_CAP];
973 while (fgets(line, sizeof(line), file)) {
974 if ((lines_read++ & 255U) == 0U && application_job_cancel_requested(job)) {
975 *cancelled_out = true;
976 allocation_failed = true;
977 break;
978 }
979 size_t length = strlen(line);
980 if (length == 0 || line[length - 1] != '\n') {
981 break;
982 }
983 line[--length] = '\0';
984 if (length > 0 && line[length - 1] == '\r') {
985 line[--length] = '\0';
986 }
987 if (length < 3 || (line[0] != 'S' && line[0] != 'D') || line[1] != ' ') {
988 continue;
989 }
990 const char *relative = line + 2;
991 if (line[0] == 'S') {
992 if (open_count >= APPLICATION_MAX_SUSPECTS) {
993 allocation_failed = true;
994 break;
995 }
996 bool already_open = false;
997 for (int i = 0; i < open_count && !already_open; i++) {
998 already_open = strcmp(open_paths[i], relative) == 0;
999 }
1000 if (already_open) {
1001 continue;
1002 }
1003 if (open_count == open_capacity) {
1004 int next_capacity = open_capacity ? open_capacity * 2 : 16;
1005 char **next = realloc(open_paths, (size_t)next_capacity * sizeof(*next));
1006 if (!next) {
1007 allocation_failed = true;
1008 break;
1009 }
1010 open_paths = next;
1011 open_capacity = next_capacity;
1012 }

Callers 1

Calls 3

cbm_file_sizeFunction · 0.85
cbm_fopenFunction · 0.85

Tested by

no test coverage detected