* call.c (z_candidate::template_decl): Rename from template.
[official-gcc.git] / libbanshee / engine / util.h
blobdea62fe2d4448ab84d02a46aea0d9944750ece5b
1 /*
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
7 * are met:
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
27 * SUCH DAMAGE.
31 #ifndef UTIL_H
32 #define UTIL_H
34 #include <assert.h>
35 #include <stdarg.h>
36 #include <stdlib.h>
37 #include <regions.h>
38 #include <ansidecl.h>
39 #include "compiler.h"
40 #include "linkage.h"
41 #include "bool.h"
44 EXTERN_C_BEGIN
46 #ifdef HAVE_VARIADIC_MACROS
47 #define fail(args...) __fail(__FILE__, __LINE__, __FUNCTION__, args)
48 #else
49 void fail(const char *fmt, ...);
50 #endif
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
57 side-effects */
58 #ifdef NDEBUG
59 # define insist(action) (action)
60 #else
61 # define insist assert
62 #endif
64 #ifdef NDEBUG
65 # define insistnot(action) (action)
66 #else
67 # define insistnot(action) assert(!(action))
68 #endif
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
87 internal buffer. */
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; }
105 EXTERN_C_END
107 #endif