X-Git-Url: http://git.eversberg.eu/gitweb.cgi?p=lcr.git;a=blobdiff_plain;f=macro.h;h=29b27942558900dd5ed2f5ad5ed51cfa73d26dc3;hp=9bb1f2961f67d80f43ddb97a974e4124e08381a2;hb=cf1ea15cc320019d7b41eb56aeeb3c1956fbb7a0;hpb=a54078ccf090907f1ebd9ddc3a02cd613ffecf9c diff --git a/macro.h b/macro.h index 9bb1f29..29b2794 100644 --- a/macro.h +++ b/macro.h @@ -11,28 +11,28 @@ \*****************************************************************************/ -/* save strcpy/strncpy */ +/* safe strcpy/strncpy */ #define SCPY(dst, src) scpy(dst, src, sizeof(dst)) -extern __inline__ void scpy(char *dst, char *src, unsigned int siz) +static inline void scpy(char *dst, const char *src, unsigned int siz) { strncpy(dst, src, siz); dst[siz-1] = '\0'; } -/* save strcat/strncat */ +/* safe strcat/strncat */ -#define SCAT(dst, src) scat(dst, src, sizeof(dst)) -extern __inline__ void scat(char *dst, char *src, unsigned int siz) +#define SCAT(dst, src) scat(dst, src, sizeof(dst)-strlen(dst)-1) +static inline void scat(char *dst, const char *src, unsigned int siz) { strncat(dst, src, siz); dst[siz-1] = '\0'; } -/* save concat of a byte */ +/* safe concat of a byte */ #define SCCAT(dst, src) sccat(dst, src, sizeof(dst)) -extern __inline__ void sccat(char *dst, char chr, unsigned int siz) +static inline void sccat(char *dst, char chr, unsigned int siz) { if (strlen(dst) < siz-1) { @@ -41,10 +41,10 @@ extern __inline__ void sccat(char *dst, char chr, unsigned int siz) } } -/* save sprintf/snprintf */ +/* safe sprintf/snprintf */ #define SPRINT(dst, fmt, arg...) sprint(dst, sizeof(dst), fmt, ## arg) -extern __inline__ void sprint(char *dst, unsigned int siz, char *fmt, ...) +static inline void sprint(char *dst, unsigned int siz, const char *fmt, ...) { va_list args; @@ -54,7 +54,7 @@ extern __inline__ void sprint(char *dst, unsigned int siz, char *fmt, ...) va_end(args); } -/* unsave */ +/* unsafe */ #define UCPY strcpy #define UNCPY strncpy #define UCAT strcat @@ -65,7 +65,7 @@ extern __inline__ void sprint(char *dst, unsigned int siz, char *fmt, ...) /* fatal error with error message and exit */ #define FATAL(fmt, arg...) fatal(__FUNCTION__, __LINE__, fmt, ##arg) -extern __inline__ void fatal(const char *function, int line, char *fmt, ...) +static inline void fatal(const char *function, int line, const char *fmt, ...) { va_list args; char buffer[256]; @@ -78,14 +78,14 @@ extern __inline__ void fatal(const char *function, int line, char *fmt, ...) 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", "This error is not recoverable, must exit here.\n"); + debug(function, line, "FATAL ERROR", (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__) -extern __inline__ void *_malloc(unsigned long size, const char *function, int line) +static inline void *_malloc(unsigned int size, const char *function, int line) { void *addr; addr = malloc(size); @@ -97,7 +97,7 @@ extern __inline__ void *_malloc(unsigned long size, const char *function, int li /* memory freeing with clearing memory to prevent using freed memory */ #define FREE(addr, size) _free(addr, size) -extern __inline void _free(void *addr, int size) +static inline void _free(void *addr, int size) { if (size) memset(addr, 0, size);