/* safe strcpy/strncpy */
#define SCPY(dst, src) scpy(dst, src, sizeof(dst))
-static 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';
/* safe strcat/strncat */
-#define SCAT(dst, src) scat(dst, src, sizeof(dst))
-static 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';
/* safe sprintf/snprintf */
#define SPRINT(dst, fmt, arg...) sprint(dst, sizeof(dst), fmt, ## arg)
-static 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;
/* 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, char *fmt, ...)
+static inline void fatal(const char *function, int line, const char *fmt, ...)
{
va_list args;
char buffer[256];
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__)
-static 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);