| 98 | } |
| 99 | |
| 100 | cbm_gitignore_t *cbm_gitignore_load(const char *path) { |
| 101 | if (!path) { |
| 102 | return NULL; |
| 103 | } |
| 104 | |
| 105 | FILE *f = cbm_fopen(path, "r"); |
| 106 | if (!f) { |
| 107 | return NULL; |
| 108 | } |
| 109 | |
| 110 | /* Read entire file */ |
| 111 | (void)fseek(f, 0, SEEK_END); |
| 112 | long size = ftell(f); |
| 113 | (void)fseek(f, 0, SEEK_SET); |
| 114 | |
| 115 | if (size <= 0) { |
| 116 | (void)fclose(f); |
| 117 | return cbm_gitignore_parse(""); |
| 118 | } |
| 119 | |
| 120 | char *buf = malloc(size + SKIP_ONE); |
| 121 | if (!buf) { |
| 122 | (void)fclose(f); |
| 123 | return NULL; |
| 124 | } |
| 125 | |
| 126 | size_t n = fread(buf, SKIP_ONE, size, f); |
| 127 | buf[n] = '\0'; |
| 128 | (void)fclose(f); |
| 129 | |
| 130 | cbm_gitignore_t *gi = cbm_gitignore_parse(buf); |
| 131 | free(buf); |
| 132 | return gi; |
| 133 | } |
| 134 | |
| 135 | int cbm_gitignore_match_result(const cbm_gitignore_t *gi, const char *rel_path, bool is_dir) { |
| 136 | if (!gi || !rel_path) { |
no test coverage detected