]> Pileus Git - lackey/commitdiff
Add alloc0 and new0 functions
authorAndy Spencer <andy753421@gmail.com>
Sun, 2 Jun 2013 07:07:50 +0000 (07:07 +0000)
committerAndy Spencer <andy753421@gmail.com>
Tue, 4 Jun 2013 04:24:32 +0000 (04:24 +0000)
cals/ical.c
src/util.c
src/util.h

index 2a48bada91117467bf7f260d6697853f23451eb3..33df76c7ebbff68c21293cf79d0600acaae47fdd 100644 (file)
@@ -118,7 +118,7 @@ static event_t *to_event(ical_inst *inst)
 {
        icalproperty *prop = icalcomponent_get_first_property(inst->comp, ICAL_CATEGORIES_PROPERTY);
 
-       event_t *event = calloc(1, sizeof(event_t));
+       event_t *event = new0(event_t);
        event->name  = icalcomponent_get_summary(inst->comp);
        event->desc  = icalcomponent_get_description(inst->comp);
        event->loc   = icalcomponent_get_location(inst->comp);
@@ -155,7 +155,7 @@ static todo_t *to_todo(ical_inst *inst)
        icalproperty *cat  = icalcomponent_get_first_property(inst->comp, ICAL_CATEGORIES_PROPERTY);
        icalproperty *perc = icalcomponent_get_first_property(inst->comp, ICAL_PERCENTCOMPLETE_PROPERTY);
 
-       todo_t *todo = calloc(1, sizeof(todo_t));
+       todo_t *todo = new0(todo_t);
        todo->name   = icalcomponent_get_summary(inst->comp);
        todo->desc   = icalcomponent_get_description(inst->comp);
        todo->cat    = icalproperty_get_value_as_string(cat);
index e3f3a43a8015cb630302d507b45c66f8f7b43a02..131e9dea2e6261ccf4823030e4bde638a2bcff1d 100644 (file)
@@ -75,6 +75,15 @@ void strsub(char *str, char find, char repl)
                        *cur = repl;
 }
 
+/* Memory functions */
+void *alloc0(int size)
+{
+       void *data = calloc(1, size);
+       if (!data)
+               error("memory allocation failed");
+       return data;
+}
+
 /* Debugging functions */
 void debug(char *fmt, ...)
 {
index a424b7bd73e531dcd2e6a7fce0b197ede10cf3d9..d0baa3b37e28a7010eca8ff4ef0ddc4948114396 100644 (file)
 #define ROUND(x) ((int)((x)+0.5))
 #define N_ELEMENTS(x) (sizeof(x)/sizeof((x)[0]))
 
+#define new0(type) alloc0(sizeof(type))
+
 /* Debug functions */
 void util_init(void);
 
 /* Stirng functions */
 void strsub(char *str, char find, char repl);
 
+/* Memory functions */
+void *alloc0(int size);
+
 /* Debug functions */
 void debug(char *fmt, ...);
 void error(char *fmt, ...);