36#if defined(SIR_IMPL_STRLCAT) && !defined(SIR_IMPL_STRLCAT_DEF)
48_sir_strlcat(
char *dst,
const char *src,
size_t dsize)
50 const char *odst = dst;
51 const char *osrc = src;
60 while (n-- != 0 && *dst !=
'\0')
67 return dlen + strlen(src);
69 while (*src !=
'\0') {
79 return dlen + (src - osrc);
82# define strlcat _sir_strlcat
83# define SIR_IMPL_STRLCAT_DEF 1
92#if defined(SIR_IMPL_STRLCPY) && !defined(SIR_IMPL_STRLCPY_DEF)
102_sir_strlcpy(
char *dst,
const char *src,
size_t dsize)
104 const char *osrc = src;
105 size_t nleft = dsize;
112 while (--nleft != 0) {
113 if ((*dst++ = *src++) ==
'\0')
129 return src - osrc - 1;
132# define strlcpy _sir_strlcpy
133# define SIR_IMPL_STRLCPY_DEF 1
142#if (defined(SIR_IMPL_STRNLEN) || defined(SIR_IMPL_STRNDUP)) && \
143 !defined(SIR_IMPL_STRNLEN_DEF)
147_sir_strnlen(
const char *str,
size_t maxlen)
151 for (cp = str; maxlen != 0 && *cp !=
'\0'; cp++, maxlen--);
153 return (
size_t)(cp - str);
156# define strnlen _sir_strnlen
157# define SIR_IMPL_STRNLEN_DEF 1
166#if defined(SIR_IMPL_STRNDUP) && !defined(SIR_IMPL_STRNDUP_DEF)
170_sir_strndup(
const char *str,
size_t maxlen)
175 len = _sir_strnlen(str, maxlen);
177 copy = (
char*)malloc(len + 1);
179 (void)memcpy(copy, str, len);
186# define strndup _sir_strndup
187# define SIR_IMPL_STRNDUP_DEF 1
230#if defined(SIR_IMPL_STRCASESTR) && !defined(SIR_IMPL_STRCASESTR_DEF)
234_sir_strcasestr(
const char *s,
const char *find)
239 if ((c = *find++) != 0) {
240 c = (char)tolower((
unsigned char)c);
244 if ((sc = *s++) == 0)
246 }
while ((
char)tolower((
unsigned char)sc) != c);
247 }
while (strncasecmp(s, find, len) != 0);
254# define strcasestr _sir_strcasestr
255# define SIR_IMPL_STRCASESTR_DEF 1