Chameleon

Chameleon Commit Details

Date:2015-03-11 15:39:11 (9 years 1 month ago)
Author:ErmaC
Commit:2615
Parents: 2614
Message:Implement strlcat (credits to cparm)
Changes:
M/trunk/i386/libsa/libsa.h
M/trunk/i386/libsa/string.c

File differences

trunk/i386/libsa/libsa.h
102102
103103
104104
105
105106
106107
107108
extern intatoi(const char * str);
extern intptol(const char * str);
extern size_tstrlen(const char * str);
extern size_tstrlcat(char *, const char *, size_t);
extern char*strcat(char * s1, const char * s2);
extern char*strncat(char * s1, const char * s2, size_t n);
extern char*strdup(const char *s1);
trunk/i386/libsa/string.c
243243
244244
245245
246
247
248
249
250
251
252
253
254
255
256
257
258
246259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
247288
248289
249290
}
return sum;
}
/*
* Appends src to string dst of size siz (unlike strncat, siz is the
* full size of dst, not space left). At most siz-1 characters
* will be copied. Always NUL terminates (unless siz <= strlen(dst)).
* Returns strlen(src) + MIN(siz, strlen(initial dst)).
* If retval >= siz, truncation occurred.
*/
size_t strlcat(char *dst, const char *src, size_t siz)
{
char *d = dst;
const char *s = src;
size_t n = siz;
size_t dlen;
/* Find the end of dst and adjust bytes left but don't go past end */
while (n-- != 0 && *d != '\0')
{
d++;
}
dlen = d - dst;
n = siz - dlen;
if (n == 0)
{
return(dlen + strlen(s));
}
while (*s != '\0')
{
if (n != 1)
{
*d++ = *s;
n--;
}
s++;
}
*d = '\0';
return(dlen + (s - src)); /* count does not include NUL */
}
char *strncat(char *s1, const char *s2, size_t n)
{
register char *ret = s1;

Archive Download the corresponding diff file

Revision: 2615