cudd  3.0.0
The University of Colorado Decision Diagram Package
Macros | Typedefs | Functions | Variables
util.h File Reference

Low-level utilities. More...

#include "config.h"
#include <assert.h>
#include <unistd.h>
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
Include dependency graph for util.h:

Go to the source code of this file.

Macros

#define PRIszt   "zu"
 Format string for a size_t value.
 
#define UTIL_UNUSED
 Macro to tell gcc that a variable is intentionally unused.
 
#define NIL(type)   ((type *) 0)
 Type-decorated NULL (for documentation).
 
#define ALLOC(type, num)   ((type *) MMalloc(sizeof(type) * (size_t) (num)))
 Wrapper for either malloc or MMalloc. More...
 
#define REALLOC(type, obj, num)   ((type *) MMrealloc((obj), sizeof(type) * (size_t) (num)))
 Wrapper for either realloc or MMrealloc. More...
 
#define FREE(obj)   (free(obj), (obj) = 0)
 Wrapper for free. More...
 
#define fail(why)
 Prints message and terminates execution. More...
 
#define ABS(a)   ((a) < 0 ? -(a) : (a))
 Computes the absolute value of its argument.
 
#define MAX(a, b)   ((a) > (b) ? (a) : (b))
 Computes the maximum of its two arguments.
 
#define MIN(a, b)   ((a) < (b) ? (a) : (b))
 Computes the minimum of its two arguments.
 

Typedefs

typedef int(* QSFP) (void const *, void const *)
 Type of comparison functions for util_qsort.
 

Functions

void * MMalloc (size_t)
 malloc replacement.
 
void * MMrealloc (void *, size_t)
 realloc replacement.
 
void MMout_of_memory (size_t)
 Out of memory for lazy people: flush and exit.
 
long util_cpu_time (void)
 returns a long which represents the elapsed processor time in milliseconds since some constant reference.
 
long util_cpu_ctime (void)
 returns a long which represents the elapsed processor time in milliseconds since some constant reference. It includes waited-for terminated children.
 
char * util_path_search (char const *)
 Looks for a program in the directories specified by PATH.
 
char * util_file_search (char const *, char *, char const *)
 Searches for a file given a set of paths.
 
void util_print_cpu_stats (FILE *)
 Prints CPU statistics. More...
 
char * util_print_time (unsigned long)
 Massages a long that represents a time interval in milliseconds into a string suitable for output. More...
 
char * util_strsav (char const *)
 Returns a copy of a string.
 
char * util_tilde_expand (char const *)
 Expands tilde in a file name.
 
size_t getSoftDataLimit (void)
 Gets the soft datasize limit.
 
void util_qsort (void *vbase, int n, int size, QSFP compar)
 Implements the quicksort algorithm. More...
 
int util_pipefork (char *const *argv, FILE **toCommand, FILE **fromCommand, int *pid)
 Forks a command and sets up pipes to and from. More...
 

Variables

void(* MMoutOfMemory )(size_t)
 Global out-of-memory handler.
 

Detailed Description

Low-level utilities.

Macro Definition Documentation

◆ ALLOC

#define ALLOC (   type,
  num 
)    ((type *) MMalloc(sizeof(type) * (size_t) (num)))

Wrapper for either malloc or MMalloc.

Which function is wrapped depends on whether USE_MM is defined.

◆ fail

#define fail (   why)
Value:
{\
(void) fprintf(stderr, "Fatal error: file %s, line %d\n%s\n",\
__FILE__, __LINE__, why);\
(void) fflush(stdout);\
abort();\
}

Prints message and terminates execution.

◆ FREE

#define FREE (   obj)    (free(obj), (obj) = 0)

Wrapper for free.

Sets its argument to 0 after freeing.

◆ REALLOC

#define REALLOC (   type,
  obj,
  num 
)    ((type *) MMrealloc((obj), sizeof(type) * (size_t) (num)))

Wrapper for either realloc or MMrealloc.

Which function is wrapped depends on whether USE_MM is defined.

Function Documentation

◆ util_pipefork()

int util_pipefork ( char *const *  argv,
FILE **  toCommand,
FILE **  fromCommand,
int *  pid 
)

Forks a command and sets up pipes to and from.

Returns
1 for success, with toCommand and fromCommand pointing to the streams; 0 for failure
Parameters
argvnormal argv argument list
toCommandpointer to the sending stream
fromCommandpointer to the reading stream
pidprocess ID

◆ util_print_cpu_stats()

void util_print_cpu_stats ( FILE *  fp)

Prints CPU statistics.

The amount of detail printed depends on the host operating system.

◆ util_print_time()

char* util_print_time ( unsigned long  t)

Massages a long that represents a time interval in milliseconds into a string suitable for output.

Hack for IBM/PC – avoids using floating point.

◆ util_qsort()

void util_qsort ( void *  vbase,
int  n,
int  size,
QSFP  compar 
)

Implements the quicksort algorithm.

First, set up some global parameters for qst to share. Then, quicksort with qst(), and then a cleanup insertion sort ourselves. Sound simple? It's not...

Parameters
vbasestart address of array
nnumber of items
sizesize of each item
comparcomparison function