Rev | Line | |
---|
[5261] | 1 | #ifdef HAVE_CONFIG_H |
---|
| 2 | # include "config.h" |
---|
| 3 | #endif |
---|
| 4 | |
---|
| 5 | #ifdef HAVE_STDLIB_H |
---|
| 6 | # include <stdlib.h> |
---|
| 7 | #endif |
---|
[5266] | 8 | #ifdef HAVE_STRING_H |
---|
| 9 | # include <string.h> |
---|
| 10 | #endif |
---|
[5261] | 11 | #include "error.h" |
---|
[5267] | 12 | #include "xfunctions.h" |
---|
[5261] | 13 | |
---|
[5266] | 14 | void *xmalloc(size_t size, const char *message){ |
---|
[5261] | 15 | void *mem; |
---|
| 16 | if((mem = malloc(size)) == NULL) |
---|
[5266] | 17 | AnugaVis_SetError("%s: Failed to malloc %d bytes", message, size); |
---|
[5261] | 18 | return mem; |
---|
| 19 | } |
---|
[5266] | 20 | |
---|
| 21 | #ifndef HAVE_STRDUP |
---|
| 22 | char *strdup(const char *s){ |
---|
| 23 | char *str; |
---|
| 24 | if((str = malloc(strlen(s) + 1)) != NULL) |
---|
| 25 | strcpy(str, s); |
---|
| 26 | return str; |
---|
| 27 | } |
---|
| 28 | #endif |
---|
| 29 | |
---|
| 30 | char *xstrdup(const char *s, const char *message){ |
---|
| 31 | char *str; |
---|
| 32 | if((str = strdup(s)) == NULL) |
---|
| 33 | AnugaVis_SetError("%s: Failed to strdup \"%s\"", message, s); |
---|
| 34 | return str; |
---|
| 35 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.