* Contributors: Details at http://www.graphviz.org/
*************************************************************************/
-
-#include <stdio.h>
+#include <cgraph/alloc.h>
#include <stdlib.h>
#include <inttypes.h>
-#include <errno.h>
#include "generic_list.h"
generic_list_t *new_generic_list(uint64_t size)
{
- generic_list_t *list;
-
- list = malloc(sizeof(generic_list_t));
- if (list == NULL) {
- perror("[new_generic_list()] Error allocating memory:");
- return NULL;
- }
+ generic_list_t *list = gv_alloc(sizeof(generic_list_t));
if (size != 0) {
- list->data = malloc(size * sizeof(gl_data));
- if (list->data == NULL) {
- perror("[new_generic_list()] Error allocating memory:");
- free(list);
- return NULL;
- }
- } else
- list->data = NULL;
+ list->data = gv_calloc(size, sizeof(gl_data));
+ }
list->size = size;
- list->used = 0;
return list;
}
generic_list_t *add_to_generic_list(generic_list_t * list, gl_data element)
{
uint64_t new_size;
- gl_data *new_data;
if (list->size == list->used) {
if (list->size == 0) {
} else {
new_size = list->size * 2;
}
- new_data = realloc(list->data, new_size * sizeof(gl_data));
- if (new_data == NULL) {
- perror("[add_to_generic_list()] Error allocating memory:");
- return NULL;
- }
+ gl_data *new_data = gv_recalloc(list->data, list->size, new_size,
+ sizeof(gl_data));
list->data = new_data;
list->size = new_size;
}
#include <ctype.h>
#include <getopt.h>
-
+#include <cgraph/alloc.h>
#include <cgraph/cgraph.h>
#include <cgraph/exit.h>
#include <ingraphs/ingraphs.h>
generic_list_t *addattr(generic_list_t * l, char *a)
{
char *p;
- strattr_t *sp;
- sp = malloc(sizeof(strattr_t));
- if (sp == NULL) {
- perror("[addattr()->malloc()]");
- graphviz_exit(EXIT_FAILURE);
- }
+ strattr_t *sp = gv_alloc(sizeof(strattr_t));
/* Split argument spec. at first '=' */
p = strchr(a, '=');
*(p++) = '\0';
/* pointer to argument name */
- sp->n = strdup(a);
- if (sp->n == NULL) {
- perror("[addattr()->strdup()]");
- graphviz_exit(EXIT_FAILURE);
- }
+ sp->n = gv_strdup(a);
/* pointer to argument value */
- sp->v = strdup(p);
- if (sp->v == NULL) {
- perror("[addattr()->strdup()]");
- graphviz_exit(EXIT_FAILURE);
- }
+ sp->v = gv_strdup(p);
return add_to_generic_list(l, (gl_data) sp);
}
/* add element to node list */
generic_list_t *addnode(generic_list_t * l, char *n)
{
- char *sp;
-
- sp = strdup(n);
- if (sp == NULL) {
- perror("[addnode()->strdup()]");
- graphviz_exit(EXIT_FAILURE);
- }
+ char *sp = gv_strdup(n);
return add_to_generic_list(l, (gl_data) sp);
}