strnum.c revision ba54c370c4c1fee3d59a90cd4986bb7859a62c52
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen/* Copyright (c) 2010 Dovecot authors, see the included COPYING file */
55a210942dc7da58b2fd0b11bed8da6b030af5c1Timo Sirainenbool str_is_numeric(const char *str, char end_char)
56f45b3f3ae20e5c933701f4657dda5ef1916855Timo Sirainenint str_to_uint(const char *str, unsigned int *num_r)
1175f27441385a7011629f295f42708f9a3a4ffcTimo Sirainen if (l > (unsigned int)-1)
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen *num_r = (unsigned int)l;
1175f27441385a7011629f295f42708f9a3a4ffcTimo Sirainenint str_to_ulong(const char *str, unsigned long *num_r)
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen if (l > (unsigned long)-1)
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen *num_r = (unsigned long)l;
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenint str_to_ullong(const char *str, unsigned long long *num_r)
d8b77aef97e89f1ccc5cbdaef77be9052279e35fTimo Sirainen if (l > (unsigned long long)-1)
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen *num_r = (unsigned long long)l;
56f45b3f3ae20e5c933701f4657dda5ef1916855Timo Sirainenint str_to_uint32(const char *str, uint32_t *num_r)
7797aa2479e99aeb71057b7a2584b2cb72e4d3f8Timo Sirainenint str_to_uint64(const char *str, uint64_t *num_r)
5a07b37a9df398b5189c14872a600384208ab74bTimo Sirainenint str_to_uintmax(const char *str, uintmax_t *num_r)
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* overflow */
93b29720c5141f787bd1861796867e4595c9d084Timo Sirainenint str_to_llong(const char *str, long long *num_r)
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen *num_r = (long long)l;
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenint str_to_intmax(const char *str, intmax_t *num_r)
str++;
if (!neg) {
if (l > INTMAX_MAX)
unsigned int result_bits;
if ((l >> result_bits) != 0)
uintmax_t l;
uintmax_t l;
uintmax_t l;
uintmax_t l;
uintmax_t l;
return FALSE;
return l == num;