File indexing completed on 2025-01-18 10:02:04
0001 #ifndef MAD_MAC_H
0002 #define MAD_MAC_H
0003
0004 #include <limits.h>
0005 #include <string.h>
0006
0007 static inline size_t
0008 mad_strlen(const char *file, int line, const char *src)
0009 {
0010 (void)file, (void)line;
0011
0012 assert(src);
0013 return strlen(src);
0014 }
0015
0016 static inline char*
0017 mad_strncpy(const char *file, int line, char *dst, const char *src, size_t siz)
0018 {
0019 (void)file, (void)line;
0020
0021 assert(dst && src && siz < INT_MAX);
0022 *dst = 0;
0023 if (siz > 0) strncat(dst, src, siz-1);
0024 return dst;
0025 }
0026
0027 static inline char*
0028 mad_strncat(const char *file, int line, char *dst, const char *src, size_t siz)
0029 {
0030 (void)file, (void)line;
0031
0032 assert(dst && src && siz < INT_MAX);
0033 return strncat(dst, src, siz);
0034 }
0035
0036 static inline char*
0037 mad_strfcpy(const char *file, int line, char *dst, const char *src, size_t siz)
0038 {
0039 (void)file, (void)line;
0040
0041 assert(dst && src && siz < INT_MAX);
0042 *dst = 0;
0043 if (siz > 0) {
0044 strncat(dst, src, siz-1);
0045 size_t len = strlen(dst);
0046 memset(dst+len, ' ', siz-len);
0047 }
0048 return dst;
0049 }
0050
0051 #undef strlen
0052 #define strlen(src) mad_strlen (__FILE__,__LINE__,src)
0053
0054 #undef strncpy
0055 #define strncpy(dst,src,siz) mad_strncpy(__FILE__,__LINE__,dst,src,siz)
0056
0057 #undef strncat
0058 #define strncat(dst,src,siz) mad_strncat(__FILE__,__LINE__,dst,src,siz)
0059
0060 #undef strfcpy
0061 #define strfcpy(dst,src,siz) mad_strfcpy(__FILE__,__LINE__,dst,src,siz)
0062
0063 #endif