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

Function application_read_suspects

src/daemon/application.c:671–761  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

669static bool application_job_cancel_requested(cbm_daemon_application_job_t *job);
670
671static char **application_read_suspects(cbm_daemon_application_job_t *job, const char *path,
672 int *count_out, bool *cancelled_out) {
673 *count_out = 0;
674 *cancelled_out = false;
675 int64_t marker_size = cbm_file_size(path);
676 if (marker_size < 0 || marker_size > APPLICATION_MARKER_MAX_BYTES) {
677 return NULL;
678 }
679 FILE *file = cbm_fopen(path, "rb");
680 if (!file) {
681 return NULL;
682 }
683 char **open_paths = NULL;
684 int open_count = 0;
685 int open_capacity = 0;
686 bool allocation_failed = false;
687 size_t lines_read = 0;
688 char line[APPLICATION_PATH_CAP];
689 while (fgets(line, sizeof(line), file)) {
690 if ((lines_read++ & 255U) == 0U && application_job_cancel_requested(job)) {
691 *cancelled_out = true;
692 allocation_failed = true;
693 break;
694 }
695 size_t length = strlen(line);
696 if (length == 0 || line[length - 1] != '\n') {
697 break;
698 }
699 line[--length] = '\0';
700 if (length > 0 && line[length - 1] == '\r') {
701 line[--length] = '\0';
702 }
703 if (length < 3 || (line[0] != 'S' && line[0] != 'D') || line[1] != ' ') {
704 continue;
705 }
706 const char *relative = line + 2;
707 if (line[0] == 'S') {
708 if (open_count >= APPLICATION_MAX_SUSPECTS) {
709 allocation_failed = true;
710 break;
711 }
712 bool already_open = false;
713 for (int i = 0; i < open_count && !already_open; i++) {
714 already_open = strcmp(open_paths[i], relative) == 0;
715 }
716 if (already_open) {
717 continue;
718 }
719 if (open_count == open_capacity) {
720 int next_capacity = open_capacity ? open_capacity * 2 : 16;
721 char **next = realloc(open_paths, (size_t)next_capacity * sizeof(*next));
722 if (!next) {
723 allocation_failed = true;
724 break;
725 }
726 open_paths = next;
727 open_capacity = next_capacity;
728 }

Callers 1

Calls 3

cbm_file_sizeFunction · 0.85
cbm_fopenFunction · 0.85

Tested by

no test coverage detected