1
2#ifndef _LINUX_KSTRTOX_H
3#define _LINUX_KSTRTOX_H
4
5#include <linux/compiler.h>
6#include <linux/types.h>
7
8
9int __must_check _kstrtoul(const char *s, unsigned int base, unsigned long *res);
10int __must_check _kstrtol(const char *s, unsigned int base, long *res);
11
12int __must_check kstrtoull(const char *s, unsigned int base, unsigned long long *res);
13int __must_check kstrtoll(const char *s, unsigned int base, long long *res);
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30static inline int __must_check kstrtoul(const char *s, unsigned int base, unsigned long *res)
31{
32
33
34
35
36 if (sizeof(unsigned long) == sizeof(unsigned long long) &&
37 __alignof__(unsigned long) == __alignof__(unsigned long long))
38 return kstrtoull(s, base, (unsigned long long *)res);
39 else
40 return _kstrtoul(s, base, res);
41}
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58static inline int __must_check kstrtol(const char *s, unsigned int base, long *res)
59{
60
61
62
63
64 if (sizeof(long) == sizeof(long long) &&
65 __alignof__(long) == __alignof__(long long))
66 return kstrtoll(s, base, (long long *)res);
67 else
68 return _kstrtol(s, base, res);
69}
70
71int __must_check kstrtouint(const char *s, unsigned int base, unsigned int *res);
72int __must_check kstrtoint(const char *s, unsigned int base, int *res);
73
74static inline int __must_check kstrtou64(const char *s, unsigned int base, u64 *res)
75{
76 return kstrtoull(s, base, res);
77}
78
79static inline int __must_check kstrtos64(const char *s, unsigned int base, s64 *res)
80{
81 return kstrtoll(s, base, res);
82}
83
84static inline int __must_check kstrtou32(const char *s, unsigned int base, u32 *res)
85{
86 return kstrtouint(s, base, res);
87}
88
89static inline int __must_check kstrtos32(const char *s, unsigned int base, s32 *res)
90{
91 return kstrtoint(s, base, res);
92}
93
94int __must_check kstrtou16(const char *s, unsigned int base, u16 *res);
95int __must_check kstrtos16(const char *s, unsigned int base, s16 *res);
96int __must_check kstrtou8(const char *s, unsigned int base, u8 *res);
97int __must_check kstrtos8(const char *s, unsigned int base, s8 *res);
98int __must_check kstrtobool(const char *s, bool *res);
99
100int __must_check kstrtoull_from_user(const char __user *s, size_t count, unsigned int base, unsigned long long *res);
101int __must_check kstrtoll_from_user(const char __user *s, size_t count, unsigned int base, long long *res);
102int __must_check kstrtoul_from_user(const char __user *s, size_t count, unsigned int base, unsigned long *res);
103int __must_check kstrtol_from_user(const char __user *s, size_t count, unsigned int base, long *res);
104int __must_check kstrtouint_from_user(const char __user *s, size_t count, unsigned int base, unsigned int *res);
105int __must_check kstrtoint_from_user(const char __user *s, size_t count, unsigned int base, int *res);
106int __must_check kstrtou16_from_user(const char __user *s, size_t count, unsigned int base, u16 *res);
107int __must_check kstrtos16_from_user(const char __user *s, size_t count, unsigned int base, s16 *res);
108int __must_check kstrtou8_from_user(const char __user *s, size_t count, unsigned int base, u8 *res);
109int __must_check kstrtos8_from_user(const char __user *s, size_t count, unsigned int base, s8 *res);
110int __must_check kstrtobool_from_user(const char __user *s, size_t count, bool *res);
111
112static inline int __must_check kstrtou64_from_user(const char __user *s, size_t count, unsigned int base, u64 *res)
113{
114 return kstrtoull_from_user(s, count, base, res);
115}
116
117static inline int __must_check kstrtos64_from_user(const char __user *s, size_t count, unsigned int base, s64 *res)
118{
119 return kstrtoll_from_user(s, count, base, res);
120}
121
122static inline int __must_check kstrtou32_from_user(const char __user *s, size_t count, unsigned int base, u32 *res)
123{
124 return kstrtouint_from_user(s, count, base, res);
125}
126
127static inline int __must_check kstrtos32_from_user(const char __user *s, size_t count, unsigned int base, s32 *res)
128{
129 return kstrtoint_from_user(s, count, base, res);
130}
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145extern unsigned long simple_strtoul(const char *,char **,unsigned int);
146extern long simple_strtol(const char *,char **,unsigned int);
147extern unsigned long long simple_strtoull(const char *,char **,unsigned int);
148extern long long simple_strtoll(const char *,char **,unsigned int);
149
150static inline int strtobool(const char *s, bool *res)
151{
152 return kstrtobool(s, res);
153}
154
155#endif
156