summaryrefslogtreecommitdiff
path: root/src/utils.c
blob: 05844da8ef9c2dcf2372ec6790ffe44b053cb538 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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);
}