This set of routines provides conversion between strings and data types such as integers, floating point numbers, and so on.
◆ safe_strtobool()
int safe_strtobool |
( |
const char * |
data, |
|
|
int * |
out |
|
) |
| |
Convert string to boolean.
- Parameters
-
| data | Scalar (string) value. |
[out] | out | If the conversion is successful, the result is written into this value. |
- Return values
-
0 | on success. |
non-0 | on error. |
Attempts to convert a scalar (string) value into a boolean. If the string value represents an integer, then 0 is false and non-0 is true. Also recognised are the literals "false" and "true". Trailing and leading whitespace are skipped. On success, the result is written into out and 0 is returned.
◆ safe_strtoint()
int safe_strtoint |
( |
const char * |
data, |
|
|
int * |
out |
|
) |
| |
Convert string to integer.
- Parameters
-
| data | Scalar (string) value. |
[out] | out | If the conversion is successful, the result is written into this value. |
- Return values
-
0 | on success. |
non-0 | on error. |
Attempts to convert a scalar (string) value into an integer. Trailing and leading whitespace are skipped. On success, the result is written into out and 0 is returned.
◆ safe_strtod()
int safe_strtod |
( |
const char * |
data, |
|
|
double * |
out |
|
) |
| |
Convert string to double-precision floating point.
- Parameters
-
| data | Scalar (string) value. |
[out] | out | If the conversion is successful, the result is written into this value. |
- Return values
-
0 | on success. |
non-0 | on error. |
Attempts to convert a scalar (string) value into a double-precision floating point number. Trailing and leading whitespace are skipped. On success, the result is written into out and 0 is returned.
◆ safe_strtoenum()
int safe_strtoenum |
( |
const char * |
data, |
|
|
int * |
out, |
|
|
const char *const * |
values |
|
) |
| |
Convert string to enumeration value.
- Parameters
-
| data | Scalar (string) value. |
[out] | out | If the conversion is successful, the result is written into this value. |
| values | A null-terminated array of choices; out is an index into this array. |
- Return values
-
0 | on success. |
non-0 | on error. |
Attempts to convert a scalar (string) value into an index into an array of choices (values). Trailing and leading whitespace are skipped. The conversion is case sensitive. The array values must be null terminated. On success, the result is written into out and 0 is returned.
◆ safe_strtooctalmode()
int safe_strtooctalmode |
( |
const char * |
data, |
|
|
int * |
out, |
|
|
int |
accept_mask |
|
) |
| |
Convert string to octal mode, suitable for filesystem.
- Parameters
-
| data | Scalar (string) value. |
[out] | out | If the conversion is successful, the result is written into this value. |
| accept_mask | A bitmask specifying the values that will be accepted. |
- Return values
-
0 | on success. |
non-0 | on error (and see errno). |
Attempts to convert a string (scalar) value into an octal mode suitable for filesystem use. The string itself does not have to be prefixed with "0" since we force octal conversion. If the conversion is successful, and the result does not contain any bits not set in accept_mask, the result is written into out and 0 is returned.