OSDN Git Service

Add xtalloc_reference.
authorCarl Worth <cworth@cworth.org>
Tue, 25 May 2010 21:40:47 +0000 (14:40 -0700)
committerCarl Worth <cworth@cworth.org>
Tue, 25 May 2010 21:40:47 +0000 (14:40 -0700)
Yet another talloc wrapper that should come in handy.

glcpp.h
xtalloc.c

diff --git a/glcpp.h b/glcpp.h
index 503731b..6171ce8 100644 (file)
--- a/glcpp.h
+++ b/glcpp.h
@@ -164,4 +164,10 @@ xtalloc_strndup (const void *t, const char *p, size_t n);
 char *
 xtalloc_asprintf (const void *t, const char *fmt, ...);
 
+void *
+_xtalloc_reference_loc (const void *context,
+                       const void *ptr, const char *location);
+
+#define xtalloc_reference(ctx, ptr) (_TALLOC_TYPEOF(ptr))_xtalloc_reference_loc((ctx),(ptr), __location__)
+
 #endif
index e52d12a..656ac2d 100644 (file)
--- a/xtalloc.c
+++ b/xtalloc.c
@@ -82,3 +82,18 @@ xtalloc_asprintf (const void *t, const char *fmt, ...)
        va_end(ap);
        return ret;
 }
+
+void *
+_xtalloc_reference_loc (const void *context,
+                       const void *ptr, const char *location)
+{
+       void *ret;
+
+       ret = _talloc_reference_loc (context, ptr, location);
+       if (ret == NULL) {
+               fprintf (stderr, "Out of memory.\n");
+               exit (1);
+       }
+
+       return ret;
+}