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

Function application_read_suspects

src/daemon/application.c:700–790  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

698 size_t *active_jobs_out);
699
700static char **application_read_suspects(cbm_daemon_application_job_t *job, const char *path,
701 int *count_out, bool *cancelled_out) {
702 *count_out = 0;
703 *cancelled_out = false;
704 int64_t marker_size = cbm_file_size(path);
705 if (marker_size < 0 || marker_size > APPLICATION_MARKER_MAX_BYTES) {
706 return NULL;
707 }
708 FILE *file = cbm_fopen(path, "rb");
709 if (!file) {
710 return NULL;
711 }
712 char **open_paths = NULL;
713 int open_count = 0;
714 int open_capacity = 0;
715 bool allocation_failed = false;
716 size_t lines_read = 0;
717 char line[APPLICATION_PATH_CAP];
718 while (fgets(line, sizeof(line), file)) {
719 if ((lines_read++ & 255U) == 0U && application_job_cancel_requested(job)) {
720 *cancelled_out = true;
721 allocation_failed = true;
722 break;
723 }
724 size_t length = strlen(line);
725 if (length == 0 || line[length - 1] != '\n') {
726 break;
727 }
728 line[--length] = '\0';
729 if (length > 0 && line[length - 1] == '\r') {
730 line[--length] = '\0';
731 }
732 if (length < 3 || (line[0] != 'S' && line[0] != 'D') || line[1] != ' ') {
733 continue;
734 }
735 const char *relative = line + 2;
736 if (line[0] == 'S') {
737 if (open_count >= APPLICATION_MAX_SUSPECTS) {
738 allocation_failed = true;
739 break;
740 }
741 bool already_open = false;
742 for (int i = 0; i < open_count && !already_open; i++) {
743 already_open = strcmp(open_paths[i], relative) == 0;
744 }
745 if (already_open) {
746 continue;
747 }
748 if (open_count == open_capacity) {
749 int next_capacity = open_capacity ? open_capacity * 2 : 16;
750 char **next = realloc(open_paths, (size_t)next_capacity * sizeof(*next));
751 if (!next) {
752 allocation_failed = true;
753 break;
754 }
755 open_paths = next;
756 open_capacity = next_capacity;
757 }

Callers 1

Calls 3

cbm_file_sizeFunction · 0.85
cbm_fopenFunction · 0.85

Tested by

no test coverage detected