0001
0002 #ifndef _LINUX_KSTRTOX_H
0003 #define _LINUX_KSTRTOX_H
0004
0005 #include <linux/compiler.h>
0006 #include <linux/types.h>
0007
0008
0009 int __must_check _kstrtoul(const char *s, unsigned int base, unsigned long *res);
0010 int __must_check _kstrtol(const char *s, unsigned int base, long *res);
0011
0012 int __must_check kstrtoull(const char *s, unsigned int base, unsigned long long *res);
0013 int __must_check kstrtoll(const char *s, unsigned int base, long long *res);
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030 static inline int __must_check kstrtoul(const char *s, unsigned int base, unsigned long *res)
0031 {
0032
0033
0034
0035
0036 if (sizeof(unsigned long) == sizeof(unsigned long long) &&
0037 __alignof__(unsigned long) == __alignof__(unsigned long long))
0038 return kstrtoull(s, base, (unsigned long long *)res);
0039 else
0040 return _kstrtoul(s, base, res);
0041 }
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058 static inline int __must_check kstrtol(const char *s, unsigned int base, long *res)
0059 {
0060
0061
0062
0063
0064 if (sizeof(long) == sizeof(long long) &&
0065 __alignof__(long) == __alignof__(long long))
0066 return kstrtoll(s, base, (long long *)res);
0067 else
0068 return _kstrtol(s, base, res);
0069 }
0070
0071 int __must_check kstrtouint(const char *s, unsigned int base, unsigned int *res);
0072 int __must_check kstrtoint(const char *s, unsigned int base, int *res);
0073
0074 static inline int __must_check kstrtou64(const char *s, unsigned int base, u64 *res)
0075 {
0076 return kstrtoull(s, base, res);
0077 }
0078
0079 static inline int __must_check kstrtos64(const char *s, unsigned int base, s64 *res)
0080 {
0081 return kstrtoll(s, base, res);
0082 }
0083
0084 static inline int __must_check kstrtou32(const char *s, unsigned int base, u32 *res)
0085 {
0086 return kstrtouint(s, base, res);
0087 }
0088
0089 static inline int __must_check kstrtos32(const char *s, unsigned int base, s32 *res)
0090 {
0091 return kstrtoint(s, base, res);
0092 }
0093
0094 int __must_check kstrtou16(const char *s, unsigned int base, u16 *res);
0095 int __must_check kstrtos16(const char *s, unsigned int base, s16 *res);
0096 int __must_check kstrtou8(const char *s, unsigned int base, u8 *res);
0097 int __must_check kstrtos8(const char *s, unsigned int base, s8 *res);
0098 int __must_check kstrtobool(const char *s, bool *res);
0099
0100 int __must_check kstrtoull_from_user(const char __user *s, size_t count, unsigned int base, unsigned long long *res);
0101 int __must_check kstrtoll_from_user(const char __user *s, size_t count, unsigned int base, long long *res);
0102 int __must_check kstrtoul_from_user(const char __user *s, size_t count, unsigned int base, unsigned long *res);
0103 int __must_check kstrtol_from_user(const char __user *s, size_t count, unsigned int base, long *res);
0104 int __must_check kstrtouint_from_user(const char __user *s, size_t count, unsigned int base, unsigned int *res);
0105 int __must_check kstrtoint_from_user(const char __user *s, size_t count, unsigned int base, int *res);
0106 int __must_check kstrtou16_from_user(const char __user *s, size_t count, unsigned int base, u16 *res);
0107 int __must_check kstrtos16_from_user(const char __user *s, size_t count, unsigned int base, s16 *res);
0108 int __must_check kstrtou8_from_user(const char __user *s, size_t count, unsigned int base, u8 *res);
0109 int __must_check kstrtos8_from_user(const char __user *s, size_t count, unsigned int base, s8 *res);
0110 int __must_check kstrtobool_from_user(const char __user *s, size_t count, bool *res);
0111
0112 static inline int __must_check kstrtou64_from_user(const char __user *s, size_t count, unsigned int base, u64 *res)
0113 {
0114 return kstrtoull_from_user(s, count, base, res);
0115 }
0116
0117 static inline int __must_check kstrtos64_from_user(const char __user *s, size_t count, unsigned int base, s64 *res)
0118 {
0119 return kstrtoll_from_user(s, count, base, res);
0120 }
0121
0122 static inline int __must_check kstrtou32_from_user(const char __user *s, size_t count, unsigned int base, u32 *res)
0123 {
0124 return kstrtouint_from_user(s, count, base, res);
0125 }
0126
0127 static inline int __must_check kstrtos32_from_user(const char __user *s, size_t count, unsigned int base, s32 *res)
0128 {
0129 return kstrtoint_from_user(s, count, base, res);
0130 }
0131
0132
0133
0134
0135
0136
0137
0138
0139
0140
0141
0142
0143
0144
0145 extern unsigned long simple_strtoul(const char *,char **,unsigned int);
0146 extern long simple_strtol(const char *,char **,unsigned int);
0147 extern unsigned long long simple_strtoull(const char *,char **,unsigned int);
0148 extern long long simple_strtoll(const char *,char **,unsigned int);
0149
0150 static inline int strtobool(const char *s, bool *res)
0151 {
0152 return kstrtobool(s, res);
0153 }
0154
0155 #endif