Changeset 5266
- Timestamp:
- May 2, 2008, 11:30:37 AM (17 years ago)
- Location:
- anuga_work/development/anugavis/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_work/development/anugavis/src/xmalloc.c
r5261 r5266 6 6 # include <stdlib.h> 7 7 #endif 8 #ifdef HAVE_STRING_H 9 # include <string.h> 10 #endif 8 11 #include "error.h" 9 12 #include "xmalloc.h" 10 13 11 void *xmalloc(size_t size, const char * func){14 void *xmalloc(size_t size, const char *message){ 12 15 void *mem; 13 16 if((mem = malloc(size)) == NULL) 14 AnugaVis_SetError(" Failed to malloc %d bytes in %s", size, func);17 AnugaVis_SetError("%s: Failed to malloc %d bytes", message, size); 15 18 return mem; 16 19 } 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 } -
anuga_work/development/anugavis/src/xmalloc.h
r5261 r5266 2 2 #define XMALLOC_H 3 3 4 /* Attempt a malloc. If it fails, set an error message and return NULL. 4 /* For a given func, xfunc behaves like func but sets an error message 5 * using AnugaVis_SetError(). 5 6 */ 6 extern void *xmalloc(size_t size, const char *func); 7 extern void *xmalloc(size_t size, const char *message); 8 extern char *xstrdup(const char *s, const char *message); 7 9 8 10 #endif
Note: See TracChangeset
for help on using the changeset viewer.