1 /* ---------------------------------------------------------------------
2  *
3  * -- Integer Matrix Library (IML)
4  *    (C) Copyright 2004, 2006 All Rights Reserved
5  *
6  * -- IML routines -- Version 1.0.1 -- November, 2006
7  *
8  * Author         : Zhuliang Chen
9  * Contributor(s) : Arne Storjohann
10  * University of Waterloo -- School of Computer Science
11  * Waterloo, Ontario, N2L3G1 Canada
12  *
13  * ---------------------------------------------------------------------
14  *
15  * -- Copyright notice and Licensing terms:
16  *
17  *  Redistribution  and  use in  source and binary forms, with or without
18  *  modification, are  permitted provided  that the following  conditions
19  *  are met:
20  *
21  * 1. Redistributions  of  source  code  must retain the above copyright
22  *    notice, this list of conditions and the following disclaimer.
23  * 2. Redistributions in binary form must reproduce  the above copyright
24  *    notice,  this list of conditions, and the  following disclaimer in
25  *    the documentation and/or other materials provided with the distri-
26  *    bution.
27  * 3. The name of the University,  the IML group,  or the names of its
28  *    contributors  may not be used to endorse or promote products deri-
29  *    ved from this software without specific written permission.
30  *
31  * -- Disclaimer:
32  *
33  * THIS  SOFTWARE  IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
34  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,  INCLUDING,  BUT NOT
35  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
36  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY
37  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,  INDIRECT, INCIDENTAL, SPE-
38  * CIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
39  * TO,  PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
40  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEO-
41  * RY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT  (IN-
42  * CLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
43  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
44  *
45  */
46 
47 
48 
49 /*
50  *  common.h provides the basic library header include and memory management
51  *  functions.
52  *
53  *  It is written based on the examples from Gary V. Vaughan's Autobook.
54  *
55  */
56 
57 #ifndef IML_COMMON_H
58 #define IML_COMMON_H 1
59 
60 #if HAVE_CONFIG_H
61 #  include <config.h>
62 #endif
63 
64 #include <stdio.h>
65 #include <sys/types.h>
66 
67 #if HAVE_MATH_H
68 #  include <math.h>
69 #endif
70 
71 #if STDC_HEADERS || HAVE_STDLIB_H
72 #  include <stdlib.h>
73 #endif
74 
75 #if HAVE_TIME_H
76 #  include <time.h>
77 #endif
78 
79 #if defined __CYGWIN32__ && !defined __CYGWIN__
80 #  define __CYGWIN__ __CYGWIN32__
81 #endif
82 #if defined __CYGWIN__ && !defined WIN32
83 #  define WIN32
84 #endif
85 
86 #ifdef __GNUC__
87 #  ifndef const
88 #    define const       __const
89 #  endif
90 #  ifndef signed
91 #    define signed      __signed
92 #  endif
93 #else
94 #  ifdef __STDC__
95 #    undef  signed
96 #    define signed
97 #  endif
98 #endif
99 
100 #ifndef EXIT_SUCCESS
101 #  define EXIT_SUCCESS  0
102 #  define EXIT_FAILURE  1
103 #endif
104 
105 #if !HAVE_BZERO && HAVE_MEMSET
106 # define bzero(buf, bytes)    ((void) memset (buf, 0, bytes))
107 #endif
108 
109 #define XCALLOC(type, num)                                  \
110         ((type *) xcalloc ((num), sizeof(type)))
111 #define XMALLOC(type, num)                                  \
112         ((type *) xmalloc ((num) * sizeof(type)))
113 #define XREALLOC(type, p, num)                              \
114         ((type *) xrealloc ((p), (num) * sizeof(type)))
115 #define XFREE(stale)                            do {        \
116         if (stale) { free (stale);  stale = 0; }            \
117                                                 } while (0)
118 
119 void *xcalloc  (size_t num, size_t size);
120 void *xmalloc  (size_t num);
121 void *xrealloc (void *p, size_t num);
122 
123 #endif /* !IML_COMMON_H */
124 
125