| 80 | } |
| 81 | |
| 82 | static char *agent_read(const char *path) { |
| 83 | FILE *fp = fopen(path, "rb"); |
| 84 | if (!fp || fseek(fp, 0L, SEEK_END) != 0) { |
| 85 | if (fp) { |
| 86 | fclose(fp); |
| 87 | } |
| 88 | return NULL; |
| 89 | } |
| 90 | long length = ftell(fp); |
| 91 | if (length < 0L || fseek(fp, 0L, SEEK_SET) != 0) { |
| 92 | fclose(fp); |
| 93 | return NULL; |
| 94 | } |
| 95 | char *text = (char *)malloc((size_t)length + 1U); |
| 96 | if (!text) { |
| 97 | fclose(fp); |
| 98 | return NULL; |
| 99 | } |
| 100 | size_t read_count = fread(text, 1U, (size_t)length, fp); |
| 101 | int close_rc = fclose(fp); |
| 102 | if (read_count != (size_t)length || close_rc != 0) { |
| 103 | free(text); |
| 104 | return NULL; |
| 105 | } |
| 106 | text[read_count] = '\0'; |
| 107 | return text; |
| 108 | } |
| 109 | |
| 110 | static size_t agent_occurrences(const char *text, const char *needle) { |
| 111 | size_t count = 0U; |
no test coverage detected