Git-Url: 
http://git.frugalware.org/gitweb/gitweb.cgi?p=pacman-g2.git;a=commitdiff;h=ccdade5e0866b9561a1445a6ae69fbe83a926b09

commit ccdade5e0866b9561a1445a6ae69fbe83a926b09
Author: Michel Hermier <herm...@frugalware.org>
Date:   Fri Jul 29 22:25:29 2011 +0200

util.h: introduce _pacman_{malloc,zalloc} helpers.

diff --git a/lib/libpacman/util.h b/lib/libpacman/util.h
index 7ff4a02..1542c05 100644
--- a/lib/libpacman/util.h
+++ b/lib/libpacman/util.h
@@ -26,6 +26,8 @@
#define _PACMAN_UTIL_H

#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
#if defined(__OpenBSD__)
#include "/usr/local/include/archive.h"
#include "/usr/local/include/archive_entry.h"
@@ -34,6 +36,8 @@
#include <archive_entry.h>
#endif

+#include "error.h"
+
#define FREE(p) do { if (p) { free(p); p = NULL; } } while(0)

#define ASSERT(cond, action) do { if(!(cond)) { action; } } while(0)
@@ -78,6 +82,24 @@ char* mkdtemp(char *template);
#endif
char *_pacman_archive_fgets(char *line, size_t size, struct archive *a);

+static inline void *_pacman_malloc(size_t size)
+{
+       void *ptr = malloc(size);
+       if(ptr == NULL) {
+               _pacman_log(PM_LOG_ERROR, _("malloc failure: could not allocate 
%d bytes"), size);
+               RET_ERR(PM_ERR_MEMORY, NULL);
+       }
+       return ptr;
+}
+
+static inline void *_pacman_zalloc(size_t size)
+{
+       void *ptr = _pacman_malloc(size);
+       if(ptr != NULL)
+               memset(ptr, 0, size);
+       return ptr;
+}
+
#endif /* _PACMAN_UTIL_H */

/* vim: set ts=2 sw=2 noet: */
_______________________________________________
Frugalware-git mailing list
Frugalware-git@frugalware.org
http://frugalware.org/mailman/listinfo/frugalware-git

Reply via email to