Sync usage with man page.
[netbsd-mini2440.git] / share / examples / refuse / virtdir / defs.h
blob6edc9d01299629209c3746a6143855820bd9168e
1 /* $NetBSD: defs.h,v 1.1 2007/03/31 21:05:57 agc Exp $ */
3 /*
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
8 * are met:
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
16 * permission.
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.
30 #ifndef DEFS_H_
31 #define DEFS_H_
33 #include <sys/types.h>
34 #include <sys/param.h>
36 #ifdef HAVE_STDINT_H
37 #include <stdint.h>
38 #endif
40 #include <stdio.h>
41 #include <stdlib.h>
42 #include <string.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))); \
48 action; \
49 } \
50 } while( /* CONSTCOND */ 0)
52 #define RENEW(type,ptr,size,where,action) do { \
53 type *_newptr; \
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))); \
57 action; \
58 } else { \
59 ptr = _newptr; \
60 } \
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; \
69 if (size == 0) { \
70 _newsize = init; \
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); \
75 } \
76 size = _newsize; \
77 } while( /* CONSTCOND */ 0)
79 /* (void) memset(&v[size], 0x0, sizeof(type) * incr); \*/
81 #define DEFINE_ARRAY(name, type) \
82 typedef struct name { \
83 uint32_t c; \
84 uint32_t size; \
85 type *v; \
86 } name
88 #endif /* !DEFS_H_ */