2 Copyright 1989, 1998 The Open Group
4 Permission to use, copy, modify, distribute, and sell this software and its
5 documentation for any purpose is hereby granted without fee, provided that
6 the above copyright notice appear in all copies and that both that
7 copyright notice and this permission notice appear in supporting
10 The above copyright notice and this permission notice shall be included in
11 all copies or substantial portions of the Software.
13 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
17 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 Except as contained in this notice, the name of The Open Group shall not be
21 used in advertising or otherwise to promote the sale, use or other dealings
22 in this Software without prior written authorization from The Open Group.
24 * Author: Keith Packard, MIT X Consortium
33 #include <X11/Xdmcp.h>
38 * This variant of malloc does not return NULL if zero size is passed into.
43 return malloc(size ? size : 1);
47 * This variant of realloc does not return NULL if zero size is passed into
50 xrealloc(void *ptr, size_t size)
52 return realloc(ptr, size ? size : 1);
56 XdmcpAllocARRAY8 (ARRAY8Ptr array, int length)
60 /* length defined in ARRAY8 struct is a CARD16 (not CARD8 like the rest) */
61 if (length > UINT16_MAX)
64 newData = (CARD8Ptr) xmalloc(length * sizeof (CARD8));
67 array->length = (CARD16) length;
68 array->data = newData;
73 XdmcpAllocARRAY16 (ARRAY16Ptr array, int length)
77 /* length defined in ARRAY16 struct is a CARD8 */
78 if (length > UINT8_MAX)
81 newData = (CARD16Ptr) xmalloc(length * sizeof (CARD16));
84 array->length = (CARD8) length;
85 array->data = newData;
90 XdmcpAllocARRAY32 (ARRAY32Ptr array, int length)
94 /* length defined in ARRAY32 struct is a CARD8 */
95 if (length > UINT8_MAX)
98 newData = (CARD32Ptr) xmalloc(length * sizeof (CARD32));
101 array->length = (CARD8) length;
102 array->data = newData;
107 XdmcpAllocARRAYofARRAY8 (ARRAYofARRAY8Ptr array, int length)
111 /* length defined in ARRAYofARRAY8 struct is a CARD8 */
112 if (length > UINT8_MAX)
115 newData = (ARRAY8Ptr) xmalloc(length * sizeof (ARRAY8));
118 array->length = (CARD8) length;
119 array->data = newData;
124 XdmcpARRAY8Equal (const ARRAY8Ptr array1, const ARRAY8Ptr array2)
126 if (array1->length != array2->length)
128 if (memcmp(array1->data, array2->data, array1->length) != 0)
134 XdmcpCopyARRAY8 (const ARRAY8Ptr src, ARRAY8Ptr dst)
136 dst->length = src->length;
137 dst->data = (CARD8 *) xmalloc(dst->length * sizeof (CARD8));
140 memmove (dst->data, src->data, src->length * sizeof (CARD8));
145 XdmcpReallocARRAY8 (ARRAY8Ptr array, int length)
149 /* length defined in ARRAY8 struct is a CARD16 (not CARD8 like the rest) */
150 if (length > UINT16_MAX)
153 newData = (CARD8Ptr) xrealloc(array->data, length * sizeof (CARD8));
156 array->length = (CARD16) length;
157 array->data = newData;
162 XdmcpReallocARRAYofARRAY8 (ARRAYofARRAY8Ptr array, int length)
166 /* length defined in ARRAYofARRAY8 struct is a CARD8 */
167 if (length > UINT8_MAX)
170 newData = (ARRAY8Ptr) xrealloc(array->data, length * sizeof (ARRAY8));
173 array->length = (CARD8) length;
174 array->data = newData;
179 XdmcpReallocARRAY16 (ARRAY16Ptr array, int length)
183 /* length defined in ARRAY16 struct is a CARD8 */
184 if (length > UINT8_MAX)
186 newData = (CARD16Ptr) xrealloc(array->data, length * sizeof (CARD16));
189 array->length = (CARD8) length;
190 array->data = newData;
195 XdmcpReallocARRAY32 (ARRAY32Ptr array, int length)
199 /* length defined in ARRAY32 struct is a CARD8 */
200 if (length > UINT8_MAX)
203 newData = (CARD32Ptr) xrealloc(array->data, length * sizeof (CARD32));
206 array->length = (CARD8) length;
207 array->data = newData;
212 XdmcpDisposeARRAY8 (ARRAY8Ptr array)
220 XdmcpDisposeARRAY16 (ARRAY16Ptr array)
228 XdmcpDisposeARRAY32 (ARRAY32Ptr array)
236 XdmcpDisposeARRAYofARRAY8 (ARRAYofARRAY8Ptr array)
240 if (array->data != NULL) {
241 for (i = 0; i < (int)array->length; i++)
242 XdmcpDisposeARRAY8 (&array->data[i]);