]> git.ozlabs.org Git - ccan/blobdiff - tools/read_config_header.c
base64: fix for unsigned chars (e.g. ARM).
[ccan] / tools / read_config_header.c
index b168a2f9494d50024410786159aeabef669c03df..da3e00cd73ba7088981d7a40ad3b995c4ad48e2b 100644 (file)
@@ -1,11 +1,10 @@
-#include <ccan/grab_file/grab_file.h>
+#include <ccan/err/err.h>
 #include <ccan/str/str.h>
-#include <ccan/str_talloc/str_talloc.h>
-#include <ccan/talloc/talloc.h>
+#include <ccan/tal/path/path.h>
+#include <ccan/tal/grab_file/grab_file.h>
 #include "read_config_header.h"
 #include "tools.h"
 #include <string.h>
-#include <err.h>
 
 /* Get an identifier token. */
 char *get_symbol_token(void *ctx, const char **line)
@@ -17,7 +16,7 @@ char *get_symbol_token(void *ctx, const char **line)
        toklen = strspn(*line, IDENT_CHARS);
        if (!toklen)
                return NULL;
-       ret = talloc_strndup(ctx, *line, toklen);
+       ret = tal_strndup(ctx, *line, toklen);
        *line += toklen;
        return ret;
 }
@@ -89,23 +88,22 @@ 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 = talloc_asprintf(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 = grab_file(NULL, fname, NULL);
-       talloc_free(fname);
+       config_header = grab_file(NULL, fname);
 
-       if (!config_header)
-               goto out;
+       if (!config_header) {
+               tal_free(fname);
+               return NULL;
+       }
 
-       lines = strsplit(config_header, config_header, "\n");
-       for (i = 0; i < talloc_array_length(lines) - 1; i++) {
+       lines = tal_strsplit(config_header, config_header, "\n", STR_EMPTY_OK);
+       for (i = 0; i < tal_count(lines) - 1; i++) {
                char *sym;
                const char **line = (const char **)&lines[i];
 
@@ -114,30 +112,24 @@ 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;
-
+       tal_free(fname);
        return config_header;
 }