/* ------------------------------ $Id: tools.c,v 1.1 2006/01/27 08:40:46 marquet Exp $ ------------------------------------------------------------ Misc. tools Philippe Marquet, Jan 2006 */ #include #include #include #include "tools.h" /*------------------------------ explain why exiting ------------------------------------------------------------*/ int fatal(int assert, const char *fname, const char *fmt, ...) { if (! assert) { va_list ap; va_start(ap, fmt); fprintf(stderr, "[Error] %s: ", fname); vfprintf(stderr, fmt, ap); fputc ('\n', stderr); exit(EXIT_FAILURE); } /* make gcc -W happy */ return EXIT_FAILURE; } /*------------------------------ Not yet implemented ------------------------------------------------------------*/ int nyi(const char *fname) { fprintf(stderr, "[Warning] function %s() not yet implemented\n", fname); return RETURN_FAILURE; } /*------------------------------ strdup() is not ANSI. ------------------------------------------------------------*/ #ifdef STRDUP_MISSING #include char * strdup(const char *s) { size_t siz; char *copy; siz = strlen(s) + 1; if ((copy = malloc(siz)) == NULL) return(NULL); (void)memcpy(copy, s, siz); return(copy); } #endif /* STRDUP_MISSING */