mb/google/brya/var/orisa: Update Type C DisplayPort HPD Configuration
[coreboot2.git] / src / commonlib / bsd / string.c
blob648227971311183da266be446ba82e2c2abc4fd3
1 /* SPDX-License-Identifier: BSD-3-Clause */
3 #include <commonlib/bsd/string.h>
4 #include <ctype.h>
5 #include <stddef.h>
7 size_t strlen(const char *str)
9 const char *ptr = str;
11 while (*ptr++)
13 return ptr - str - 1;
16 size_t strnlen(const char *str, size_t maxlen)
18 const char *ptr = str;
19 const char *end = str + maxlen;
21 if (!maxlen)
22 return 0;
24 while (*ptr++) {
25 /* Make sure this checks for ==, not >=, because the calculation
26 for `end` may overflow in some edge cases. */
27 if (ptr == end)
28 return maxlen;
30 return ptr - str - 1;
33 char *strcat(char *dst, const char *src)
35 char *ptr = dst + strlen(dst);
37 while (*src)
38 *ptr++ = *src++;
40 *ptr = '\0';
41 return dst;
44 char *strncat(char *dst, const char *src, size_t n)
46 char *ptr = dst + strlen(dst);
48 /* Not using strncpy() because '\0' may not be appended. */
49 while (n-- > 0 && *src)
50 *ptr++ = *src++;
52 *ptr = '\0';
53 return dst;
56 unsigned int skip_atoi(char **ptr)
58 unsigned int result = 0;
59 char *str;
61 for (str = *ptr; isdigit(str[0]); str++)
62 result = result * 10 + (str[0] - '0');
63 *ptr = str;
64 return result;