test-strtonum.c revision 279524
138032Speter/*	$Id: test-strtonum.c,v 1.1 2015/02/16 14:56:22 schwarze Exp $	*/
238032Speter/*
3261363Sgshapiro * Copyright (c) 2015 Ingo Schwarze <schwarze@openbsd.org>
464562Sgshapiro *
538032Speter * Permission to use, copy, modify, and distribute this software for any
638032Speter * purpose with or without fee is hereby granted, provided that the above
738032Speter * copyright notice and this permission notice appear in all copies.
838032Speter *
938032Speter * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
1038032Speter * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
1138032Speter * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
1238032Speter * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
1338032Speter * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
1438032Speter * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
1538032Speter * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1638032Speter */
1738032Speter
1838032Speter#include <stdlib.h>
1938032Speter
2038032Speterint
2138032Spetermain(void)
2238032Speter{
2338032Speter	const char *errstr;
2438032Speter
2590792Sgshapiro	if (strtonum("1", 0, 2, &errstr) != 1)
2638032Speter		return(1);
2738032Speter	if (errstr != NULL)
2838032Speter		return(2);
2938032Speter	if (strtonum("1x", 0, 2, &errstr) != 0)
3038032Speter		return(3);
31266692Sgshapiro	if (errstr == NULL)
3238032Speter		return(4);
3364562Sgshapiro	if (strtonum("2", 0, 1, &errstr) != 0)
3490792Sgshapiro		return(5);
3538032Speter	if (errstr == NULL)
3638032Speter		return(6);
3738032Speter	if (strtonum("0", 1, 2, &errstr) != 0)
3838032Speter		return(7);
39	if (errstr == NULL)
40		return(8);
41	return(0);
42}
43