xref: /aosp_15_r20/external/ltp/include/tst_parse.h (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1*49cdfc7eSAndroid Build Coastguard Worker /* SPDX-License-Identifier: GPL-2.0-or-later */
2*49cdfc7eSAndroid Build Coastguard Worker /*
3*49cdfc7eSAndroid Build Coastguard Worker  * Copyright (c) 2015-2024 Cyril Hrubis <[email protected]>
4*49cdfc7eSAndroid Build Coastguard Worker  */
5*49cdfc7eSAndroid Build Coastguard Worker 
6*49cdfc7eSAndroid Build Coastguard Worker /**
7*49cdfc7eSAndroid Build Coastguard Worker  * DOC: Option parsing functions
8*49cdfc7eSAndroid Build Coastguard Worker  *
9*49cdfc7eSAndroid Build Coastguard Worker  * Implements simple helpers on the top of the strtol() and strtod() for
10*49cdfc7eSAndroid Build Coastguard Worker  * command line option parsing.
11*49cdfc7eSAndroid Build Coastguard Worker  */
12*49cdfc7eSAndroid Build Coastguard Worker 
13*49cdfc7eSAndroid Build Coastguard Worker #ifndef TST_PARSE_H__
14*49cdfc7eSAndroid Build Coastguard Worker #define TST_PARSE_H__
15*49cdfc7eSAndroid Build Coastguard Worker 
16*49cdfc7eSAndroid Build Coastguard Worker /**
17*49cdfc7eSAndroid Build Coastguard Worker  * tst_parse_int() - Parse an integer from a string.
18*49cdfc7eSAndroid Build Coastguard Worker  *
19*49cdfc7eSAndroid Build Coastguard Worker  * @str: A string with an integer number.
20*49cdfc7eSAndroid Build Coastguard Worker  * @val: A pointer to integer to store the result to.
21*49cdfc7eSAndroid Build Coastguard Worker  * @min: A lower bound, pass INT_MIN for full range.
22*49cdfc7eSAndroid Build Coastguard Worker  * @max: An upper bound, pass INT_MAX for full range.
23*49cdfc7eSAndroid Build Coastguard Worker  * return: A zero if whole string was consumed and the value was within bounds,
24*49cdfc7eSAndroid Build Coastguard Worker  *         an errno otherwise.
25*49cdfc7eSAndroid Build Coastguard Worker  */
26*49cdfc7eSAndroid Build Coastguard Worker int tst_parse_int(const char *str, int *val, int min, int max);
27*49cdfc7eSAndroid Build Coastguard Worker 
28*49cdfc7eSAndroid Build Coastguard Worker /**
29*49cdfc7eSAndroid Build Coastguard Worker  * tst_parse_long() - Parse a long integer from a string.
30*49cdfc7eSAndroid Build Coastguard Worker  *
31*49cdfc7eSAndroid Build Coastguard Worker  * @str: A string with an integer number.
32*49cdfc7eSAndroid Build Coastguard Worker  * @val: A pointer to long integer to store the result to.
33*49cdfc7eSAndroid Build Coastguard Worker  * @min: A lower bound, pass LONG_MIN for full range.
34*49cdfc7eSAndroid Build Coastguard Worker  * @max: An upper bound, pass LONG_MAX for full range.
35*49cdfc7eSAndroid Build Coastguard Worker  * return: A zero if whole string was consumed and the value was within bounds,
36*49cdfc7eSAndroid Build Coastguard Worker  *         an errno otherwise.
37*49cdfc7eSAndroid Build Coastguard Worker  */
38*49cdfc7eSAndroid Build Coastguard Worker int tst_parse_long(const char *str, long *val, long min, long max);
39*49cdfc7eSAndroid Build Coastguard Worker 
40*49cdfc7eSAndroid Build Coastguard Worker /**
41*49cdfc7eSAndroid Build Coastguard Worker  * tst_parse_float() - Parse a floating point number from a string.
42*49cdfc7eSAndroid Build Coastguard Worker  *
43*49cdfc7eSAndroid Build Coastguard Worker  * @str: A string with a floating point number.
44*49cdfc7eSAndroid Build Coastguard Worker  * @val: A pointer to float to store the result to.
45*49cdfc7eSAndroid Build Coastguard Worker  * @min: A lower bound.
46*49cdfc7eSAndroid Build Coastguard Worker  * @max: An upper bound.
47*49cdfc7eSAndroid Build Coastguard Worker  * return: A zero if whole string was consumed and the value was within bounds,
48*49cdfc7eSAndroid Build Coastguard Worker  *         an errno otherwise.
49*49cdfc7eSAndroid Build Coastguard Worker  */
50*49cdfc7eSAndroid Build Coastguard Worker int tst_parse_float(const char *str, float *val, float min, float max);
51*49cdfc7eSAndroid Build Coastguard Worker 
52*49cdfc7eSAndroid Build Coastguard Worker /**
53*49cdfc7eSAndroid Build Coastguard Worker  * tst_parse_filesize() - Parse a file size from a string.
54*49cdfc7eSAndroid Build Coastguard Worker  *
55*49cdfc7eSAndroid Build Coastguard Worker  * @str: A string a positive number optionally followed by an unit, i.e. K, M,
56*49cdfc7eSAndroid Build Coastguard Worker  *       or G for kilobytes, megabytes and gigabytes.
57*49cdfc7eSAndroid Build Coastguard Worker  * @val: A pointer to long long integer to store the size in bytes to.
58*49cdfc7eSAndroid Build Coastguard Worker  * @min: A lower bound.
59*49cdfc7eSAndroid Build Coastguard Worker  * @max: An upper bound.
60*49cdfc7eSAndroid Build Coastguard Worker  * return: A zero if whole string was consumed and the value was within bounds,
61*49cdfc7eSAndroid Build Coastguard Worker  *         an errno otherwise.
62*49cdfc7eSAndroid Build Coastguard Worker  */
63*49cdfc7eSAndroid Build Coastguard Worker int tst_parse_filesize(const char *str, long long *val, long long min, long long max);
64*49cdfc7eSAndroid Build Coastguard Worker 
65*49cdfc7eSAndroid Build Coastguard Worker #endif	/* TST_PARSE_H__ */
66