xenocara/xserver/hw/xfree86/dummylib/xalloc.c

113 lines
1.4 KiB
C
Raw Normal View History

/* $XFree86: xc/programs/Xserver/hw/xfree86/dummylib/xalloc.c,v 1.1 2000/02/13 03:06:39 dawes Exp $ */
2006-11-26 11:13:41 -07:00
#ifdef HAVE_XORG_CONFIG_H
#include <xorg-config.h>
#endif
#include <X11/X.h>
#include "os.h"
#include "xf86.h"
#include "xf86Priv.h"
/*
* Utility functions required by libxf86_os.
*/
pointer
2006-11-26 11:13:41 -07:00
Xalloc(unsigned long n)
{
if (!n)
n = 1;
return malloc(n);
}
pointer
2006-11-26 11:13:41 -07:00
Xrealloc(pointer p, unsigned long n)
{
if (!n)
n = 1;
return realloc(p, n);
}
pointer
2006-11-26 11:13:41 -07:00
Xcalloc(unsigned long n)
{
pointer r;
r = Xalloc(n);
memset(r, 0, n);
return r;
}
pointer
2006-11-26 11:13:41 -07:00
XNFalloc(unsigned long n)
{
pointer r;
r = Xalloc(n);
if (!r)
FatalError("XNFalloc failed\n");
return r;
}
pointer
2006-11-26 11:13:41 -07:00
XNFrealloc(pointer p, unsigned long n)
{
pointer r;
r = Xrealloc(p, n);
if (!r)
FatalError("XNFrealloc failed\n");
return r;
}
pointer
2006-11-26 11:13:41 -07:00
XNFcalloc(unsigned long n)
{
pointer r;
r = Xcalloc(n);
if (!r)
FatalError("XNFcalloc failed\n");
return r;
}
void
2006-11-26 11:13:41 -07:00
Xfree(pointer p)
{
free(p);
}
char *
2006-11-26 11:13:41 -07:00
Xstrdup(const char *s)
{
char *sd;
if (s == NULL)
return NULL;
sd = (char *)Xalloc(strlen(s) + 1);
if (sd != NULL)
strcpy(sd, s);
return sd;
}
char *
XNFstrdup(const char *s)
{
char *sd;
size_t len;
if (s == NULL)
return NULL;
len = strlen(s) + 1;
sd = (char *)XNFalloc(len);
strlcpy(sd, s, len);
return sd;
}