f497f9fe231e0e400f339c84a7d80c4aae2ac4d5Joshua M. Clulow/*
f497f9fe231e0e400f339c84a7d80c4aae2ac4d5Joshua M. Clulow * This file and its contents are supplied under the terms of the
f497f9fe231e0e400f339c84a7d80c4aae2ac4d5Joshua M. Clulow * Common Development and Distribution License ("CDDL"), version 1.0.
f497f9fe231e0e400f339c84a7d80c4aae2ac4d5Joshua M. Clulow * You may only use this file in accordance with the terms of version
f497f9fe231e0e400f339c84a7d80c4aae2ac4d5Joshua M. Clulow * 1.0 of the CDDL.
f497f9fe231e0e400f339c84a7d80c4aae2ac4d5Joshua M. Clulow *
f497f9fe231e0e400f339c84a7d80c4aae2ac4d5Joshua M. Clulow * A full copy of the text of the CDDL should have accompanied this
f497f9fe231e0e400f339c84a7d80c4aae2ac4d5Joshua M. Clulow * source. A copy of the CDDL is also available via the Internet at
f497f9fe231e0e400f339c84a7d80c4aae2ac4d5Joshua M. Clulow * http://www.illumos.org/license/CDDL.
f497f9fe231e0e400f339c84a7d80c4aae2ac4d5Joshua M. Clulow */
f497f9fe231e0e400f339c84a7d80c4aae2ac4d5Joshua M. Clulow
f497f9fe231e0e400f339c84a7d80c4aae2ac4d5Joshua M. Clulow/*
f497f9fe231e0e400f339c84a7d80c4aae2ac4d5Joshua M. Clulow * Copyright (c) 2012, Joyent, Inc. All rights reserved.
f497f9fe231e0e400f339c84a7d80c4aae2ac4d5Joshua M. Clulow */
f497f9fe231e0e400f339c84a7d80c4aae2ac4d5Joshua M. Clulow
f497f9fe231e0e400f339c84a7d80c4aae2ac4d5Joshua M. Clulow/*
f497f9fe231e0e400f339c84a7d80c4aae2ac4d5Joshua M. Clulow * ASSERTION:
f497f9fe231e0e400f339c84a7d80c4aae2ac4d5Joshua M. Clulow * Test the strtoll() subroutine.
f497f9fe231e0e400f339c84a7d80c4aae2ac4d5Joshua M. Clulow *
f497f9fe231e0e400f339c84a7d80c4aae2ac4d5Joshua M. Clulow * SECTION: Actions and Subroutines/strtoll()
f497f9fe231e0e400f339c84a7d80c4aae2ac4d5Joshua M. Clulow */
f497f9fe231e0e400f339c84a7d80c4aae2ac4d5Joshua M. Clulow
f497f9fe231e0e400f339c84a7d80c4aae2ac4d5Joshua M. Clulow#pragma D option quiet
f497f9fe231e0e400f339c84a7d80c4aae2ac4d5Joshua M. Clulow
f497f9fe231e0e400f339c84a7d80c4aae2ac4d5Joshua M. ClulowBEGIN
f497f9fe231e0e400f339c84a7d80c4aae2ac4d5Joshua M. Clulow{
f497f9fe231e0e400f339c84a7d80c4aae2ac4d5Joshua M. Clulow
f497f9fe231e0e400f339c84a7d80c4aae2ac4d5Joshua M. Clulow /* minimum base (2) and maximum base (36): */
f497f9fe231e0e400f339c84a7d80c4aae2ac4d5Joshua M. Clulow printf("%d\n", strtoll("0", 2));
f497f9fe231e0e400f339c84a7d80c4aae2ac4d5Joshua M. Clulow printf("%d\n", strtoll("1", 36));
f497f9fe231e0e400f339c84a7d80c4aae2ac4d5Joshua M. Clulow
f497f9fe231e0e400f339c84a7d80c4aae2ac4d5Joshua M. Clulow /* simple tests: */
f497f9fe231e0e400f339c84a7d80c4aae2ac4d5Joshua M. Clulow printf("%d\n", strtoll("0x20", 16));
f497f9fe231e0e400f339c84a7d80c4aae2ac4d5Joshua M. Clulow printf("%d\n", strtoll("-32", 10));
f497f9fe231e0e400f339c84a7d80c4aae2ac4d5Joshua M. Clulow printf("%d\n", strtoll("010", 8));
f497f9fe231e0e400f339c84a7d80c4aae2ac4d5Joshua M. Clulow printf("%d\n", strtoll("101010", 2));
f497f9fe231e0e400f339c84a7d80c4aae2ac4d5Joshua M. Clulow
f497f9fe231e0e400f339c84a7d80c4aae2ac4d5Joshua M. Clulow /* INT64_MIN and INT64_MAX: */
f497f9fe231e0e400f339c84a7d80c4aae2ac4d5Joshua M. Clulow printf("%d\n", strtoll("9223372036854775807"));
f497f9fe231e0e400f339c84a7d80c4aae2ac4d5Joshua M. Clulow printf("%d\n", strtoll("-9223372036854775808"));
f497f9fe231e0e400f339c84a7d80c4aae2ac4d5Joshua M. Clulow printf("%d\n", strtoll("0777777777777777777777", 8));
f497f9fe231e0e400f339c84a7d80c4aae2ac4d5Joshua M. Clulow printf("%d\n", strtoll("-01000000000000000000000", 8));
f497f9fe231e0e400f339c84a7d80c4aae2ac4d5Joshua M. Clulow
f497f9fe231e0e400f339c84a7d80c4aae2ac4d5Joshua M. Clulow /* wrapping: */
f497f9fe231e0e400f339c84a7d80c4aae2ac4d5Joshua M. Clulow printf("%d\n", strtoll("1000000000000000000000", 8));
f497f9fe231e0e400f339c84a7d80c4aae2ac4d5Joshua M. Clulow printf("%d\n", strtoll("-1000000000000000000001", 8));
f497f9fe231e0e400f339c84a7d80c4aae2ac4d5Joshua M. Clulow
f497f9fe231e0e400f339c84a7d80c4aae2ac4d5Joshua M. Clulow /* hex without prefix: */
f497f9fe231e0e400f339c84a7d80c4aae2ac4d5Joshua M. Clulow printf("%d\n", strtoll("baddcafe", 16));
f497f9fe231e0e400f339c84a7d80c4aae2ac4d5Joshua M. Clulow
f497f9fe231e0e400f339c84a7d80c4aae2ac4d5Joshua M. Clulow /* stopping at first out-of-base character: */
f497f9fe231e0e400f339c84a7d80c4aae2ac4d5Joshua M. Clulow printf("%d\n", strtoll("12j", 10));
f497f9fe231e0e400f339c84a7d80c4aae2ac4d5Joshua M. Clulow printf("%d\n", strtoll("102", 2));
f497f9fe231e0e400f339c84a7d80c4aae2ac4d5Joshua M. Clulow
f497f9fe231e0e400f339c84a7d80c4aae2ac4d5Joshua M. Clulow /* base 36: */
f497f9fe231e0e400f339c84a7d80c4aae2ac4d5Joshua M. Clulow printf("%d\n", strtoll("-0DTrace4EverZ", 36));
f497f9fe231e0e400f339c84a7d80c4aae2ac4d5Joshua M. Clulow
f497f9fe231e0e400f339c84a7d80c4aae2ac4d5Joshua M. Clulow /* base 10 is assumed: */
f497f9fe231e0e400f339c84a7d80c4aae2ac4d5Joshua M. Clulow printf("%d\n", strtoll("1985"));
f497f9fe231e0e400f339c84a7d80c4aae2ac4d5Joshua M. Clulow printf("%d\n", strtoll("-2012"));
f497f9fe231e0e400f339c84a7d80c4aae2ac4d5Joshua M. Clulow
f497f9fe231e0e400f339c84a7d80c4aae2ac4d5Joshua M. Clulow /* empty string: */
f497f9fe231e0e400f339c84a7d80c4aae2ac4d5Joshua M. Clulow printf("%d\n", strtoll(""));
f497f9fe231e0e400f339c84a7d80c4aae2ac4d5Joshua M. Clulow
f497f9fe231e0e400f339c84a7d80c4aae2ac4d5Joshua M. Clulow exit(0);
f497f9fe231e0e400f339c84a7d80c4aae2ac4d5Joshua M. Clulow}