summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/xine-utils/utils.c21
-rw-r--r--src/xine-utils/xineutils.h6
2 files changed, 27 insertions, 0 deletions
diff --git a/src/xine-utils/utils.c b/src/xine-utils/utils.c
index fa0c11dbe..63c2e2f09 100644
--- a/src/xine-utils/utils.c
+++ b/src/xine-utils/utils.c
@@ -256,6 +256,27 @@ void *xine_xmalloc(size_t size) {
return ptr;
}
+/**
+ * @brief Wrapper around calloc() function.
+ * @param nmemb Number of elements to allocate
+ * @param size Size of each element to allocate
+ *
+ * This is a simple wrapper around calloc(), the only thing
+ * it does more than calloc() is outputting an error if
+ * the calloc fails (returning NULL).
+ */
+void *xine_xcalloc(size_t nmemb, size_t size) {
+ void *ptr;
+
+ if((ptr = calloc(nmemb, size)) == NULL) {
+ fprintf(stderr, "%s: calloc() failed: %s.\n",
+ __XINE_FUNCTION__, strerror(errno));
+ return NULL;
+ }
+
+ return ptr;
+}
+
void *xine_xmalloc_aligned(size_t alignment, size_t size, void **base) {
char *ptr;
diff --git a/src/xine-utils/xineutils.h b/src/xine-utils/xineutils.h
index 03c5f689a..20c3cb2dc 100644
--- a/src/xine-utils/xineutils.h
+++ b/src/xine-utils/xineutils.h
@@ -630,6 +630,12 @@ void *xine_xmalloc(size_t size) XINE_PROTECTED;
void *xine_xmalloc(size_t size) __attribute__ ((__malloc__)) XINE_PROTECTED;
#endif
+#if !defined(__GNUC__) || __GNUC__ < 3
+void *xine_xcalloc(size_t nmemb, size_t size) XINE_PROTECTED;
+#else
+void *xine_xcalloc(size_t nmemb, size_t size) __attribute__ ((__malloc__)) XINE_PROTECTED;
+#endif
+
/*
* Same as above, but memory is aligned to 'alignement'.
* **base is used to return pointer to un-aligned memory, use