]> git.ozlabs.org Git - ccan/blob - tools/gcov.c
tools: Consolidate gcov handling
[ccan] / tools / gcov.c
1 #include "tools.h"
2 #include <stdlib.h>
3 #include <stdarg.h>
4
5 bool run_gcov(const void *ctx, unsigned int *time_ms, char **output,
6               const char *fmt, ...)
7 {
8         char *args;
9         va_list ap;
10         bool rc;
11
12         va_start(ap, fmt);
13         args = tal_vfmt(ctx, fmt, ap);
14         rc = run_command(ctx, time_ms, output, "gcov %s", args);
15         tal_free(args);
16         return rc;
17 }
18
19 const char *gcov_unavailable(void *ctx)
20 {
21         const char *err = NULL;
22
23 #ifdef __GNUC__
24         unsigned int timeleft = default_timeout_ms;
25         char *output;
26
27         if (!run_gcov(ctx, &timeleft, &output, "-h")) {
28                 err = tal_fmt(ctx, "No gcov support: %s", output);
29                 tal_free(output);
30         }
31 #else
32         err = "No coverage support for this compiler";
33 #endif
34
35         return err;
36 }