2 * Copyright (c) 2000-2001
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the University nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
46 #ifdef HAVE_VARIADIC_MACROS
47 #define fail(args...) __fail(__FILE__, __LINE__, __FUNCTION__, args)
49 void fail(const char *fmt
, ...);
52 void __fail(const char *file
, unsigned int line
,
53 const char *func
, const char *fmt
, ...) __attribute__ ((__noreturn__
));
56 /* insist(action) is like assert(action), but action may have
59 # define insist(action) (action)
61 # define insist assert
65 # define insistnot(action) (action)
67 # define insistnot(action) assert(!(action))
70 void failure(const char *message
);
72 /* Concatenate 2 strings, allocating space in r for the result */
73 char *rstrcat(region
, const char *, const char *);
75 /* Concatenate n strings, allocating space in r for the result. The
76 last argument should be a null pointer. */
77 char *rstrscat(region
, ...);
79 /* Convert an integer to a string, storing the result in r */
80 const char *inttostr(region r
, int);
82 /* sprintf a string, allocating space in r for the result */
83 char *rsprintf(region r
, const char *fmt
, ...);
84 char *rvsprintf(region r
, const char *fmt
, va_list args
);
86 /* Convert a pointer to an ascii string with leading 0x. Re-uses
88 char *ptr_to_ascii(void *ptr
);
90 /* Convert a pointer to an integer */
91 long ptr_hash(void *ptr
);
93 /* Return TRUE iff ptr1 == ptr2 */
94 bool ptr_eq(void *ptr1
, void *ptr2
);
96 /* Return TRUE iff s1 == s2 */
97 bool str_eq(const char *s1
, const char *s2
);
99 /* A total ordering on pointers. Returns 0 if ptr1 = ptr2, a value <0
100 if ptr1 < ptr2, or a value >0 if ptr1 > ptr2. */
101 int ptr_cmp(const void *ptr1
, const void *ptr2
);
103 static inline int min(int a
, int b
) { if (a
< b
) return a
; else return b
; }
104 static inline int max(int a
, int b
) { if (a
< b
) return b
; else return a
; }