* Init. */
| 144 | * Init. |
| 145 | */ |
| 146 | void init(int argc, char **argv, char **envp) |
| 147 | { |
| 148 | option_tty = isatty(STDERR_FILENO); |
| 149 | const char *progname = argv[0]; |
| 150 | |
| 151 | char *input; |
| 152 | if (asprintf(&input, "%s.BBs.csv", progname) < 0) |
| 153 | error("failed to create input filename: %s", strerror(errno)); |
| 154 | stream = fopen(input, "r"); |
| 155 | if (stream == NULL) |
| 156 | error("failed to open \"%s%s%s\" for reading: %s", YELLOW, input, |
| 157 | OFF, strerror(errno)); |
| 158 | char c; |
| 159 | while ((c = getc(stream)) != '\n' && c != EOF) |
| 160 | ; |
| 161 | void *lb, *ub; |
| 162 | while (fscanf(stream, "%p,%p", &lb, &ub) == 2) |
| 163 | { |
| 164 | if (BBs.size >= BBs.max) |
| 165 | { |
| 166 | BBs.max = (BBs.max == 0? 16: 2 * BBs.max); |
| 167 | BBs.data = (uintptr_t *)realloc(BBs.data, |
| 168 | BBs.max * sizeof(uintptr_t)); |
| 169 | if (BBs.data == NULL) |
| 170 | { |
| 171 | bad_realloc: |
| 172 | error("failed to allocate memory: %s", strerror(errno)); |
| 173 | } |
| 174 | } |
| 175 | BBs.data[BBs.size++] = (uintptr_t)lb; |
| 176 | } |
| 177 | BBs.size++; |
| 178 | BBs.max = BBs.size; |
| 179 | BBs.data = (uintptr_t *)realloc(BBs.data, BBs.max * sizeof(uintptr_t)); |
| 180 | if (BBs.data == NULL) |
| 181 | goto bad_realloc; |
| 182 | BBs.data[BBs.size-1] = UINTPTR_MAX; |
| 183 | fclose(stream); |
| 184 | stream = NULL; |
| 185 | fprintf(stderr, "%sCOV%s: parsed %s%zu%s basic-blocks from \"%s%s%s\"\n", |
| 186 | GREEN, OFF, YELLOW, BBs.size-1, OFF, YELLOW, input, OFF); |
| 187 | free(input); |
| 188 | |
| 189 | if (asprintf(&output, "%s.COV.csv", progname) < 0) |
| 190 | error("failed to create output filename: %s", strerror(errno)); |
| 191 | } |
| 192 | |
| 193 | /* |
| 194 | * Fini. |
nothing calls this directly
no test coverage detected