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
45 #ifdef HAVE_VARIADIC_MACROS
46 #define fail(args...) __fail(__FILE__, __LINE__, __FUNCTION__, args)
48 void fail(const char *fmt
, ...);
51 void __fail(const char *file
, unsigned int line
,
52 const char *func
, const char *fmt
, ...) __attribute__ ((__noreturn__
));
55 /* insist(action) is like assert(action), but action may have
58 # define insist(action) (action)
60 # define insist assert
64 # define insistnot(action) (action)
66 # define insistnot(action) assert(!(action))
69 void failure(const char *message
);
71 /* Concatenate 2 strings, allocating space in r for the result */
72 char *rstrcat(region
, const char *, const char *);
74 /* Concatenate n strings, allocating space in r for the result. The
75 last argument should be a null pointer. */
76 char *rstrscat(region
, ...);
78 /* Convert an integer to a string, storing the result in r */
79 const char *inttostr(region r
, int);
81 /* sprintf a string, allocating space in r for the result */
82 char *rsprintf(region r
, const char *fmt
, ...);
83 char *rvsprintf(region r
, const char *fmt
, va_list args
);
85 /* Convert a pointer to an ascii string with leading 0x. Re-uses
87 char *ptr_to_ascii(void *ptr
);
89 /* Convert a pointer to an integer */
90 long ptr_hash(void *ptr
);
92 /* Return TRUE iff ptr1 == ptr2 */
93 bool ptr_eq(void *ptr1
, void *ptr2
);
95 /* Return TRUE iff s1 == s2 */
96 bool str_eq(const char *s1
, const char *s2
);
98 /* A total ordering on pointers. Returns 0 if ptr1 = ptr2, a value <0
99 if ptr1 < ptr2, or a value >0 if ptr1 > ptr2. */
100 int ptr_cmp(const void *ptr1
, const void *ptr2
);
102 extern inline int min(int, int);
103 extern inline int max(int, int);
104 extern inline int min(int a
, int b
) { if (a
< b
) return a
; else return b
; }
105 extern inline int max(int a
, int b
) { if (a
< b
) return b
; else return a
; }