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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
/*-
* See the file LICENSE for redistribution information.
*
* Copyright (c) 1997, 1998
* Sleepycat Software. All rights reserved.
*/
#include "config.h"
#ifndef lint
static const char sccsid[] = "@(#)os_alloc.c 10.6 (Sleepycat) 5/2/98";
#endif /* not lint */
#ifndef NO_SYSTEM_INCLUDES
#include <sys/types.h>
#include <string.h>
#endif
#include "db_int.h"
/*
* __db_strdup --
* The strdup(3) function for DB.
*
* PUBLIC: char *__db_strdup __P((const char *));
*/
char *
__db_strdup(str)
const char *str;
{
size_t len;
char *copy;
len = strlen(str) + 1;
if ((copy = __db_malloc(len)) == NULL)
return (NULL);
memcpy(copy, str, len);
return (copy);
}
/*
* XXX
* Correct for systems that return NULL when you allocate 0 bytes of memory.
* There are several places in DB where we allocate the number of bytes held
* by the key/data item, and it can be 0. Correct here so that malloc never
* returns a NULL for that reason (which behavior is permitted by ANSI). We
* could make these calls macros on non-Alpha architectures (that's where we
* saw the problem), but it's probably not worth the autoconf complexity.
*
* Out of memory.
* We wish to hold the whole sky,
* But we never will.
*/
/*
* __db_calloc --
* The calloc(3) function for DB.
*
* PUBLIC: void *__db_calloc __P((size_t, size_t));
*/
void *
__db_calloc(num, size)
size_t num, size;
{
void *p;
size *= num;
if ((p = __db_jump.j_malloc(size == 0 ? 1 : size)) != NULL)
memset(p, 0, size);
return (p);
}
/*
* __db_malloc --
* The malloc(3) function for DB.
*
* PUBLIC: void *__db_malloc __P((size_t));
*/
void *
__db_malloc(size)
size_t size;
{
#ifdef DIAGNOSTIC
void *p;
p = __db_jump.j_malloc(size == 0 ? 1 : size);
memset(p, 0xff, size == 0 ? 1 : size);
return (p);
#else
return (__db_jump.j_malloc(size == 0 ? 1 : size));
#endif
}
/*
* __db_realloc --
* The realloc(3) function for DB.
*
* PUBLIC: void *__db_realloc __P((void *, size_t));
*/
void *
__db_realloc(ptr, size)
void *ptr;
size_t size;
{
return (__db_jump.j_realloc(ptr, size == 0 ? 1 : size));
}
|