2 * Copyright 2007-2010 Luis R. Rodriguez <mcgrof@winlab.rutgers.edu>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
8 * Compatibility file for Linux wireless for kernels 2.6.25.
11 #include <linux/miscdevice.h>
14 * The following things are out of ./lib/vsprintf.c
15 * The new iwlwifi driver is using them.
19 * strict_strtoul - convert a string to an unsigned long strictly
20 * @cp: The string to be converted
21 * @base: The number base to use
22 * @res: The converted result value
24 * strict_strtoul converts a string to an unsigned long only if the
25 * string is really an unsigned long string, any string containing
26 * any invalid char at the tail will be rejected and -EINVAL is returned,
27 * only a newline char at the tail is acceptible because people generally
28 * change a module parameter in the following way:
30 * echo 1024 > /sys/module/e1000/parameters/copybreak
32 * echo will append a newline to the tail.
34 * It returns 0 if conversion is successful and *res is set to the converted
35 * value, otherwise it returns -EINVAL and *res is set to 0.
37 * simple_strtoul just ignores the successive invalid characters and
38 * return the converted value of prefix part of the string.
40 int strict_strtoul(const char *cp, unsigned int base, unsigned long *res);
43 * strict_strtol - convert a string to a long strictly
44 * @cp: The string to be converted
45 * @base: The number base to use
46 * @res: The converted result value
48 * strict_strtol is similiar to strict_strtoul, but it allows the first
49 * character of a string is '-'.
51 * It returns 0 if conversion is successful and *res is set to the converted
52 * value, otherwise it returns -EINVAL and *res is set to 0.
54 int strict_strtol(const char *cp, unsigned int base, long *res);
56 #define define_strict_strtoux(type, valtype) \
57 int strict_strtou##type(const char *cp, unsigned int base, valtype *res)\
68 val = simple_strtou##type(cp, &tail, base); \
69 if ((*tail == '\0') || \
70 ((len == (size_t)(tail - cp) + 1) && (*tail == '\n'))) {\
78 #define define_strict_strtox(type, valtype) \
79 int strict_strto##type(const char *cp, unsigned int base, valtype *res) \
83 ret = strict_strtou##type(cp+1, base, res); \
87 ret = strict_strtou##type(cp, base, res); \
92 define_strict_strtoux(l, unsigned long)
93 define_strict_strtox(l, long)
95 EXPORT_SYMBOL(strict_strtoul);
96 EXPORT_SYMBOL(strict_strtol);