util/util.h File Reference

Low-level utilities. More...

#include "config.h"
#include <stdio.h>
#include <ctype.h>
Include dependency graph for util.h:

Go to the source code of this file.

Defines

#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.
#define REALLOC(type, obj, num)   ((type *) MMrealloc((obj), sizeof(type) * (size_t) (num)))
 Wrapper for either realloc or MMrealloc.
#define FREE(obj)   (free(obj), (obj) = 0)
 Wrapper for free.
#define fail(why)
 Prints message and terminates execution.
#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.
char * util_print_time (unsigned long)
 Massages a long that represents a time interval in milliseconds into a string suitable for output.
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.
int util_pipefork (char *const *argv, FILE **toCommand, FILE **fromCommand, int *pid)
 Forks a command and sets up pipes to and from.

Variables

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

Detailed Description

Low-level utilities.

Copyright (c) 1994-1998 The Regents of the Univ. of California. All rights reserved.

Permission is hereby granted, without written agreement and without license or royalty fees, to use, copy, modify, and distribute this software and its documentation for any purpose, provided that the above copyright notice and the following two paragraphs appear in all copies of this software.

IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.

Copyright (c) 1999-2015, Regents of the University of Colorado

All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

Neither the name of the University of Colorado nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


Define Documentation

#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.

#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.

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

Wrapper for free.

Sets its argument to 0 after freeing.

#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

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:
argv normal argv argument list
toCommand pointer to the sending stream
fromCommand pointer to the reading stream
pid process ID
void util_print_cpu_stats ( FILE *  fp  ) 

Prints CPU statistics.

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

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.

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:
vbase start address of array
n number of items
size size of each item
compar comparison function
 All Data Structures Files Functions Variables Typedefs Enumerations Defines

Generated on 31 Dec 2015 for cudd by  doxygen 1.6.1