Mercurial > hg > nnchat
diff th_util.h @ 0:728243125263
Import.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 20 Mar 2008 00:15:03 +0000 |
parents | |
children | 323c98360d8b |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/th_util.h Thu Mar 20 00:15:03 2008 +0000 @@ -0,0 +1,76 @@ +/* + * Generic utility-functions, macros and defaults + * Programmed and designed by Matti 'ccr' Hamalainen + * (C) Copyright 2002-2008 Tecnic Software productions (TNSP) + * + * Please read file 'COPYING' for information on license and distribution. + */ +#ifndef _TH_UTIL_H +#define _TH_UTIL_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include "th_types.h" +#include <stdarg.h> +#include <stdlib.h> +#ifndef HAVE_NO_ASSERT +#include <assert.h> +#endif + +#ifdef HAVE_STRING_H +#include <string.h> +#define HAVE_MEMSET 1 +#else +#ifdef HAVE_STRINGS_H +#include <strings.h> +#endif +#endif + +#ifdef HAVE_MEMORY_H +#include <memory.h> +#endif + + +/* Replacement for assert() */ +#ifdef HAVE_NO_ASSERT +# ifdef NDEBUG +# define assert(NEXPR) /* stub */ +# else +# define assert(NEXPR) do { if (!(NEXPR)) { fprintf(stderr, "[%s:%d] assert(" # NEXPR ") failed!\n", __FILE__, __LINE__); abort(); } } while (0) +# endif +#endif + +/* Global variables + */ +extern int th_verbosityLevel; +extern char *th_prog_name, + *th_prog_fullname, + *th_prog_version, + *th_prog_author, + *th_prog_license; + +/* Functions + */ +void th_init(char *progName, char *progFullName, char *progVersion, + char *progAuthor, char *progLicense); +void THERR(const char *, ...); +void THMSG(int, const char *, ...); +void THPRINT(int, const char *, ...); + +void * th_malloc(size_t); +void * th_calloc(size_t, size_t); +void * th_realloc(void *, size_t); +void th_free(void *); + +#ifdef HAVE_MEMSET +#define th_memset memset +#else +void *th_memset(void *, int, size_t); +#endif + +#ifdef __cplusplus +} +#endif +#endif /* _TH_UTIL_H */