1 /* $NetBSD: defs.h,v 1.1 2007/03/31 21:05:57 agc Exp $ */
4 * Copyright (c) 1999-2005 Alistair Crooks. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote
15 * products derived from this software without specific prior written
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
19 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
22 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
24 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #include <sys/types.h>
34 #include <sys/param.h>
44 #define NEWARRAY(type,ptr,size,where,action) do { \
45 if ((ptr = (type *) calloc(sizeof(type), (unsigned)(size))) == NULL) { \
46 (void) fprintf(stderr, "%s: can't allocate %lu bytes\n", \
47 where, (unsigned long)(size * sizeof(type))); \
50 } while( /* CONSTCOND */ 0)
52 #define RENEW(type,ptr,size,where,action) do { \
54 if ((_newptr = (type *) realloc(ptr, sizeof(type) * (size))) == NULL) { \
55 (void) fprintf(stderr, "%s: can't realloc %lu bytes\n", \
56 where, (unsigned long)(size * sizeof(type))); \
61 } while( /* CONSTCOND */ 0)
63 #define NEW(type, ptr, where, action) NEWARRAY(type, ptr, 1, where, action)
65 #define FREE(ptr) (void) free(ptr)
67 #define ALLOC(type, v, size, c, init, incr, where, action) do { \
68 uint32_t _newsize = size; \
71 NEWARRAY(type, v, _newsize, where ": new", action); \
72 } else if (c == size) { \
73 _newsize = size + incr; \
74 RENEW(type, v, _newsize, where ": renew", action); \
77 } while( /* CONSTCOND */ 0)
79 /* (void) memset(&v[size], 0x0, sizeof(type) * incr); \*/
81 #define DEFINE_ARRAY(name, type) \
82 typedef struct name { \