| 1 |
|
| 2 |
|
| 3 |
#include <commonlib/bsd/string.h> |
| 4 |
#include <ctype.h> |
| 5 |
#include <stddef.h> |
| 6 |
|
| 7 |
size_t strlen(const char *str) |
| 8 |
{ |
| 9 |
const char *ptr = str; |
| 10 |
|
| 11 |
while (*ptr++) |
| 12 |
; |
| 13 |
return ptr - str - 1; |
| 14 |
} |
| 15 |
|
| 16 |
size_t strnlen(const char *str, size_t maxlen) |
| 17 |
{ |
| 18 |
const char *ptr = str; |
| 19 |
const char *end = str + maxlen; |
| 20 |
|
| 21 |
if (!maxlen) |
| 22 |
return 0; |
| 23 |
|
| 24 |
while (*ptr++) { |
| 25 |
|
| 26 |
|
| 27 |
if (ptr == end) |
| 28 |
return maxlen; |
| 29 |
} |
| 30 |
return ptr - str - 1; |
| 31 |
} |
| 32 |
|
| 33 |
char *strcat(char *dst, const char *src) |
| 34 |
{ |
| 35 |
char *ptr = dst + strlen(dst); |
| 36 |
|
| 37 |
while (*src) |
| 38 |
*ptr++ = *src++; |
| 39 |
|
| 40 |
*ptr = '\0'; |
| 41 |
return dst; |
| 42 |
} |
| 43 |
|
| 44 |
char *strncat(char *dst, const char *src, size_t n) |
| 45 |
{ |
| 46 |
char *ptr = dst + strlen(dst); |
| 47 |
|
| 48 |
|
| 49 |
while (n-- > 0 && *src) |
| 50 |
*ptr++ = *src++; |
| 51 |
|
| 52 |
*ptr = '\0'; |
| 53 |
return dst; |
| 54 |
} |
| 55 |
|
| 56 |
unsigned int skip_atoi(char **ptr) |
| 57 |
{ |
| 58 |
unsigned int result = 0; |
| 59 |
char *str; |
| 60 |
|
| 61 |
for (str = *ptr; isdigit(str[0]); str++) |
| 62 |
result = result * 10 + (str[0] - '0'); |
| 63 |
*ptr = str; |
| 64 |
return result; |
| 65 |
} |