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

kbuild: split x*alloc() functions in kconfig to scripts/include/xalloc.h



These functions will be useful for other host programs.

Signed-off-by: default avatarMasahiro Yamada <masahiroy@kernel.org>
parent 96490176
Loading
Loading
Loading
Loading
+53 −0
Original line number Diff line number Diff line
/* SPDX-License-Identifier: GPL-2.0-only */

#ifndef XALLOC_H
#define XALLOC_H

#include <stdlib.h>
#include <string.h>

static inline void *xmalloc(size_t size)
{
	void *p = malloc(size);

	if (!p)
		exit(1);
	return p;
}

static inline void *xcalloc(size_t nmemb, size_t size)
{
	void *p = calloc(nmemb, size);

	if (!p)
		exit(1);
	return p;
}

static inline void *xrealloc(void *p, size_t size)
{
	p = realloc(p, size);
	if (!p)
		exit(1);
	return p;
}

static inline char *xstrdup(const char *s)
{
	char *p = strdup(s);

	if (!p)
		exit(1);
	return p;
}

static inline char *xstrndup(const char *s, size_t n)
{
	char *p = strndup(s, n);

	if (!p)
		exit(1);
	return p;
}

#endif /* XALLOC_H */
+1 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@
#include <time.h>
#include <unistd.h>

#include <xalloc.h>
#include "internal.h"
#include "lkc.h"

+1 −0
Original line number Diff line number Diff line
@@ -9,6 +9,7 @@
#include <stdlib.h>
#include <string.h>

#include <xalloc.h>
#include "lkc.h"

#define DEBUG_EXPR	0
+1 −0
Original line number Diff line number Diff line
@@ -13,6 +13,7 @@
#include <stdlib.h>
#include <string.h>

#include <xalloc.h>
#include "lkc.h"
#include "preprocess.h"

+0 −5
Original line number Diff line number Diff line
@@ -53,11 +53,6 @@ static inline void xfwrite(const void *str, size_t len, size_t count, FILE *out)
/* util.c */
unsigned int strhash(const char *s);
const char *file_lookup(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);
char *xstrndup(const char *s, size_t n);

/* lexer.l */
int yylex(void);
Loading