guix-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

02/03: pack: Add 'xmalloc' in wrapper.


From: guix-commits
Subject: 02/03: pack: Add 'xmalloc' in wrapper.
Date: Thu, 7 May 2020 17:52:49 -0400 (EDT)

civodul pushed a commit to branch master
in repository guix.

commit 14928af2af501516aba13d569eae0853e769fb91
Author: Ludovic Courtès <address@hidden>
AuthorDate: Thu May 7 18:41:10 2020 +0200

    pack: Add 'xmalloc' in wrapper.
    
    * gnu/packages/aux-files/run-in-namespace.c (xmalloc): New function.
    (concat): Use it.
---
 gnu/packages/aux-files/run-in-namespace.c | 12 ++++++++++--
 1 file 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 37c493e..501f096 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, "/");



reply via email to

[Prev in Thread] Current Thread [Next in Thread]