aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/DocBook/kernel-api.tmpl3
-rw-r--r--include/linux/kernel.h33
-rw-r--r--lib/kstrtox.c64
3 files changed, 100 insertions, 0 deletions
diff --git a/Documentation/DocBook/kernel-api.tmpl b/Documentation/DocBook/kernel-api.tmpl
index 00687ee9d363..f75ab4c1b281 100644
--- a/Documentation/DocBook/kernel-api.tmpl
+++ b/Documentation/DocBook/kernel-api.tmpl
@@ -58,6 +58,9 @@
58 58
59 <sect1><title>String Conversions</title> 59 <sect1><title>String Conversions</title>
60!Elib/vsprintf.c 60!Elib/vsprintf.c
61!Finclude/linux/kernel.h kstrtol
62!Finclude/linux/kernel.h kstrtoul
63!Elib/kstrtox.c
61 </sect1> 64 </sect1>
62 <sect1><title>String Manipulation</title> 65 <sect1><title>String Manipulation</title>
63<!-- All functions are exported at now 66<!-- All functions are exported at now
diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index d97ed5897447..d140e8fb075f 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -220,6 +220,23 @@ int __must_check _kstrtol(const char *s, unsigned int base, long *res);
220 220
221int __must_check kstrtoull(const char *s, unsigned int base, unsigned long long *res); 221int __must_check kstrtoull(const char *s, unsigned int base, unsigned long long *res);
222int __must_check kstrtoll(const char *s, unsigned int base, long long *res); 222int __must_check kstrtoll(const char *s, unsigned int base, long long *res);
223
224/**
225 * kstrtoul - convert a string to an unsigned long
226 * @s: The start of the string. The string must be null-terminated, and may also
227 * include a single newline before its terminating null. The first character
228 * may also be a plus sign, but not a minus sign.
229 * @base: The number base to use. The maximum supported base is 16. If base is
230 * given as 0, then the base of the string is automatically detected with the
231 * conventional semantics - If it begins with 0x the number will be parsed as a
232 * hexadecimal (case insensitive), if it otherwise begins with 0, it will be
233 * parsed as an octal number. Otherwise it will be parsed as a decimal.
234 * @res: Where to write the result of the conversion on success.
235 *
236 * Returns 0 on success, -ERANGE on overflow and -EINVAL on parsing error.
237 * Used as a replacement for the obsolete simple_strtoull. Return code must
238 * be checked.
239*/
223static inline int __must_check kstrtoul(const char *s, unsigned int base, unsigned long *res) 240static inline int __must_check kstrtoul(const char *s, unsigned int base, unsigned long *res)
224{ 241{
225 /* 242 /*
@@ -233,6 +250,22 @@ static inline int __must_check kstrtoul(const char *s, unsigned int base, unsign
233 return _kstrtoul(s, base, res); 250 return _kstrtoul(s, base, res);
234} 251}
235 252
253/**
254 * kstrtol - convert a string to a long
255 * @s: The start of the string. The string must be null-terminated, and may also
256 * include a single newline before its terminating null. The first character
257 * may also be a plus sign or a minus sign.
258 * @base: The number base to use. The maximum supported base is 16. If base is
259 * given as 0, then the base of the string is automatically detected with the
260 * conventional semantics - If it begins with 0x the number will be parsed as a
261 * hexadecimal (case insensitive), if it otherwise begins with 0, it will be
262 * parsed as an octal number. Otherwise it will be parsed as a decimal.
263 * @res: Where to write the result of the conversion on success.
264 *
265 * Returns 0 on success, -ERANGE on overflow and -EINVAL on parsing error.
266 * Used as a replacement for the obsolete simple_strtoull. Return code must
267 * be checked.
268 */
236static inline int __must_check kstrtol(const char *s, unsigned int base, long *res) 269static inline int __must_check kstrtol(const char *s, unsigned int base, long *res)
237{ 270{
238 /* 271 /*
diff --git a/lib/kstrtox.c b/lib/kstrtox.c
index c3615eab0cc3..f78ae0c0c4e2 100644
--- a/lib/kstrtox.c
+++ b/lib/kstrtox.c
@@ -104,6 +104,22 @@ static int _kstrtoull(const char *s, unsigned int base, unsigned long long *res)
104 return 0; 104 return 0;
105} 105}
106 106
107/**
108 * kstrtoull - convert a string to an unsigned long long
109 * @s: The start of the string. The string must be null-terminated, and may also
110 * include a single newline before its terminating null. The first character
111 * may also be a plus sign, but not a minus sign.
112 * @base: The number base to use. The maximum supported base is 16. If base is
113 * given as 0, then the base of the string is automatically detected with the
114 * conventional semantics - If it begins with 0x the number will be parsed as a
115 * hexadecimal (case insensitive), if it otherwise begins with 0, it will be
116 * parsed as an octal number. Otherwise it will be parsed as a decimal.
117 * @res: Where to write the result of the conversion on success.
118 *
119 * Returns 0 on success, -ERANGE on overflow and -EINVAL on parsing error.
120 * Used as a replacement for the obsolete simple_strtoull. Return code must
121 * be checked.
122 */
107int kstrtoull(const char *s, unsigned int base, unsigned long long *res) 123int kstrtoull(const char *s, unsigned int base, unsigned long long *res)
108{ 124{
109 if (s[0] == '+') 125 if (s[0] == '+')
@@ -112,6 +128,22 @@ int kstrtoull(const char *s, unsigned int base, unsigned long long *res)
112} 128}
113EXPORT_SYMBOL(kstrtoull); 129EXPORT_SYMBOL(kstrtoull);
114 130
131/**
132 * kstrtoll - convert a string to a long long
133 * @s: The start of the string. The string must be null-terminated, and may also
134 * include a single newline before its terminating null. The first character
135 * may also be a plus sign or a minus sign.
136 * @base: The number base to use. The maximum supported base is 16. If base is
137 * given as 0, then the base of the string is automatically detected with the
138 * conventional semantics - If it begins with 0x the number will be parsed as a
139 * hexadecimal (case insensitive), if it otherwise begins with 0, it will be
140 * parsed as an octal number. Otherwise it will be parsed as a decimal.
141 * @res: Where to write the result of the conversion on success.
142 *
143 * Returns 0 on success, -ERANGE on overflow and -EINVAL on parsing error.
144 * Used as a replacement for the obsolete simple_strtoull. Return code must
145 * be checked.
146 */
115int kstrtoll(const char *s, unsigned int base, long long *res) 147int kstrtoll(const char *s, unsigned int base, long long *res)
116{ 148{
117 unsigned long long tmp; 149 unsigned long long tmp;
@@ -168,6 +200,22 @@ int _kstrtol(const char *s, unsigned int base, long *res)
168} 200}
169EXPORT_SYMBOL(_kstrtol); 201EXPORT_SYMBOL(_kstrtol);
170 202
203/**
204 * kstrtouint - convert a string to an unsigned int
205 * @s: The start of the string. The string must be null-terminated, and may also
206 * include a single newline before its terminating null. The first character
207 * may also be a plus sign, but not a minus sign.
208 * @base: The number base to use. The maximum supported base is 16. If base is
209 * given as 0, then the base of the string is automatically detected with the
210 * conventional semantics - If it begins with 0x the number will be parsed as a
211 * hexadecimal (case insensitive), if it otherwise begins with 0, it will be
212 * parsed as an octal number. Otherwise it will be parsed as a decimal.
213 * @res: Where to write the result of the conversion on success.
214 *
215 * Returns 0 on success, -ERANGE on overflow and -EINVAL on parsing error.
216 * Used as a replacement for the obsolete simple_strtoull. Return code must
217 * be checked.
218 */
171int kstrtouint(const char *s, unsigned int base, unsigned int *res) 219int kstrtouint(const char *s, unsigned int base, unsigned int *res)
172{ 220{
173 unsigned long long tmp; 221 unsigned long long tmp;
@@ -183,6 +231,22 @@ int kstrtouint(const char *s, unsigned int base, unsigned int *res)
183} 231}
184EXPORT_SYMBOL(kstrtouint); 232EXPORT_SYMBOL(kstrtouint);
185 233
234/**
235 * kstrtoint - convert a string to an int
236 * @s: The start of the string. The string must be null-terminated, and may also
237 * include a single newline before its terminating null. The first character
238 * may also be a plus sign or a minus sign.
239 * @base: The number base to use. The maximum supported base is 16. If base is
240 * given as 0, then the base of the string is automatically detected with the
241 * conventional semantics - If it begins with 0x the number will be parsed as a
242 * hexadecimal (case insensitive), if it otherwise begins with 0, it will be
243 * parsed as an octal number. Otherwise it will be parsed as a decimal.
244 * @res: Where to write the result of the conversion on success.
245 *
246 * Returns 0 on success, -ERANGE on overflow and -EINVAL on parsing error.
247 * Used as a replacement for the obsolete simple_strtoull. Return code must
248 * be checked.
249 */
186int kstrtoint(const char *s, unsigned int base, int *res) 250int kstrtoint(const char *s, unsigned int base, int *res)
187{ 251{
188 long long tmp; 252 long long tmp;