2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License (the "License").
2N/A * You may not use this file except in compliance with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A
2N/A/*
2N/A * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
2N/A * Use is subject to license terms.
2N/A */
2N/A
2N/A/* Copyright (c) 1988 AT&T */
2N/A/* All Rights Reserved */
2N/A
2N/A#pragma ident "%Z%%M% %I% %E% SMI"
2N/A
2N/A#include "lint.h"
2N/A#include <mtlib.h>
2N/A#include <stdarg.h>
2N/A#include <values.h>
2N/A#include <errno.h>
2N/A#include <synch.h>
2N/A#include <thread.h>
2N/A#include <sys/types.h>
2N/A#include "print.h"
2N/A#include "libc.h"
2N/A
2N/A/*
2N/A * 32-bit shadow function of vsprintf() is included here.
2N/A * When using the c89 compiler to build 32-bit applications, the size
2N/A * of intmax_t is 32-bits, otherwise the size of intmax_t is 64-bits.
2N/A * The shadow function uses 32-bit size of intmax_t for %j conversion.
2N/A * The #pragma redefine_extname in <stdio.h> selects the proper routine
2N/A * at compile time for the user application.
2N/A * NOTE: this function is only available in the 32-bit library.
2N/A */
2N/A
2N/A/*VARARGS2*/
2N/Aint
2N/A#ifdef _C89_INTMAX32
2N/A_vsprintf_c89(char *string, const char *format, va_list ap)
2N/A#else
2N/Avsprintf(char *string, const char *format, va_list ap)
2N/A#endif
2N/A{
2N/A ssize_t count;
2N/A FILE siop;
2N/A
2N/A siop._cnt = MAXINT;
2N/A siop._base = siop._ptr = (unsigned char *)string;
2N/A siop._flag = _IOREAD; /* distinguish dummy file descriptor */
2N/A#ifdef _C89_INTMAX32
2N/A count = _ndoprnt(format, ap, &siop, _F_INTMAX32);
2N/A#else
2N/A count = _ndoprnt(format, ap, &siop, 0);
2N/A#endif
2N/A *siop._ptr = '\0'; /* plant terminating null character */
2N/A
2N/A if (count == EOF) {
2N/A return (EOF);
2N/A }
2N/A /* check for overflow */
2N/A if ((size_t)count > MAXINT) {
2N/A errno = EOVERFLOW;
2N/A return (EOF);
2N/A } else {
2N/A return ((int)count);
2N/A }
2N/A}