kconfig: remove const qualifier from sym_expand_string_value()
[carl9170fw.git] / config / util.c
index d0b8b2318e489577fd82713fd79b1759c3ff170b..b98a79e30e04a4017bd33264e85b2c40e46bc3af 100644 (file)
 struct file *file_lookup(const char *name)
 {
        struct file *file;
-       const char *file_name = sym_expand_string_value(name);
+       char *file_name = sym_expand_string_value(name);
 
        for (file = file_list; file; file = file->next) {
                if (!strcmp(name, file->name)) {
-                       free((void *)file_name);
+                       free(file_name);
                        return file;
                }
        }
 
-       file = malloc(sizeof(*file));
+       file = xmalloc(sizeof(*file));
        memset(file, 0, sizeof(*file));
        file->name = file_name;
        file->next = file_list;
@@ -81,23 +81,13 @@ int file_write_dep(const char *name)
 struct gstr str_new(void)
 {
        struct gstr gs;
-       gs.s = malloc(sizeof(char) * 64);
+       gs.s = xmalloc(sizeof(char) * 64);
        gs.len = 64;
        gs.max_width = 0;
        strcpy(gs.s, "\0");
        return gs;
 }
 
-/* Allocate and assign growable string */
-struct gstr str_assign(const char *s)
-{
-       struct gstr gs;
-       gs.s = strdup(s);
-       gs.len = strlen(s) + 1;
-       gs.max_width = 0;
-       return gs;
-}
-
 /* Free storage for growable string */
 void str_free(struct gstr *gs)
 {
@@ -114,7 +104,7 @@ void str_append(struct gstr *gs, const char *s)
        if (s) {
                l = strlen(gs->s) + strlen(s) + 1;
                if (l > gs->len) {
-                       gs->s   = realloc(gs->s, l);
+                       gs->s = xrealloc(gs->s, l);
                        gs->len = l;
                }
                strcat(gs->s, s);
@@ -138,3 +128,29 @@ const char *str_get(struct gstr *gs)
        return gs->s;
 }
 
+void *xmalloc(size_t size)
+{
+       void *p = malloc(size);
+       if (p)
+               return p;
+       fprintf(stderr, "Out of memory.\n");
+       exit(1);
+}
+
+void *xcalloc(size_t nmemb, size_t size)
+{
+       void *p = calloc(nmemb, size);
+       if (p)
+               return p;
+       fprintf(stderr, "Out of memory.\n");
+       exit(1);
+}
+
+void *xrealloc(void *p, size_t size)
+{
+       p = realloc(p, size);
+       if (p)
+               return p;
+       fprintf(stderr, "Out of memory.\n");
+       exit(1);
+}