strnum.c revision 076f8c12cfa4c8d30695f94f389c670d89e200fa
02c335c23bf5fa225a467c19f2c063fb0dc7b8c3Timo Sirainen/* Copyright (c) 2010-2011 Dovecot authors, see the included COPYING file */
854b4074ac77a138b3983d72510b4d8779d15040Timo Sirainenbool str_is_numeric(const char *str, char end_char)
854b4074ac77a138b3983d72510b4d8779d15040Timo Sirainenint str_to_uint(const char *str, unsigned int *num_r)
854b4074ac77a138b3983d72510b4d8779d15040Timo Sirainen if (l > (unsigned int)-1)
854b4074ac77a138b3983d72510b4d8779d15040Timo Sirainen *num_r = (unsigned int)l;
854b4074ac77a138b3983d72510b4d8779d15040Timo Sirainenint str_to_ulong(const char *str, unsigned long *num_r)
854b4074ac77a138b3983d72510b4d8779d15040Timo Sirainen if (l > (unsigned long)-1)
854b4074ac77a138b3983d72510b4d8779d15040Timo Sirainen *num_r = (unsigned long)l;
29cda2d6eb57b7fb65a55115ea8bcb6ab6938477Timo Sirainenint str_to_ullong(const char *str, unsigned long long *num_r)
854b4074ac77a138b3983d72510b4d8779d15040Timo Sirainen if (l > (unsigned long long)-1)
854b4074ac77a138b3983d72510b4d8779d15040Timo Sirainen *num_r = (unsigned long long)l;
854b4074ac77a138b3983d72510b4d8779d15040Timo Sirainenint str_to_uint32(const char *str, uint32_t *num_r)
854b4074ac77a138b3983d72510b4d8779d15040Timo Sirainenint str_to_uint64(const char *str, uint64_t *num_r)
29cda2d6eb57b7fb65a55115ea8bcb6ab6938477Timo Sirainenint str_to_uintmax(const char *str, uintmax_t *num_r)
854b4074ac77a138b3983d72510b4d8779d15040Timo Sirainen /* overflow */
decdff03c32cb5d0e99d71c5678fd008714de70bTimo Sirainenint str_to_llong(const char *str, long long *num_r)
854b4074ac77a138b3983d72510b4d8779d15040Timo Sirainen *num_r = (long long)l;
uintmax_t l;
str++;
if (!neg) {
if (l > INTMAX_MAX)
unsigned int result_bits;
if ((l >> result_bits) != 0)
uintmax_t l;
uintmax_t l;
#ifndef __APPLE__
uintmax_t l;
uintmax_t l;
intmax_t l;
uintmax_t l;
return FALSE;
return l == num;