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