2004-06-25 16:49:53 +00:00
|
|
|
/* strl(cat|cpy) implementation for systems that do not have it in libc */
|
|
|
|
/* strl.c - strlcpy/strlcat implementation
|
|
|
|
* Time-stamp: <2004-03-14 njk>
|
|
|
|
* (C) 2003-2004 Nicholas J. Kain <njk@aerifal.cx>
|
|
|
|
*/
|
|
|
|
|
2005-11-14 00:30:37 +00:00
|
|
|
#include "config.h"
|
2004-06-25 16:49:53 +00:00
|
|
|
|
|
|
|
#ifndef HAVE_STRLCPY
|
2005-04-06 11:57:10 +00:00
|
|
|
unsigned int strlcpy (char *dest, const char *src, unsigned int size)
|
2004-06-25 16:49:53 +00:00
|
|
|
{
|
2006-03-08 10:24:07 +00:00
|
|
|
register unsigned int i = 0;
|
2004-06-25 16:49:53 +00:00
|
|
|
|
2005-10-25 17:13:20 +00:00
|
|
|
if (size > 0) {
|
|
|
|
size--;
|
2004-06-25 16:49:53 +00:00
|
|
|
for (i=0; size > 0 && src[i] != '\0'; ++i, size--)
|
|
|
|
dest[i] = src[i];
|
|
|
|
|
|
|
|
dest[i] = '\0';
|
2005-10-25 17:13:20 +00:00
|
|
|
}
|
|
|
|
while (src[i++]);
|
2004-06-25 16:49:53 +00:00
|
|
|
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef HAVE_STRLCAT
|
2005-04-06 11:57:10 +00:00
|
|
|
unsigned int strlcat (char *dest, const char *src, unsigned int size)
|
2004-06-25 16:49:53 +00:00
|
|
|
{
|
2005-04-06 11:57:10 +00:00
|
|
|
register char *d = dest;
|
2004-06-25 16:49:53 +00:00
|
|
|
|
|
|
|
for (; size > 0 && *d != '\0'; size--, d++);
|
2005-10-25 17:13:20 +00:00
|
|
|
return (d - dest) + strlcpy(d, src, size);
|
2004-06-25 16:49:53 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|