strnum.c revision 7943dd081e6e3a856e6ccc56f11f17c983afbb9d
/* Copyright (c) 2010-2014 Dovecot authors, see the included COPYING file */
#include "lib.h"
#include "strnum.h"
{
return FALSE;
return FALSE;
str++;
}
return TRUE;
}
{
uintmax_t l;
if (str_to_uintmax(str, &l) < 0)
return -1;
if (l > UINT_MAX)
return -1;
*num_r = (unsigned int)l;
return 0;
}
{
uintmax_t l;
if (str_to_uintmax(str, &l) < 0)
return -1;
if (l > (unsigned long)-1)
return -1;
*num_r = (unsigned long)l;
return 0;
}
{
uintmax_t l;
if (str_to_uintmax(str, &l) < 0)
return -1;
if (l > (unsigned long long)-1)
return -1;
*num_r = (unsigned long long)l;
return 0;
}
{
uintmax_t l;
if (str_to_uintmax(str, &l) < 0)
return -1;
if (l > (uint32_t)-1)
return -1;
return 0;
}
{
uintmax_t l;
if (str_to_uintmax(str, &l) < 0)
return -1;
if (l > (uint64_t)-1)
return -1;
return 0;
}
{
uintmax_t n = 0;
return -1;
return -1;
return -1;
}
}
*num_r = n;
return 0;
}
{
const char *endp;
ret = -1;
return ret;
}
{ \
uintmax_t l; \
return -1; \
*num_r = l; \
return 0; \
}
STR_TO_U__TEMPLATE(str_parse_uint, unsigned int)
{
intmax_t l;
if (str_to_intmax(str, &l) < 0)
return -1;
return -1;
*num_r = (int)l;
return 0;
}
{
intmax_t l;
if (str_to_intmax(str, &l) < 0)
return -1;
return -1;
*num_r = (long)l;
return 0;
}
{
intmax_t l;
if (str_to_intmax(str, &l) < 0)
return -1;
return -1;
*num_r = (long long)l;
return 0;
}
{
uintmax_t l;
if (*str == '-') {
str++;
}
if (str_to_uintmax(str, &l) < 0)
return -1;
if (!neg) {
if (l > INTMAX_MAX)
return -1;
} else {
return -1;
}
return 0;
}
{
unsigned int result_bits;
/* we assume that result is a signed type,
but that it can never be negative */
if ((l >> result_bits) != 0)
return -1;
return 0;
}
{
uintmax_t l;
if (str_to_uintmax(str, &l) < 0)
return -1;
if (verify_xid(l, sizeof(*num_r)) < 0)
return -1;
return 0;
}
{
uintmax_t l;
if (str_to_uintmax(str, &l) < 0)
return -1;
/* OS X uses negative GIDs */
#ifndef __APPLE__
if (verify_xid(l, sizeof(*num_r)) < 0)
return -1;
#endif
return 0;
}
{
uintmax_t l;
if (str_to_uintmax(str, &l) < 0)
return -1;
if (verify_xid(l, sizeof(*num_r)) < 0)
return -1;
return 0;
}
{
uintmax_t l;
if (str_to_uintmax(str, &l) < 0)
return -1;
if (l > (uoff_t)-1)
return -1;
return 0;
}
{
intmax_t l;
if (str_to_intmax(str, &l) < 0)
return -1;
return 0;
}
{
uintmax_t l;
if (str_to_uintmax(str, &l) < 0)
return FALSE;
return l == num;
}
const char *str_num_error(const char *str)
{
if (*str == '-') {
return "Not a valid number";
return "Number too small";
} else {
return "Not a valid number";
return "Number too large";
}
}