blob: 784c762ace25bf4b7fe333c34d2eaeca7634222e (
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
/* strdup.c 2.9.0 92/07/06 - a coupla convenience routines */
/* - Damian Cugley <pdc@prg.ox.ac.uk> Fri. 1 Mar. 1991
-----------------------------------------------------------------------
This software module copyright (c) 1991 Damian Cugley.
It is provided for free on an "as-is" basis.
See the file COPYING for more information.
-----------------------------------------------------------------------
*/
#include "fatal.h"
#include "strmisc.h"
addr malloc ARGS((sizeof_t));
addr realloc ARGS((addr, sizeof_t));
#ifndef xpg2
void
xfree(a)
addr a;
{
int free ARGS((addr));
if (!free(a))
pfatalf("free(0x%lX)", (long)a);
}
#endif
addr malloc ARGS((sizeof_t));
addr realloc ARGS((addr, sizeof_t));
addr
xmalloc(siz)
sizeof_t siz;
{
register addr t;
if (!(t = malloc(siz)))
pfatalf("malloc(%ld)", (long)siz);
return t;
}
addr
xrealloc(oldptr, siz)
addr oldptr;
sizeof_t siz;
{
register addr t;
if (!(t = realloc(oldptr, siz)))
pfatalf("realloc(*,%ld)", (long)siz);
return t;
}
char *
strdup(s)
const char *s;
{
int siz; char *t;
if (!s) return (char *)0;
siz = strlen(s) + 1;
if (!(t = malloc(siz)))
pfatalf("malloc(%ld)", (long)siz);
bcopy((addr)s, t, siz);
t[siz - 1] = 0;
return t;
}
|