|
Lines 23-28
Link Here
|
| 23 |
|
23 |
|
| 24 |
#include <sys/types.h> |
24 |
#include <sys/types.h> |
| 25 |
#include <string.h> |
25 |
#include <string.h> |
|
|
26 |
#include <stdint.h> |
| 26 |
|
27 |
|
| 27 |
/* |
28 |
/* |
| 28 |
* Appends src to string dst of size siz (unlike strncat, siz is the |
29 |
* Appends src to string dst of size siz (unlike strncat, siz is the |
|
Lines 42-48
strlcat(char *dst, const char *src, size_t siz)
Link Here
|
| 42 |
/* Find the end of dst and adjust bytes left but don't go past end */ |
43 |
/* Find the end of dst and adjust bytes left but don't go past end */ |
| 43 |
while (n-- != 0 && *d != '\0') |
44 |
while (n-- != 0 && *d != '\0') |
| 44 |
d++; |
45 |
d++; |
| 45 |
dlen = d - dst; |
46 |
dlen = (uintptr_t)d - (uintptr_t)dst; |
| 46 |
n = siz - dlen; |
47 |
n = siz - dlen; |
| 47 |
|
48 |
|
| 48 |
if (n == 0) |
49 |
if (n == 0) |
|
Lines 55-62
strlcat(char *dst, const char *src, size_t siz)
Link Here
|
| 55 |
s++; |
56 |
s++; |
| 56 |
} |
57 |
} |
| 57 |
*d = '\0'; |
58 |
*d = '\0'; |
| 58 |
|
59 |
/* |
| 59 |
return(dlen + (s - src)); /* count does not include NUL */ |
60 |
* Cast pointers to unsigned type before calculation, to avoid signed |
|
|
61 |
* overflow when the string ends where the MSB has changed. |
| 62 |
*/ |
| 63 |
return (dlen + ((uintptr_t)s - (uintptr_t)src)); /* count does not include NUL */ |
| 60 |
} |
64 |
} |
| 61 |
|
65 |
|
| 62 |
#endif /* !HAVE_STRLCAT */ |
66 |
#endif /* !HAVE_STRLCAT */ |