3 * Helper functions generally used for parsing kernel command line
6 * Code and copyrights come from init/main.c and arch/i386/kernel/setup.c.
8 * This source code is licensed under the GNU General Public License,
9 * Version 2. See the file COPYING for more details.
11 * GNU Indent formatting options for this file: -kr -i8 -npsl -pcs
15 #include <linux/module.h>
16 #include <linux/kernel.h>
17 #include <linux/string.h>
21 * get_option - Parse integer from an option string
23 * @pint: (output) integer value parsed from @str
25 * Read an int from an option string; if available accept a subsequent
29 * 0 : no int in string
30 * 1 : int found, no subsequent comma
31 * 2 : int found including a subsequent comma
34 int get_option (char **str
, int *pint
)
40 *pint
= simple_strtol (cur
, str
, 0);
52 * get_options - Parse a string into a list of integers
53 * @str: String to be parsed
54 * @nints: size of integer array
55 * @ints: integer array
57 * This function parses a string containing a comma-separated
58 * list of integers. The parse halts when the array is
59 * full, or when no more numbers can be retrieved from the
62 * Return value is the character in the string which caused
63 * the parse to end (typically a null terminator, if @str is
64 * completely parseable).
67 char *get_options (char *str
, int nints
, int *ints
)
72 res
= get_option (&str
, ints
+ i
);
84 * memparse - parse a string with mem suffixes into a number
85 * @ptr: Where parse begins
86 * @retptr: (output) Pointer to next char after parse completes
88 * Parses a string into a number. The number stored
89 * at @ptr is potentially suffixed with %K (for
90 * kilobytes, or 1024 bytes) or suffixed with %M (for
91 * megabytes, or 1048576 bytes). If the number is suffixed
92 * with K or M, then the return value is the number
93 * multiplied by one kilobyte, or one megabyte, respectively.
96 unsigned long memparse (char *ptr
, char **retptr
)
98 unsigned long ret
= simple_strtoul (ptr
, retptr
, 0);
115 EXPORT_SYMBOL(memparse
);
116 EXPORT_SYMBOL(get_option
);
117 EXPORT_SYMBOL(get_options
);