#include "asterisk.h"
#include <ctype.h>
Go to the source code of this file.
Functions | |
size_t | strlcat (char *dst, const char *src, size_t siz) |
size_t | strlcpy (char *dst, const char *src, size_t siz) |
Definition in file main/strcompat.c.
size_t strlcat | ( | char * | dst, | |
const char * | src, | |||
size_t | siz | |||
) |
Definition at line 375 of file main/strcompat.c.
00376 { 00377 register char *d = dst; 00378 register const char *s = src; 00379 register size_t n = siz; 00380 size_t dlen; 00381 00382 /* Find the end of dst and adjust bytes left but don't go past end */ 00383 while (n-- != 0 && *d != '\0') 00384 d++; 00385 dlen = d - dst; 00386 n = siz - dlen; 00387 00388 if (n == 0) 00389 return dlen + strlen(s); 00390 00391 while (*s != '\0') { 00392 if (n != 1) { 00393 *d++ = *s; 00394 n--; 00395 } 00396 s++; 00397 } 00398 *d = '\0'; 00399 00400 return dlen + (s - src); /* count does not include NUL */ 00401 }
size_t strlcpy | ( | char * | dst, | |
const char * | src, | |||
size_t | siz | |||
) |
Definition at line 439 of file main/strcompat.c.
00440 { 00441 register char *d = dst; 00442 register const char *s = src; 00443 register size_t n = siz; 00444 00445 /* Copy as many bytes as will fit */ 00446 if (n != 0 && --n != 0) { 00447 do { 00448 if ((*d++ = *s++) == 0) 00449 break; 00450 } while (--n != 0); 00451 } 00452 00453 /* Not enough room in dst, add NUL and traverse rest of src */ 00454 if (n == 0) { 00455 if (siz != 0) 00456 *d = '\0'; /* NUL-terminate dst */ 00457 while (*s++) 00458 ; 00459 } 00460 00461 return s - src - 1; /* count does not include NUL */ 00462 }