MCPcopy Create free account
hub / github.com/GJDuck/e9patch / init

Function init

examples/cov.c:146–191  ·  view source on GitHub ↗

* Init. */

Source from the content-addressed store, hash-verified

144 * Init.
145 */
146void 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.

Callers

nothing calls this directly

Calls 11

isattyFunction · 0.85
asprintfFunction · 0.85
errorFunction · 0.85
strerrorFunction · 0.85
fopenFunction · 0.85
getcFunction · 0.85
fscanfFunction · 0.85
reallocFunction · 0.85
fcloseFunction · 0.85
freeFunction · 0.85
fprintfFunction · 0.70

Tested by

no test coverage detected