1 | #include <machine/rtems-bsd-user-space.h> |
---|
2 | #ifdef __rtems__ |
---|
3 | #include <machine/rtems-bsd-program.h> |
---|
4 | #include "rtems-bsd-racoon-namespace.h" |
---|
5 | #endif /* __rtems__ */ |
---|
6 | |
---|
7 | /* $NetBSD: vmbuf.c,v 1.4 2006/09/09 16:22:10 manu Exp $ */ |
---|
8 | |
---|
9 | /* $KAME: vmbuf.c,v 1.11 2001/11/26 16:54:29 sakane Exp $ */ |
---|
10 | |
---|
11 | /* |
---|
12 | * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. |
---|
13 | * All rights reserved. |
---|
14 | * |
---|
15 | * Redistribution and use in source and binary forms, with or without |
---|
16 | * modification, are permitted provided that the following conditions |
---|
17 | * are met: |
---|
18 | * 1. Redistributions of source code must retain the above copyright |
---|
19 | * notice, this list of conditions and the following disclaimer. |
---|
20 | * 2. Redistributions in binary form must reproduce the above copyright |
---|
21 | * notice, this list of conditions and the following disclaimer in the |
---|
22 | * documentation and/or other materials provided with the distribution. |
---|
23 | * 3. Neither the name of the project nor the names of its contributors |
---|
24 | * may be used to endorse or promote products derived from this software |
---|
25 | * without specific prior written permission. |
---|
26 | * |
---|
27 | * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND |
---|
28 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
29 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
30 | * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE |
---|
31 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
---|
32 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
---|
33 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
---|
34 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
---|
35 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
---|
36 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
---|
37 | * SUCH DAMAGE. |
---|
38 | */ |
---|
39 | |
---|
40 | #include "config.h" |
---|
41 | |
---|
42 | #define NONEED_DRM |
---|
43 | |
---|
44 | #include <sys/types.h> |
---|
45 | #include <sys/param.h> |
---|
46 | |
---|
47 | #include <stdlib.h> |
---|
48 | #include <stdio.h> |
---|
49 | #include <string.h> |
---|
50 | |
---|
51 | #include "var.h" |
---|
52 | #include "misc.h" |
---|
53 | #include "vmbuf.h" |
---|
54 | #include "debug.h" |
---|
55 | #include "plog.h" |
---|
56 | #include "gcmalloc.h" |
---|
57 | |
---|
58 | vchar_t * |
---|
59 | vmalloc(size) |
---|
60 | size_t size; |
---|
61 | { |
---|
62 | vchar_t *var; |
---|
63 | |
---|
64 | if ((var = (vchar_t *)racoon_malloc(sizeof(*var))) == NULL) |
---|
65 | return NULL; |
---|
66 | |
---|
67 | var->l = size; |
---|
68 | if (size == 0) { |
---|
69 | var->v = NULL; |
---|
70 | } else { |
---|
71 | var->v = (caddr_t)racoon_calloc(1, size); |
---|
72 | if (var->v == NULL) { |
---|
73 | (void)racoon_free(var); |
---|
74 | return NULL; |
---|
75 | } |
---|
76 | } |
---|
77 | |
---|
78 | return var; |
---|
79 | } |
---|
80 | |
---|
81 | vchar_t * |
---|
82 | vrealloc(ptr, size) |
---|
83 | vchar_t *ptr; |
---|
84 | size_t size; |
---|
85 | { |
---|
86 | caddr_t v; |
---|
87 | |
---|
88 | if (ptr != NULL) { |
---|
89 | if (ptr->l == 0) { |
---|
90 | (void)vfree(ptr); |
---|
91 | return vmalloc(size); /* zero-fill it? */ |
---|
92 | } |
---|
93 | |
---|
94 | if ((v = (caddr_t)racoon_realloc(ptr->v, size)) == NULL) { |
---|
95 | (void)vfree(ptr); |
---|
96 | return NULL; |
---|
97 | } |
---|
98 | |
---|
99 | if ( size > ptr->l) |
---|
100 | memset(v + ptr->l, 0, size - ptr->l); |
---|
101 | ptr->v = v; |
---|
102 | ptr->l = size; |
---|
103 | } else { |
---|
104 | if ((ptr = vmalloc(size)) == NULL) |
---|
105 | return NULL; |
---|
106 | } |
---|
107 | |
---|
108 | return ptr; |
---|
109 | } |
---|
110 | |
---|
111 | void |
---|
112 | vfree(var) |
---|
113 | vchar_t *var; |
---|
114 | { |
---|
115 | if (var == NULL) |
---|
116 | return; |
---|
117 | |
---|
118 | if (var->v) |
---|
119 | (void)racoon_free(var->v); |
---|
120 | |
---|
121 | (void)racoon_free(var); |
---|
122 | |
---|
123 | return; |
---|
124 | } |
---|
125 | |
---|
126 | vchar_t * |
---|
127 | vdup(src) |
---|
128 | vchar_t *src; |
---|
129 | { |
---|
130 | vchar_t *new; |
---|
131 | |
---|
132 | if (src == NULL) { |
---|
133 | plog(LLV_ERROR, LOCATION, NULL, "vdup(NULL) called\n"); |
---|
134 | return NULL; |
---|
135 | } |
---|
136 | |
---|
137 | if ((new = vmalloc(src->l)) == NULL) |
---|
138 | return NULL; |
---|
139 | |
---|
140 | memcpy(new->v, src->v, src->l); |
---|
141 | |
---|
142 | return new; |
---|
143 | } |
---|
144 | #ifdef __rtems__ |
---|
145 | #include "rtems-bsd-racoon-vmbuf-data.h" |
---|
146 | #endif /* __rtems__ */ |
---|