summaryrefslogtreecommitdiff
path: root/libiberty/neutral.c
blob: cbf1a1da62a82a22aeeb6675c994e863bd33a3b7 (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
#define _GNU_SOURCE

#include <stddef.h>
#include <errno.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>

#include <config.h>

void   xexit(int status) 			{_exit(status); return;}
int    xatexit(void (*function)(void))		{return atexit(function);}
void * xcalloc(size_t nmemb, size_t size)	{return calloc(nmemb,size);}
void * xrealloc(void *ptr, size_t size) 	{return realloc(ptr,size);}
char * xstrdup(const char *s)			{return strdup(s);}
char * xstrndup(const char *s, size_t n)	{return strndup(s,n);}
void * xmalloc(size_t block_size)		{return malloc(block_size);}

void * xmemdup (const void * src, size_t copy_size, size_t alloc_size)
{
	void * dst = calloc (1, alloc_size);
	return dst ? memcpy(dst, src, copy_size) : 0;
}

void xmalloc_set_program_name (const char *s)
{
	return;
}

void xmalloc_failed (size_t size)
{
	fputs("malloc failed, aborting.\n\0",stderr);
	_exit(1);
}

static char errdesc_fallback[64];

char * xstrerror(int errnum)
{
	char * errdesc;

	if ((errdesc = strerror(errnum)))
		return errdesc;

	sprintf(errdesc_fallback,"Undocumented error %d.",errnum);
	return errdesc_fallback;
}