]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
kbuild: split x*alloc() functions in kconfig to scripts/include/xalloc.h
authorMasahiro Yamada <masahiroy@kernel.org>
Mon, 12 Aug 2024 12:48:50 +0000 (21:48 +0900)
committerMasahiro Yamada <masahiroy@kernel.org>
Sun, 1 Sep 2024 11:34:48 +0000 (20:34 +0900)
These functions will be useful for other host programs.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
14 files changed:
scripts/include/xalloc.h [new file with mode: 0644]
scripts/kconfig/confdata.c
scripts/kconfig/expr.c
scripts/kconfig/lexer.l
scripts/kconfig/lkc.h
scripts/kconfig/mconf.c
scripts/kconfig/menu.c
scripts/kconfig/nconf.c
scripts/kconfig/nconf.gui.c
scripts/kconfig/parser.y
scripts/kconfig/preprocess.c
scripts/kconfig/qconf.cc
scripts/kconfig/symbol.c
scripts/kconfig/util.c

diff --git a/scripts/include/xalloc.h b/scripts/include/xalloc.h
new file mode 100644 (file)
index 0000000..cdadb07
--- /dev/null
@@ -0,0 +1,53 @@
+/* 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 */
index 76193ce5a79297ac1b67e56d2fca3a2d97fab237..d8849dfb06dbbfc4f5d2757b213bad11cf1d8f3d 100644 (file)
@@ -18,6 +18,7 @@
 #include <time.h>
 #include <unistd.h>
 
+#include <xalloc.h>
 #include "internal.h"
 #include "lkc.h"
 
index c349da7fe3f88d6c0fc7eb51b9bc50fe66cc1017..a16451347f63239ff71c82decae82ef4f341d7b2 100644 (file)
@@ -9,6 +9,7 @@
 #include <stdlib.h>
 #include <string.h>
 
+#include <xalloc.h>
 #include "lkc.h"
 
 #define DEBUG_EXPR     0
index 8dd597c4710dcbf8a2f638d022afe29a52d25b96..9c2cdfc33c6f06a0f93e0c6ebe9b217dc3280150 100644 (file)
@@ -13,6 +13,7 @@
 #include <stdlib.h>
 #include <string.h>
 
+#include <xalloc.h>
 #include "lkc.h"
 #include "preprocess.h"
 
index 401bdf36323a9a3fbedb46a554b17d27193bbb5f..ddfb2b1cb7375c3e83f7423f1d795f1a6aa1becd 100644 (file)
@@ -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);
index 3887eac7528938474a03c8e96269ef3c0fb09d63..84ea9215c0a7ee28888c6c9e9216283919ddd97e 100644 (file)
@@ -20,6 +20,7 @@
 #include <unistd.h>
 
 #include <list.h>
+#include <xalloc.h>
 #include "lkc.h"
 #include "lxdialog/dialog.h"
 #include "mnconf-common.h"
index 854edeb4d2db0f886921dc8df78b5729de3549d7..f61327fabead895e5b8539cef0b2b5416cbc7c52 100644 (file)
@@ -9,6 +9,7 @@
 #include <string.h>
 
 #include <list.h>
+#include <xalloc.h>
 #include "lkc.h"
 #include "internal.h"
 
index b91ca47e9e9a0fb227e1c797617e55efd51b63e6..063b4f7ccbdb369b96a01a9413f8ade5393beea9 100644 (file)
@@ -12,6 +12,7 @@
 #include <stdlib.h>
 
 #include <list.h>
+#include <xalloc.h>
 #include "lkc.h"
 #include "mnconf-common.h"
 #include "nconf.h"
index 25a7263ef3c8c586f0c199f0c5a0d3aef1292193..72b605efe549d9d82b2e8a0f29bf47036ea07e67 100644 (file)
@@ -4,6 +4,7 @@
  *
  * Derived from menuconfig.
  */
+#include <xalloc.h>
 #include "nconf.h"
 #include "lkc.h"
 
index 2d5e5ed56abaa8b502aa007f2ad5c9f259243e09..1ad60f9e164e496c989f8d6ce6d37bc9b2ab62c9 100644 (file)
@@ -11,6 +11,7 @@
 #include <string.h>
 #include <stdbool.h>
 
+#include <xalloc.h>
 #include "lkc.h"
 #include "internal.h"
 #include "preprocess.h"
index 67d1fb95c4912c6824d51eb0607cf45689142c99..783abcaa5cc5eed162b73d32dcdd7b9678a2a176 100644 (file)
@@ -11,6 +11,7 @@
 
 #include <array_size.h>
 #include <list.h>
+#include <xalloc.h>
 #include "internal.h"
 #include "lkc.h"
 #include "preprocess.h"
index 88797d1742612d7361b3d68a88f34b50b36f1b5d..97fce13e551ef3ab41c204380838e182a4128c65 100644 (file)
@@ -22,6 +22,7 @@
 
 #include <stdlib.h>
 
+#include <xalloc.h>
 #include "lkc.h"
 #include "qconf.h"
 
index d75665f3dfa26cdd2030114a2743189e2751d12b..6793f016af5e8b4903be985c237e2d485a323c98 100644 (file)
@@ -9,6 +9,7 @@
 #include <string.h>
 #include <regex.h>
 
+#include <xalloc.h>
 #include "internal.h"
 #include "lkc.h"
 
index 696ff477671ecc788a0bb71e1ed7a136068e521b..50698fff5b9d6da69bf1a7e7dd84dd7f0f4df20a 100644 (file)
@@ -9,6 +9,7 @@
 #include <string.h>
 
 #include <hashtable.h>
+#include <xalloc.h>
 #include "lkc.h"
 
 unsigned int strhash(const char *s)
@@ -102,52 +103,3 @@ char *str_get(const 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);
-}
-
-char *xstrdup(const char *s)
-{
-       char *p;
-
-       p = strdup(s);
-       if (p)
-               return p;
-       fprintf(stderr, "Out of memory.\n");
-       exit(1);
-}
-
-char *xstrndup(const char *s, size_t n)
-{
-       char *p;
-
-       p = strndup(s, n);
-       if (p)
-               return p;
-       fprintf(stderr, "Out of memory.\n");
-       exit(1);
-}