10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*6812Sraf * Common Development and Distribution License (the "License").
6*6812Sraf * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate * See the License for the specific language governing permissions
110Sstevel@tonic-gate * and limitations under the License.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * CDDL HEADER END
200Sstevel@tonic-gate */
21*6812Sraf
220Sstevel@tonic-gate /*
23*6812Sraf * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
240Sstevel@tonic-gate * Use is subject to license terms.
250Sstevel@tonic-gate */
260Sstevel@tonic-gate
270Sstevel@tonic-gate /* Copyright (c) 1988 AT&T */
280Sstevel@tonic-gate /* All Rights Reserved */
290Sstevel@tonic-gate
30*6812Sraf #pragma ident "%Z%%M% %I% %E% SMI"
310Sstevel@tonic-gate
320Sstevel@tonic-gate /*
330Sstevel@tonic-gate * lltostr -- convert long long to decimal string
340Sstevel@tonic-gate *
350Sstevel@tonic-gate * char *
360Sstevel@tonic-gate * lltostr(value, ptr)
370Sstevel@tonic-gate * long long value;
380Sstevel@tonic-gate * char *ptr;
390Sstevel@tonic-gate *
400Sstevel@tonic-gate * Ptr is assumed to point to the byte following a storage area
410Sstevel@tonic-gate * into which the decimal representation of "value" is to be
420Sstevel@tonic-gate * placed as a string. Lltostr converts "value" to decimal and
430Sstevel@tonic-gate * produces the string, and returns a pointer to the beginning
440Sstevel@tonic-gate * of the string. No leading zeroes are produced, and no
450Sstevel@tonic-gate * terminating null is produced. The low-order digit of the
460Sstevel@tonic-gate * result always occupies memory position ptr-1.
470Sstevel@tonic-gate * Lltostr's behavior is undefined if "value" is negative. A single
480Sstevel@tonic-gate * zero digit is produced if "value" is zero.
490Sstevel@tonic-gate */
500Sstevel@tonic-gate
51*6812Sraf #pragma weak _lltostr = lltostr
52*6812Sraf #pragma weak _ulltostr = ulltostr
530Sstevel@tonic-gate
54*6812Sraf #include "lint.h"
550Sstevel@tonic-gate #include <sys/types.h>
560Sstevel@tonic-gate #include <stdlib.h>
570Sstevel@tonic-gate
580Sstevel@tonic-gate char *
lltostr(longlong_t value,char * ptr)590Sstevel@tonic-gate lltostr(longlong_t value, char *ptr)
600Sstevel@tonic-gate {
610Sstevel@tonic-gate longlong_t t;
620Sstevel@tonic-gate
630Sstevel@tonic-gate #ifdef _ILP32
640Sstevel@tonic-gate if (!(0xffffffff00000000ULL & value)) {
650Sstevel@tonic-gate ulong_t t, val = (ulong_t)value;
660Sstevel@tonic-gate
670Sstevel@tonic-gate do {
680Sstevel@tonic-gate *--ptr = (char)('0' + val - 10 * (t = val / 10));
690Sstevel@tonic-gate } while ((val = t) != 0);
700Sstevel@tonic-gate
710Sstevel@tonic-gate return (ptr);
720Sstevel@tonic-gate }
730Sstevel@tonic-gate #endif
740Sstevel@tonic-gate
750Sstevel@tonic-gate do {
760Sstevel@tonic-gate *--ptr = (char)('0' + value - 10 * (t = value / 10));
770Sstevel@tonic-gate } while ((value = t) != 0);
780Sstevel@tonic-gate
790Sstevel@tonic-gate return (ptr);
800Sstevel@tonic-gate }
810Sstevel@tonic-gate
820Sstevel@tonic-gate char *
ulltostr(u_longlong_t value,char * ptr)830Sstevel@tonic-gate ulltostr(u_longlong_t value, char *ptr)
840Sstevel@tonic-gate {
850Sstevel@tonic-gate u_longlong_t t;
860Sstevel@tonic-gate
870Sstevel@tonic-gate #ifdef _ILP32
880Sstevel@tonic-gate if (!(0xffffffff00000000ULL & value)) {
890Sstevel@tonic-gate ulong_t t, val = (ulong_t)value;
900Sstevel@tonic-gate
910Sstevel@tonic-gate do {
920Sstevel@tonic-gate *--ptr = (char)('0' + val - 10 * (t = val / 10));
930Sstevel@tonic-gate } while ((val = t) != 0);
940Sstevel@tonic-gate
950Sstevel@tonic-gate return (ptr);
960Sstevel@tonic-gate }
970Sstevel@tonic-gate #endif
980Sstevel@tonic-gate
990Sstevel@tonic-gate do {
1000Sstevel@tonic-gate *--ptr = (char)('0' + value - 10 * (t = value / 10));
1010Sstevel@tonic-gate } while ((value = t) != 0);
1020Sstevel@tonic-gate
1030Sstevel@tonic-gate return (ptr);
1040Sstevel@tonic-gate }
105