Files
Centos-kernel-stream-9/scripts/include/xalloc.h
T
Desnes Nunes e71cb77839 kbuild: split x*alloc() functions in kconfig to scripts/include/xalloc.h
JIRA: https://issues.redhat.com/browse/RHEL-78837
Conflicts:
  * Code changes due to the following (no functional change):
    - Avoiding commit <91b69454f93d> ("kconfig: use generic macros to im-
      plement symbol hashtable") that created the internal.h header
    - Avoiding commit <5b058034e3aa> ("kconfig: change file_lookup() to
      return the file name") that changed *file_lookup type to const char
    - Avoiding commit <7c4aa901bd9d> ("kconfig: move strhash() to util.c
      as a global function") that moved strhash()'s definition to lkc.h
    - Performing a partial backport of commit <fbaf242c956a> ("kbuild:
      move some helper headers from scripts/kconfig/ to scripts/include/")
      here only targetting infrastructure compilation changes (e.g.,
      Makefile) needed by the new xalloc.h file created on this patch. The
      helper functions in xalloc.h will be used by new functions of latter
      commits in this MR (e.g., module_alias_printf()).

commit a9d83d74783b00f9189c14180f77bbed133b092c
Author: Masahiro Yamada <masahiroy@kernel.org>
Date: Mon, 12 Aug 2024 21:48:50 +0900

  These functions will be useful for other host programs.

  Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>

Signed-off-by: Desnes Nunes <desnesn@redhat.com>
2025-06-12 16:47:10 -03:00

54 lines
699 B
C

/* 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 */