diff options
Diffstat (limited to 'src/utils.c')
-rw-r--r-- | src/utils.c | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/src/utils.c b/src/utils.c new file mode 100644 index 0000000..05844da --- /dev/null +++ b/src/utils.c @@ -0,0 +1,52 @@ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <limits.h> +#include <unistd.h> + +#include <utils.h> + +void no_space( void ) +{ + char buf[MAX_ERROR_MSG_SIZE]; + char *format = "%s: Cannot allocate memory"; + + snprintf( buf, MAX_ERROR_MSG_SIZE, format, "sila" ); + + fprintf( stderr, "%s", buf ); +// FATAL_ERROR( "%s", buf ); + +// ++errors; +// exit( 1 ); +} + +void *xmalloc( size_t n ) +{ + void *p = NULL; + + p = malloc( n ); + if( !p ) no_space(); + bzero( p, n ); + + return( p ); +} + +void *xrealloc( void *b, size_t n ) +{ + void *p = NULL; + + p = realloc( b , n ); + if( !p ) no_space(); + + return( p ); +} + +char *dupstr( char *s ) +{ + char *r; + + r = xmalloc (strlen (s) + 1); + strcpy (r, s); + return (r); +} |