Expand PMF_FN_* macros.
[netbsd-mini2440.git] / external / bsd / iscsi / dist / include / defs.h
blob1440bdab94ec95124106fa7298d504f37ef07b26
1 /* $NetBSD: defs.h,v 1.4 2006/04/17 16:44:42 thorpej 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 "config.h"
35 #include <sys/types.h>
36 #include <sys/param.h>
38 #ifdef HAVE_STDINT_H
39 #include <stdint.h>
40 #endif
42 #include <stdio.h>
43 #include <stdlib.h>
44 #include <string.h>
46 #define NEWARRAY(type,ptr,size,where,action) do { \
47 if ((ptr = (type *) calloc(sizeof(type), (unsigned)(size))) == NULL) { \
48 (void) fprintf(stderr, "%s: can't allocate %lu bytes\n", \
49 where, (unsigned long)(size * sizeof(type))); \
50 action; \
51 } \
52 } while( /* CONSTCOND */ 0)
54 #define RENEW(type,ptr,size,where,action) do { \
55 type *_newptr; \
56 if ((_newptr = (type *) realloc(ptr, sizeof(type) * (size))) == NULL) { \
57 (void) fprintf(stderr, "%s: can't realloc %lu bytes\n", \
58 where, (unsigned long)(size * sizeof(type))); \
59 action; \
60 } else { \
61 ptr = _newptr; \
62 } \
63 } while( /* CONSTCOND */ 0)
65 #define NEW(type, ptr, where, action) NEWARRAY(type, ptr, 1, where, action)
67 #define FREE(ptr) (void) free(ptr)
69 #define ALLOC(type, v, size, c, init, incr, where, action) do { \
70 uint32_t _newsize = size; \
71 if (size == 0) { \
72 _newsize = init; \
73 NEWARRAY(type, v, _newsize, where ": new", action); \
74 } else if (c == size) { \
75 _newsize = size + incr; \
76 RENEW(type, v, _newsize, where ": renew", action); \
77 } \
78 size = _newsize; \
79 } while( /* CONSTCOND */ 0)
81 #define USE_ARG(x) /*LINTED*/(void)&(x)
83 #define DEFINE_ARRAY(name, type) \
84 typedef struct name { \
85 uint32_t c; \
86 uint32_t size; \
87 type *v; \
88 } name
90 #ifndef ABS
91 #define ABS(a) (((a) < 0) ? -(a) : (a))
92 #endif
94 #endif /* !DEFS_H_ */