X-Git-Url: http://git.eversberg.eu/gitweb.cgi?p=lcr.git;a=blobdiff_plain;f=macro.h;h=e4a2f2e079e05f5c206a7c8ae0c563a2a8ec683a;hp=9e4bcd1ccd3eac35b31d80081d6325d5ac93c279;hb=0a71f8f76f975b4c5937cbe476a7edd722c3e0ba;hpb=8994874d7bcb1eff9ee833fb22e4910cc365f456 diff --git a/macro.h b/macro.h index 9e4bcd1..e4a2f2e 100644 --- a/macro.h +++ b/macro.h @@ -22,10 +22,10 @@ static inline void scpy(char *dst, const char *src, unsigned int siz) /* safe strcat/strncat */ -#define SCAT(dst, src) scat(dst, src, sizeof(dst)-strlen(dst)-1) +#define SCAT(dst, src) scat(dst, src, sizeof(dst)) static inline void scat(char *dst, const char *src, unsigned int siz) { - strncat(dst, src, siz); + strncat(dst, src, siz-strlen(dst)-1); dst[siz-1] = '\0'; } @@ -63,9 +63,9 @@ static inline void sprint(char *dst, unsigned int siz, const char *fmt, ...) #define UNPRINT snprintf #define VUNPRINT vsnprintf +#define FATAL(fmt, arg...) _fatal(__FILE__, __FUNCTION__, __LINE__, fmt, ##arg) /* fatal error with error message and exit */ -#define FATAL(fmt, arg...) fatal(__FUNCTION__, __LINE__, fmt, ##arg) -static inline void fatal(const char *function, int line, const char *fmt, ...) +static inline void _fatal(const char *file, const char *function, int line, const char *fmt, ...) { va_list args; char buffer[256]; @@ -74,23 +74,23 @@ static inline void fatal(const char *function, int line, const char *fmt, ...) vsnprintf(buffer, sizeof(buffer), fmt, args); va_end(args); buffer[sizeof(buffer)-1] = '\0'; - fprintf(stderr, "FATAL ERROR in function %s, line %d: %s", function, line, buffer); + fprintf(stderr, "FATAL ERROR in function %s/%s, line %d: %s", file, function, line, buffer); fprintf(stderr, "This error is not recoverable, must exit here.\n"); #ifdef DEBUG_FUNC - debug(function, line, "FATAL ERROR", buffer); - debug(function, line, "FATAL ERROR", (char *)"This error is not recoverable, must exit here.\n"); + debug(file, function, line, "FATAL", buffer); + debug(file, function, line, "FATAL", (char *)"This error is not recoverable, must exit here.\n"); #endif exit(EXIT_FAILURE); } /* memory allocation with setting to zero */ -#define MALLOC(size) _malloc(size, __FUNCTION__, __LINE__) -static inline void *_malloc(unsigned int size, const char *function, int line) +#define MALLOC(size) _malloc(size, __FILE__, __FUNCTION__, __LINE__) +static inline void *_malloc(unsigned int size, const char *file, const char *function, int line) { void *addr; addr = malloc(size); if (!addr) - fatal(function, line, "No memory for %d bytes.\n", size); + _fatal(file, function, line, "No memory for %d bytes.\n", size); memset(addr, 0, size); return addr; }