cudd  3.0.0
The University of Colorado Decision Diagram Package
util.h
Go to the documentation of this file.
1 
64 #ifndef UTIL_H_
65 #define UTIL_H_
66 
67 #include "config.h"
68 
69 #if HAVE_ASSERT_H == 1
70 #include <assert.h>
71 #else
72 #error assert.h is needed to build this package
73 #endif
74 
75 #if HAVE_UNISTD_H == 1
76 #include <unistd.h>
77 #endif
78 
79 #include <stdio.h>
80 #include <ctype.h>
81 
82 #if HAVE_STDLIB_H
83 #include <stdlib.h>
84 #else
85 #error stdlib.h is needed to build this package
86 #endif
87 
88 #if HAVE_STRING_H == 1
89 #include <string.h>
90 #else
91 #error string.h is needed to build this package
92 #endif
93 
94 #if HAVE_INTTYPES_H == 1
95 #include <inttypes.h>
96 #else
97 #error inttypes.h is needed to build this package
98 #endif
99 
104 #if defined(_WIN32) && !defined(__USE_MINGW_ANSI_STDIO)
105 #ifndef PRIuPTR
106 #define PRIuPTR "Iu"
107 #endif
108 #ifndef PRIxPTR
109 #define PRIxPTR "Ix"
110 #endif
111 #ifndef PRIiPTR
112 #define PRIiPTR "Id"
113 #endif
114 #define PRIszt "Iu"
115 #else
116 #define PRIszt "zu"
117 #endif
118 
123 #if defined(__GNUC__)
124 #if __GNUC__ > 2 || __GNUC_MINOR__ >= 7
125 #define UTIL_UNUSED __attribute__ ((unused))
126 #else
127 #define UTIL_UNUSED
128 #endif
129 #else
130 #define UTIL_UNUSED
131 #endif
132 
136 #define NIL(type) ((type *) 0)
137 
138 /* #define USE_MM */ /* choose default memory allocator */
139 
158 #if defined(USE_MM)
159 /* Assumes the memory manager is default one. */
160 #define ALLOC(type, num) \
161  ((type *) malloc(sizeof(type) * (num)))
162 #define REALLOC(type, obj, num) \
163  ((type *) realloc(obj, sizeof(type) * (num)))
164 #else
165 /* Use replacements that call MMoutOfMemory if allocation fails. */
166 #define ALLOC(type, num) \
167  ((type *) MMalloc(sizeof(type) * (size_t) (num)))
168 #define REALLOC(type, obj, num) \
169  ((type *) MMrealloc((obj), sizeof(type) * (size_t) (num)))
170 #endif
171 /* In any case, set to zero the pointer to freed memory. */
172 #define FREE(obj) (free(obj), (obj) = 0)
173 
177 #define fail(why) {\
178  (void) fprintf(stderr, "Fatal error: file %s, line %d\n%s\n",\
179  __FILE__, __LINE__, why);\
180  (void) fflush(stdout);\
181  abort();\
182 }
183 
184 /* These arguably do NOT belong in util.h */
188 #define ABS(a) ((a) < 0 ? -(a) : (a))
189 
192 #define MAX(a,b) ((a) > (b) ? (a) : (b))
193 
196 #define MIN(a,b) ((a) < (b) ? (a) : (b))
197 
201 typedef int (*QSFP)(void const *, void const *);
202 
203 #ifdef __cplusplus
204 extern "C" {
205 #endif
206 
207 #ifndef USE_MM
208 extern void *MMalloc(size_t);
209 extern void *MMrealloc(void *, size_t);
210 #endif
211 extern void MMout_of_memory(size_t);
212 extern void (*MMoutOfMemory) (size_t);
213 
214 extern long util_cpu_time(void);
215 extern long util_cpu_ctime(void);
216 extern char *util_path_search(char const *);
217 extern char *util_file_search(char const *, char *, char const *);
218 extern void util_print_cpu_stats(FILE *);
219 extern char *util_print_time(unsigned long);
220 extern char *util_strsav(char const *);
221 extern char *util_tilde_expand(char const *);
222 extern size_t getSoftDataLimit(void);
223 extern void util_qsort (void *vbase, int n, int size, QSFP compar);
224 extern int util_pipefork(char * const * argv, FILE ** toCommand,
225  FILE ** fromCommand, int * pid);
226 #ifdef __cplusplus
227 }
228 #endif
229 
230 #endif /* UTIL_H_ */
void(* MMoutOfMemory)(size_t)
Global out-of-memory handler.
Definition: safe_mem.c:79
void * MMrealloc(void *, size_t)
realloc replacement.
Definition: safe_mem.c:119
void * MMalloc(size_t)
malloc replacement.
Definition: safe_mem.c:103
void util_qsort(void *vbase, int n, int size, QSFP compar)
Implements the quicksort algorithm.
Definition: ucbqsort.c:123
int util_pipefork(char *const *argv, FILE **toCommand, FILE **fromCommand, int *pid)
Forks a command and sets up pipes to and from.
Definition: pipefork.c:98
int(* QSFP)(void const *, void const *)
Type of comparison functions for util_qsort.
Definition: util.h:201
char * util_file_search(char const *, char *, char const *)
Searches for a file given a set of paths.
Definition: pathsearch.c:91
void MMout_of_memory(size_t)
Out of memory for lazy people: flush and exit.
Definition: safe_mem.c:90
long util_cpu_time(void)
returns a long which represents the elapsed processor time in milliseconds since some constant refere...
Definition: cpu_time.c:82
long util_cpu_ctime(void)
returns a long which represents the elapsed processor time in milliseconds since some constant refere...
Definition: cpu_time.c:118
size_t getSoftDataLimit(void)
Gets the soft datasize limit.
Definition: datalimit.c:89
void util_print_cpu_stats(FILE *)
Prints CPU statistics.
Definition: cpu_stats.c:98
char * util_tilde_expand(char const *)
Expands tilde in a file name.
Definition: texpand.c:75
char * util_strsav(char const *)
Returns a copy of a string.
Definition: strsav.c:71
char * util_print_time(unsigned long)
Massages a long that represents a time interval in milliseconds into a string suitable for output...
Definition: prtime.c:74
char * util_path_search(char const *)
Looks for a program in the directories specified by PATH.
Definition: pathsearch.c:77