Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit cd81fc82 authored by Masahiro Yamada's avatar Masahiro Yamada
Browse files

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
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -178,7 +178,7 @@ static int conf_set_sym_val(struct symbol *sym, int def, int def_flags, char *p)
	case S_HEX:
	done:
		if (sym_string_valid(sym, p)) {
			sym->def[def].val = strdup(p);
			sym->def[def].val = xstrdup(p);
			sym->flags |= def_flags;
		} else {
			if (def != S_DEF_AUTO)
+1 −1
Original line number Diff line number Diff line
@@ -101,7 +101,7 @@ static struct message *message__new(const char *msg, char *option,
	if (self->files == NULL)
		goto out_fail;

	self->msg = strdup(msg);
	self->msg = xstrdup(msg);
	if (self->msg == NULL)
		goto out_fail_msg;

+1 −0
Original line number Diff line number Diff line
@@ -115,6 +115,7 @@ int file_write_dep(const char *name);
void *xmalloc(size_t size);
void *xcalloc(size_t nmemb, size_t size);
void *xrealloc(void *p, size_t size);
char *xstrdup(const char *s);

struct gstr {
	size_t len;
+2 −2
Original line number Diff line number Diff line
@@ -183,7 +183,7 @@ static void sym_validate_range(struct symbol *sym)
		sprintf(str, "%lld", val2);
	else
		sprintf(str, "0x%llx", val2);
	sym->curr.val = strdup(str);
	sym->curr.val = xstrdup(str);
}

static void sym_set_changed(struct symbol *sym)
@@ -849,7 +849,7 @@ struct symbol *sym_lookup(const char *name, int flags)
				   : !(symbol->flags & (SYMBOL_CONST|SYMBOL_CHOICE))))
				return symbol;
		}
		new_name = strdup(name);
		new_name = xstrdup(name);
	} else {
		new_name = NULL;
		hash = 0;
+11 −0
Original line number Diff line number Diff line
@@ -154,3 +154,14 @@ void *xrealloc(void *p, size_t size)
	fprintf(stderr, "Out of memory.\n");
	exit(1);
}

char *xstrdup(const char *s)
{
	char *p;

	p = strdup(s);
	if (p)
		return p;
	fprintf(stderr, "Out of memory.\n");
	exit(1);
}
Loading