Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1905 serge 1
/*
2
	compat: Some compatibility functions. Basic standard C stuff, that may barely be above/around C89.
3
 
4
	The mpg123 code is determined to keep it's legacy. A legacy of old, old UNIX.
5
 
6
	copyright 2007-8 by the mpg123 project - free software under the terms of the LGPL 2.1
7
	see COPYING and AUTHORS files in distribution or http://mpg123.org
8
	initially written by Thomas Orgis
9
*/
10
 
11
#include "config.h"
12
#include "compat.h"
13
 
14
/* A safe realloc also for very old systems where realloc(NULL, size) returns NULL. */
15
void *safe_realloc(void *ptr, size_t size)
16
{
17
	if(ptr == NULL) return malloc(size);
18
	else return realloc(ptr, size);
19
}
20
 
21
#ifndef HAVE_STRERROR
22
const char *strerror(int errnum)
23
{
24
	extern int sys_nerr;
25
	extern char *sys_errlist[];
26
 
27
	return (errnum < sys_nerr) ?  sys_errlist[errnum]  :  "";
28
}
29
#endif
30
 
31
#ifndef HAVE_STRDUP
32
char *strdup(const char *src)
33
{
34
	char *dest;
35
 
36
	if (!(dest = (char *) malloc(strlen(src)+1)))
37
	return NULL;
38
	else
39
	return strcpy(dest, src);
40
}
41
#endif