aboutsummaryrefslogtreecommitdiff
path: root/module
diff options
context:
space:
mode:
authorнаб <nabijaczleweli@nabijaczleweli.xyz>2022-05-07 17:54:29 +0000
committerBrian Behlendorf <behlendorf1@llnl.gov>2022-05-13 17:15:47 +0000
commitde8216451840add3be18df0d9fa423a30e35e8a6 (patch)
tree682088d4f916bc48bbf2266bd203cb5428bedeab /module
parent354a1bfb8e77ebcba5482139931144e88ec74bbc (diff)
downloadsrc-de8216451840add3be18df0d9fa423a30e35e8a6.tar.gz
src-de8216451840add3be18df0d9fa423a30e35e8a6.zip
linux: spl: generic: ddi_strto*: match solaris ddi_strto*(9)
Recognise initial whitespace, + in both cases, and - also in unsigneds Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz> Closes #13434
Diffstat (limited to 'module')
-rw-r--r--module/os/linux/spl/spl-generic.c46
-rw-r--r--module/zfs/sa.c4
2 files changed, 19 insertions, 31 deletions
diff --git a/module/os/linux/spl/spl-generic.c b/module/os/linux/spl/spl-generic.c
index 435b054617cf..f99a2f966660 100644
--- a/module/os/linux/spl/spl-generic.c
+++ b/module/os/linux/spl/spl-generic.c
@@ -425,22 +425,33 @@ EXPORT_SYMBOL(__aeabi_ldivmod);
* functions against their Solaris counterparts. It is possible that I
* may have misinterpreted the man page or the man page is incorrect.
*/
-static int ddi_strtoul(const char *, char **, int, unsigned long *);
int ddi_strtol(const char *, char **, int, long *);
int ddi_strtoull(const char *, char **, int, unsigned long long *);
int ddi_strtoll(const char *, char **, int, long long *);
-#define define_ddi_strtoux(type, valtype, ...) \
-__VA_ARGS__ int ddi_strtou##type(const char *str, char **endptr, \
+#define define_ddi_strtox(type, valtype) \
+int ddi_strto##type(const char *str, char **endptr, \
int base, valtype *result) \
{ \
valtype last_value, value = 0; \
char *ptr = (char *)str; \
- int digit; \
+ int digit, minus = 0; \
+ \
+ while (strchr(" \t\n\r\f", *ptr)) \
+ ++ptr; \
\
if (strlen(ptr) == 0) \
return (EINVAL); \
\
+ switch (*ptr) { \
+ case '-': \
+ minus = 1; \
+ zfs_fallthrough; \
+ case '+': \
+ ++ptr; \
+ break; \
+ } \
+ \
/* Auto-detect base based on prefix */ \
if (!base) { \
if (str[0] == '0') { \
@@ -477,7 +488,7 @@ __VA_ARGS__ int ddi_strtou##type(const char *str, char **endptr, \
ptr++; \
} \
\
- *result = value; \
+ *result = minus ? -value : value; \
\
if (endptr) \
*endptr = ptr; \
@@ -485,31 +496,8 @@ __VA_ARGS__ int ddi_strtou##type(const char *str, char **endptr, \
return (0); \
} \
-#define define_ddi_strtox(type, valtype) \
-int ddi_strto##type(const char *str, char **endptr, \
- int base, valtype *result) \
-{ \
- int rc; \
- \
- if (*str == '-') { \
- rc = ddi_strtou##type(str + 1, endptr, base, result); \
- if (!rc) { \
- if (*endptr == str + 1) \
- *endptr = (char *)str; \
- else \
- *result = -*result; \
- } \
- } else { \
- rc = ddi_strtou##type(str, endptr, base, result); \
- } \
- \
- return (rc); \
-}
-
-#define blank
-define_ddi_strtoux(l, unsigned long, static)
define_ddi_strtox(l, long)
-define_ddi_strtoux(ll, unsigned long long, blank)
+define_ddi_strtox(ull, unsigned long long)
define_ddi_strtox(ll, long long)
EXPORT_SYMBOL(ddi_strtol);
diff --git a/module/zfs/sa.c b/module/zfs/sa.c
index 2b6776581a47..db8c2b831f1d 100644
--- a/module/zfs/sa.c
+++ b/module/zfs/sa.c
@@ -1068,8 +1068,8 @@ sa_setup(objset_t *os, uint64_t sa_obj, const sa_attr_reg_t *reg_attrs,
za.za_num_integers);
break;
}
- VERIFY(ddi_strtoull(za.za_name, NULL, 10,
- (unsigned long long *)&lot_num) == 0);
+ VERIFY0(ddi_strtoull(za.za_name, NULL, 10,
+ (unsigned long long *)&lot_num));
(void) sa_add_layout_entry(os, lot_attrs,
za.za_num_integers, lot_num,