MCPcopy Create free account
hub / github.com/apache/nuttx / append

Function append

tools/mkdeps.c:224–256  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

222#endif
223
224static void append(char **base, const char *str)
225{
226 char *oldbase;
227 char *newbase;
228 int alloclen;
229
230 oldbase = *base;
231 if (!oldbase)
232 {
233 newbase = strdup(str);
234 if (!newbase)
235 {
236 fprintf(stderr, "ERROR: Failed to strdup %s\n", str);
237 exit(EXIT_FAILURE);
238 }
239 }
240 else
241 {
242 alloclen = strlen(oldbase) + strlen(str) +
243 sizeof((char) ' ') + sizeof((char) '\0');
244 newbase = malloc(alloclen);
245 if (!newbase)
246 {
247 fprintf(stderr, "ERROR: Failed to allocate %d bytes\n", alloclen);
248 exit(EXIT_FAILURE);
249 }
250
251 snprintf(newbase, alloclen, "%s %s", oldbase, str);
252 free(oldbase);
253 }
254
255 *base = newbase;
256}
257
258static void show_usage(const char *progname, const char *msg, int exitcode)
259{

Callers 1

parse_argsFunction · 0.70

Calls 7

strdupFunction · 0.85
fprintfFunction · 0.85
exitFunction · 0.85
strlenFunction · 0.50
mallocFunction · 0.50
snprintfFunction · 0.50
freeFunction · 0.50

Tested by

no test coverage detected