X-Git-Url: http://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=tools%2Fread_config_header.c;h=da9ed0a3fad62bdd3330285ae67751ef8084c7d2;hp=bd268722bb2f9d7cb63c04a87c6f0e40dc08a28b;hb=adc90816df194167a588a943ae503a37fec3fb6a;hpb=dc8042b42500f79f613b1197df6cdf739615a89f diff --git a/tools/read_config_header.c b/tools/read_config_header.c index bd268722..da9ed0a3 100644 --- a/tools/read_config_header.c +++ b/tools/read_config_header.c @@ -1,5 +1,7 @@ #include #include +#include +#include #include "read_config_header.h" #include "tools.h" #include @@ -86,20 +88,18 @@ static char *demangle_string(char *string) return string; } -char *read_config_header(const char *ccan_dir, - const char **compiler, const char **cflags, - bool verbose) +char *read_config_header(const char *ccan_dir, bool verbose) { - char *fname = tal_fmt(NULL, "%s/config.h", ccan_dir); + char *fname = path_join(NULL, ccan_dir, "config.h"); char **lines; unsigned int i; char *config_header; - config_header = tal_grab_file(NULL, fname, NULL); + config_header = grab_file(NULL, fname); tal_free(fname); if (!config_header) - goto out; + return NULL; lines = tal_strsplit(config_header, config_header, "\n", STR_EMPTY_OK); for (i = 0; i < tal_count(lines) - 1; i++) { @@ -111,30 +111,23 @@ char *read_config_header(const char *ccan_dir, if (!get_token(line, "define")) continue; sym = get_symbol_token(lines, line); - if (streq(sym, "CCAN_COMPILER") && !compiler) { - *compiler = demangle_string(lines[i]); - if (!*compiler) + if (streq(sym, "CCAN_COMPILER")) { + compiler = demangle_string(lines[i]); + if (!compiler) errx(1, "%s:%u:could not parse CCAN_COMPILER", fname, i+1); if (verbose) printf("%s: compiler set to '%s'\n", - fname, *compiler); - } else if (streq(sym, "CCAN_CFLAGS") && !cflags) { - *cflags = demangle_string(lines[i]); - if (!*cflags) + fname, compiler); + } else if (streq(sym, "CCAN_CFLAGS")) { + cflags = demangle_string(lines[i]); + if (!cflags) errx(1, "%s:%u:could not parse CCAN_CFLAGS", fname, i+1); if (verbose) printf("%s: compiler flags set to '%s'\n", - fname, *cflags); + fname, cflags); } } - -out: - if (!*compiler) - *compiler = CCAN_COMPILER; - if (!*cflags) - *cflags = CCAN_CFLAGS; - return config_header; }