clk: samsung: Add bus clock for GPU/G3D on Exynos4412
[linux/fpc-iii.git] / arch / s390 / boot / string.c
blobb11e8108773a56a77c7d8b96ec2aacc27a8e6e52
1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/ctype.h>
3 #include <linux/kernel.h>
4 #include <linux/errno.h>
5 #undef CONFIG_KASAN
6 #include "../lib/string.c"
8 int strncmp(const char *cs, const char *ct, size_t count)
10 unsigned char c1, c2;
12 while (count) {
13 c1 = *cs++;
14 c2 = *ct++;
15 if (c1 != c2)
16 return c1 < c2 ? -1 : 1;
17 if (!c1)
18 break;
19 count--;
21 return 0;
24 char *skip_spaces(const char *str)
26 while (isspace(*str))
27 ++str;
28 return (char *)str;
31 char *strim(char *s)
33 size_t size;
34 char *end;
36 size = strlen(s);
37 if (!size)
38 return s;
40 end = s + size - 1;
41 while (end >= s && isspace(*end))
42 end--;
43 *(end + 1) = '\0';
45 return skip_spaces(s);
48 /* Works only for digits and letters, but small and fast */
49 #define TOLOWER(x) ((x) | 0x20)
51 static unsigned int simple_guess_base(const char *cp)
53 if (cp[0] == '0') {
54 if (TOLOWER(cp[1]) == 'x' && isxdigit(cp[2]))
55 return 16;
56 else
57 return 8;
58 } else {
59 return 10;
63 /**
64 * simple_strtoull - convert a string to an unsigned long long
65 * @cp: The start of the string
66 * @endp: A pointer to the end of the parsed string will be placed here
67 * @base: The number base to use
70 unsigned long long simple_strtoull(const char *cp, char **endp,
71 unsigned int base)
73 unsigned long long result = 0;
75 if (!base)
76 base = simple_guess_base(cp);
78 if (base == 16 && cp[0] == '0' && TOLOWER(cp[1]) == 'x')
79 cp += 2;
81 while (isxdigit(*cp)) {
82 unsigned int value;
84 value = isdigit(*cp) ? *cp - '0' : TOLOWER(*cp) - 'a' + 10;
85 if (value >= base)
86 break;
87 result = result * base + value;
88 cp++;
90 if (endp)
91 *endp = (char *)cp;
93 return result;
96 long simple_strtol(const char *cp, char **endp, unsigned int base)
98 if (*cp == '-')
99 return -simple_strtoull(cp + 1, endp, base);
101 return simple_strtoull(cp, endp, base);
104 int kstrtobool(const char *s, bool *res)
106 if (!s)
107 return -EINVAL;
109 switch (s[0]) {
110 case 'y':
111 case 'Y':
112 case '1':
113 *res = true;
114 return 0;
115 case 'n':
116 case 'N':
117 case '0':
118 *res = false;
119 return 0;
120 case 'o':
121 case 'O':
122 switch (s[1]) {
123 case 'n':
124 case 'N':
125 *res = true;
126 return 0;
127 case 'f':
128 case 'F':
129 *res = false;
130 return 0;
131 default:
132 break;
134 default:
135 break;
138 return -EINVAL;