home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright (c) 1990 Carnegie Mellon University
- * All Rights Reserved.
- *
- * Permission to use, copy, modify and distribute this software and its
- * documentation is hereby granted, provided that both the copyright
- * notice and this permission notice appear in all copies of the
- * software, derivative works or modified versions, and any portions
- * thereof, and that both notices appear in supporting documentation.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND CARNEGIE MELLON UNIVERSITY
- * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT
- * SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE FOR ANY SPECIAL, DIRECT,
- * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
- * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
- * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
- * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- *
- * Users of this software agree to return to Carnegie Mellon any
- * improvements or extensions that they make and grant Carnegie the
- * rights to redistribute these changes.
- *
- * Export of this software is permitted only after complying with the
- * regulations of the U.S. Deptartment of Commerce relating to the
- * Export of Technical Data.
- */
- /*
- * varargs versions of printf routines
- *
- **********************************************************************
- * HISTORY
- * $Log: vprintf.c,v $
- * Revision 2.6 90/12/11 18:00:40 mja
- * Add copyright/disclaimer for distribution.
- *
- * Revision 2.5 89/09/08 18:15:55 mbj
- * Use _doprnt() for the Multimax (an "old" architecture).
- * [89/09/08 mbj]
- *
- * Revision 2.4 89/08/03 14:40:10 mja
- * Add vsnprintf() routine.
- * [89/07/12 mja]
- *
- * Terminate vsprintf() string with null byte.
- * [89/04/21 mja]
- *
- * Change to use new hidden name for _doprnt on MIPS.
- * [89/04/18 mja]
- *
- * Revision 2.3 89/06/10 14:13:43 gm0w
- * Added putc of NULL byte to vsprintf.
- * [89/06/10 gm0w]
- *
- * Revision 2.2 88/12/13 13:53:17 gm0w
- * From Brad White.
- * [88/12/13 gm0w]
- *
- **********************************************************************
- */
- #include <stdio.h>
- #include <varargs.h>
-
- #if !defined(vax) && !defined(sun3) && !defined(ibmrt) && !defined(multimax) && !defined(NeXT)
- /*
- * No new architectures make _doprnt() visible.
- */
- #define _doprnt _doprnt_va
- #endif
-
-
- int
- vprintf(fmt, args)
- char *fmt;
- va_list args;
- {
- _doprnt(fmt, args, stdout);
- return (ferror(stdout) ? EOF : 0);
- }
-
- int
- vfprintf(f, fmt, args)
- FILE *f;
- char *fmt;
- va_list args;
- {
- _doprnt(fmt, args, f);
- return (ferror(f) ? EOF : 0);
- }
-
- int
- vsprintf(s, fmt, args)
- char *s, *fmt;
- va_list args;
- {
- FILE fakebuf;
-
- fakebuf._flag = _IOSTRG; /* no _IOWRT: avoid stdio bug */
- fakebuf._ptr = s;
- fakebuf._cnt = 32767;
- _doprnt(fmt, args, &fakebuf);
- putc('\0', &fakebuf);
- return (strlen(s));
- }
-
- int
- vsnprintf(s, n, fmt, args)
- char *s, *fmt;
- va_list args;
- {
- FILE fakebuf;
-
- fakebuf._flag = _IOSTRG; /* no _IOWRT: avoid stdio bug */
- fakebuf._ptr = s;
- fakebuf._cnt = n-1;
- _doprnt(fmt, args, &fakebuf);
- fakebuf._cnt++;
- putc('\0', &fakebuf);
- if (fakebuf._cnt<0)
- fakebuf._cnt = 0;
- return (n-fakebuf._cnt-1);
- }
-