strnum.h revision 0d73aae8da55fadb59c1fef7aa36d5e43f5f8840
de62ce819d59a529530da4b57be1b8d6dad13d6bTimo Sirainen/* Return TRUE if all characters in string are numbers.
de62ce819d59a529530da4b57be1b8d6dad13d6bTimo Sirainen Stop when `end_char' is found from string. */
de62ce819d59a529530da4b57be1b8d6dad13d6bTimo Sirainenbool str_is_numeric(const char *str, char end_char) ATTR_PURE;
af49da69a12b5383b89c7b2fa574c2a85b9ca310Timo Sirainen/* str_to_*() functions return 0 if string is nothing more than a valid number
fea53234804e75bb8f0b87ab0a0b1cc1c9770031Timo Sirainen in valid range. Otherwise -1 is returned and num_r is left untouched
de62ce819d59a529530da4b57be1b8d6dad13d6bTimo Sirainen str_parse_*() helpers do not require the number to be the entire string
de62ce819d59a529530da4b57be1b8d6dad13d6bTimo Sirainen and pass back the pointer just past a valid parsed integer in endp_r if
de62ce819d59a529530da4b57be1b8d6dad13d6bTimo Sirainen it is non-NULL. What is written to endp_r in error cases is undefined.
518781a0a4ba2403f23dbadda445b107fbb87daaPhil Carmodyint str_to_uint(const char *str, unsigned int *num_r) ATTR_WARN_UNUSED_RESULT;
33750ba29b605a925af5aed58d3f3735422b1e25Phil Carmodyint str_to_ulong(const char *str, unsigned long *num_r) ATTR_WARN_UNUSED_RESULT;
33750ba29b605a925af5aed58d3f3735422b1e25Phil Carmodyint str_to_ullong(const char *str, unsigned long long *num_r) ATTR_WARN_UNUSED_RESULT;
33750ba29b605a925af5aed58d3f3735422b1e25Phil Carmodyint str_to_uint32(const char *str, uint32_t *num_r) ATTR_WARN_UNUSED_RESULT;
33750ba29b605a925af5aed58d3f3735422b1e25Phil Carmodyint str_to_uint64(const char *str, uint64_t *num_r) ATTR_WARN_UNUSED_RESULT;
40ac30b9267c710f5fcdd4b2f6bcd7718a631843Timo Sirainenint str_to_uintmax(const char *str, uintmax_t *num_r) ATTR_WARN_UNUSED_RESULT;
518781a0a4ba2403f23dbadda445b107fbb87daaPhil Carmodyint str_parse_uintmax(const char *str, uintmax_t *num_r, const char **endp_r) ATTR_WARN_UNUSED_RESULT ATTR_NULL(3);
8562f8de469e87ad4104747cebec6b133fa3a0f5Timo Sirainenint str_to_int(const char *str, int *num_r) ATTR_WARN_UNUSED_RESULT;
8562f8de469e87ad4104747cebec6b133fa3a0f5Timo Sirainenint str_to_long(const char *str, long *num_r) ATTR_WARN_UNUSED_RESULT;
8562f8de469e87ad4104747cebec6b133fa3a0f5Timo Sirainenint str_to_llong(const char *str, long long *num_r) ATTR_WARN_UNUSED_RESULT;
8562f8de469e87ad4104747cebec6b133fa3a0f5Timo Sirainenint str_to_intmax(const char *str, intmax_t *num_r) ATTR_WARN_UNUSED_RESULT;
de62ce819d59a529530da4b57be1b8d6dad13d6bTimo Sirainenint str_to_uid(const char *str, uid_t *num_r) ATTR_WARN_UNUSED_RESULT;
de62ce819d59a529530da4b57be1b8d6dad13d6bTimo Sirainenint str_to_gid(const char *str, gid_t *num_r) ATTR_WARN_UNUSED_RESULT;
de62ce819d59a529530da4b57be1b8d6dad13d6bTimo Sirainenint str_to_pid(const char *str, pid_t *num_r) ATTR_WARN_UNUSED_RESULT;
de62ce819d59a529530da4b57be1b8d6dad13d6bTimo Sirainenint str_to_uoff(const char *str, uoff_t *num_r) ATTR_WARN_UNUSED_RESULT;
de62ce819d59a529530da4b57be1b8d6dad13d6bTimo Sirainenint str_to_time(const char *str, time_t *num_r) ATTR_WARN_UNUSED_RESULT;
518781a0a4ba2403f23dbadda445b107fbb87daaPhil Carmody/* Returns TRUE if str is a valid unsigned number that equals to num. */
518781a0a4ba2403f23dbadda445b107fbb87daaPhil Carmodybool str_uint_equals(const char *str, uintmax_t num);
af49da69a12b5383b89c7b2fa574c2a85b9ca310Timo Sirainen/* Returns human readable string about what is wrong with the string.
af49da69a12b5383b89c7b2fa574c2a85b9ca310Timo Sirainen This function assumes that str_to_*() had already returned -1 for the