#ifndef UTILITY_H
#define UTILITY_H

/** MM: temporary pointer used in memory-manipulating macros */ 
extern void *valid(void *ptr, int size);
extern char errorbuffer[512]; /** MM: pridane kvoli hlaske pre vynimku */

/** MM: macros ALLOC and REALLOC changed by Martin Miklanek */
#define NIL(type)		((type *) 0)
#define ALLOC(type, num)	\
    ( (type *) valid( malloc( sizeof(type)*(num) ), (sizeof(type)*(num) ) ) )
#define REALLOC(type, obj, num)	\
    ( (type *) valid(realloc((void *) obj, sizeof(type) * (num)), (sizeof(type)*(num) ) ) )
#define FREE(obj)		\
    if ((obj)) { (void) free( (void *) (obj)); (obj) = NULL; }

extern long  util_cpu_time(void);
extern char *util_print_time(long t);
extern char *util_strsav(const char *ptr);

#ifndef NIL_FN
#define NIL_FN(type) ((type (*)()) 0)
#endif /* NIL_FN */

#ifndef MAX
#define MAX(a,b)	((a) > (b) ? (a) : (b))
#endif /* MAX */
#ifndef MIN
#define MIN(a,b)	((a) < (b) ? (a) : (b))
#endif /* MIN */
#ifndef ABS
#define ABS(a)		((a) > 0 ? (a) : -(a))
#endif /* ABS */


#ifdef lint
#undef ALLOC			/* allow for lint -h flag */
#undef REALLOC
#define ALLOC(type, num)	(((type *) 0) + (num))
#define REALLOC(type, obj, num)	((obj) + (num))
#endif /* lint */

#endif

