Commit cd81fc82 authored by Masahiro Yamada's avatar Masahiro Yamada

kconfig: add xstrdup() helper

We already have xmalloc(), xcalloc(), and xrealloc(().  Add xstrdup()
as well to save tedious error handling.
Signed-off-by: default avatarMasahiro Yamada <yamada.masahiro@socionext.com>
parent 6c49f359
...@@ -178,7 +178,7 @@ static int conf_set_sym_val(struct symbol *sym, int def, int def_flags, char *p) ...@@ -178,7 +178,7 @@ static int conf_set_sym_val(struct symbol *sym, int def, int def_flags, char *p)
case S_HEX: case S_HEX:
done: done:
if (sym_string_valid(sym, p)) { if (sym_string_valid(sym, p)) {
sym->def[def].val = strdup(p); sym->def[def].val = xstrdup(p);
sym->flags |= def_flags; sym->flags |= def_flags;
} else { } else {
if (def != S_DEF_AUTO) if (def != S_DEF_AUTO)
......
...@@ -101,7 +101,7 @@ static struct message *message__new(const char *msg, char *option, ...@@ -101,7 +101,7 @@ static struct message *message__new(const char *msg, char *option,
if (self->files == NULL) if (self->files == NULL)
goto out_fail; goto out_fail;
self->msg = strdup(msg); self->msg = xstrdup(msg);
if (self->msg == NULL) if (self->msg == NULL)
goto out_fail_msg; goto out_fail_msg;
......
...@@ -115,6 +115,7 @@ int file_write_dep(const char *name); ...@@ -115,6 +115,7 @@ int file_write_dep(const char *name);
void *xmalloc(size_t size); void *xmalloc(size_t size);
void *xcalloc(size_t nmemb, size_t size); void *xcalloc(size_t nmemb, size_t size);
void *xrealloc(void *p, size_t size); void *xrealloc(void *p, size_t size);
char *xstrdup(const char *s);
struct gstr { struct gstr {
size_t len; size_t len;
......
...@@ -183,7 +183,7 @@ static void sym_validate_range(struct symbol *sym) ...@@ -183,7 +183,7 @@ static void sym_validate_range(struct symbol *sym)
sprintf(str, "%lld", val2); sprintf(str, "%lld", val2);
else else
sprintf(str, "0x%llx", val2); sprintf(str, "0x%llx", val2);
sym->curr.val = strdup(str); sym->curr.val = xstrdup(str);
} }
static void sym_set_changed(struct symbol *sym) static void sym_set_changed(struct symbol *sym)
...@@ -849,7 +849,7 @@ struct symbol *sym_lookup(const char *name, int flags) ...@@ -849,7 +849,7 @@ struct symbol *sym_lookup(const char *name, int flags)
: !(symbol->flags & (SYMBOL_CONST|SYMBOL_CHOICE)))) : !(symbol->flags & (SYMBOL_CONST|SYMBOL_CHOICE))))
return symbol; return symbol;
} }
new_name = strdup(name); new_name = xstrdup(name);
} else { } else {
new_name = NULL; new_name = NULL;
hash = 0; hash = 0;
......
...@@ -154,3 +154,14 @@ void *xrealloc(void *p, size_t size) ...@@ -154,3 +154,14 @@ void *xrealloc(void *p, size_t size)
fprintf(stderr, "Out of memory.\n"); fprintf(stderr, "Out of memory.\n");
exit(1); exit(1);
} }
char *xstrdup(const char *s)
{
char *p;
p = strdup(s);
if (p)
return p;
fprintf(stderr, "Out of memory.\n");
exit(1);
}
...@@ -127,7 +127,7 @@ no_mainmenu_stmt: /* empty */ ...@@ -127,7 +127,7 @@ no_mainmenu_stmt: /* empty */
* later regardless of whether it comes from the 'prompt' in * later regardless of whether it comes from the 'prompt' in
* mainmenu_stmt or here * mainmenu_stmt or here
*/ */
menu_add_prompt(P_MENU, strdup("Linux Kernel Configuration"), NULL); menu_add_prompt(P_MENU, xstrdup("Linux Kernel Configuration"), NULL);
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment