summary refs log tree commit diff
path: root/gnu
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2020-05-07 18:41:10 +0200
committerLudovic Courtès <ludo@gnu.org>2020-05-07 23:52:25 +0200
commit14928af2af501516aba13d569eae0853e769fb91 (patch)
tree3829b7d086c5f0f4f100707d532de0722615f7fe /gnu
parent4a53c19a325e7192c5aa6b0b34daf660ea615e17 (diff)
downloadguix-14928af2af501516aba13d569eae0853e769fb91.tar.gz
pack: Add 'xmalloc' in wrapper.
* gnu/packages/aux-files/run-in-namespace.c (xmalloc): New function.
(concat): Use it.
Diffstat (limited to 'gnu')
-rw-r--r--gnu/packages/aux-files/run-in-namespace.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/gnu/packages/aux-files/run-in-namespace.c b/gnu/packages/aux-files/run-in-namespace.c
index 37c493eeeb..501f096dc6 100644
--- a/gnu/packages/aux-files/run-in-namespace.c
+++ b/gnu/packages/aux-files/run-in-namespace.c
@@ -42,13 +42,21 @@
 #include <dirent.h>
 #include <sys/syscall.h>
 
+/* Like 'malloc', but abort if 'malloc' returns NULL.  */
+static void *
+xmalloc (size_t size)
+{
+  void *result = malloc (size);
+  assert (result != NULL);
+  return result;
+}
+
 /* Concatenate DIRECTORY, a slash, and FILE.  Return the result, which the
    caller must eventually free.  */
 static char *
 concat (const char *directory, const char *file)
 {
-  char *result = malloc (strlen (directory) + 2 + strlen (file));
-  assert (result != NULL);
+  char *result = xmalloc (strlen (directory) + 2 + strlen (file));
 
   strcpy (result, directory);
   strcat (result, "/");