home *** CD-ROM | disk | FTP | other *** search
/ Nebula / nebula.bin / SourceCode / libcs / vprintf.c < prev    next >
C/C++ Source or Header  |  1992-05-15  |  3KB  |  123 lines

  1. /*
  2.  * Copyright (c) 1990 Carnegie Mellon University
  3.  * All Rights Reserved.
  4.  * 
  5.  * Permission to use, copy, modify and distribute this software and its
  6.  * documentation is hereby granted, provided that both the copyright
  7.  * notice and this permission notice appear in all copies of the
  8.  * software, derivative works or modified versions, and any portions
  9.  * thereof, and that both notices appear in supporting documentation.
  10.  *
  11.  * THE SOFTWARE IS PROVIDED "AS IS" AND CARNEGIE MELLON UNIVERSITY
  12.  * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
  13.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.  IN NO EVENT
  14.  * SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE FOR ANY SPECIAL, DIRECT,
  15.  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
  16.  * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
  17.  * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  18.  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  19.  *
  20.  * Users of this software agree to return to Carnegie Mellon any
  21.  * improvements or extensions that they make and grant Carnegie the
  22.  * rights to redistribute these changes.
  23.  *
  24.  * Export of this software is permitted only after complying with the
  25.  * regulations of the U.S. Deptartment of Commerce relating to the
  26.  * Export of Technical Data.
  27.  */
  28. /*
  29.  * varargs versions of printf routines
  30.  *
  31.  **********************************************************************
  32.  * HISTORY
  33.  * $Log:    vprintf.c,v $
  34.  * Revision 2.6  90/12/11  18:00:40  mja
  35.  *     Add copyright/disclaimer for distribution.
  36.  * 
  37.  * Revision 2.5  89/09/08  18:15:55  mbj
  38.  *     Use _doprnt() for the Multimax (an "old" architecture).
  39.  *     [89/09/08            mbj]
  40.  * 
  41.  * Revision 2.4  89/08/03  14:40:10  mja
  42.  *     Add vsnprintf() routine.
  43.  *     [89/07/12            mja]
  44.  * 
  45.  *     Terminate vsprintf() string with null byte.
  46.  *     [89/04/21            mja]
  47.  * 
  48.  *     Change to use new hidden name for _doprnt on MIPS.
  49.  *     [89/04/18            mja]
  50.  * 
  51.  * Revision 2.3  89/06/10  14:13:43  gm0w
  52.  *     Added putc of NULL byte to vsprintf.
  53.  *     [89/06/10            gm0w]
  54.  * 
  55.  * Revision 2.2  88/12/13  13:53:17  gm0w
  56.  *     From Brad White.
  57.  *     [88/12/13            gm0w]
  58.  * 
  59.  **********************************************************************
  60.  */
  61. #include <stdio.h>
  62. #include <varargs.h>
  63.  
  64. #if    !defined(vax) && !defined(sun3) && !defined(ibmrt) && !defined(multimax) && !defined(NeXT)
  65. /* 
  66.  *  No new architectures make _doprnt() visible.
  67.  */
  68. #define    _doprnt    _doprnt_va
  69. #endif
  70.  
  71.  
  72. int
  73. vprintf(fmt, args)
  74.     char *fmt;
  75.     va_list args;
  76. {
  77.     _doprnt(fmt, args, stdout);
  78.     return (ferror(stdout) ? EOF : 0);
  79. }
  80.  
  81. int
  82. vfprintf(f, fmt, args)
  83.     FILE *f;
  84.     char *fmt;
  85.     va_list args;
  86. {
  87.     _doprnt(fmt, args, f);
  88.     return (ferror(f) ? EOF : 0);
  89. }
  90.  
  91. int
  92. vsprintf(s, fmt, args)
  93.     char *s, *fmt;
  94.     va_list args;
  95. {
  96.     FILE fakebuf;
  97.  
  98.     fakebuf._flag = _IOSTRG;    /* no _IOWRT: avoid stdio bug */
  99.     fakebuf._ptr = s;
  100.     fakebuf._cnt = 32767;
  101.     _doprnt(fmt, args, &fakebuf);
  102.     putc('\0', &fakebuf);
  103.     return (strlen(s));
  104. }
  105.  
  106. int
  107. vsnprintf(s, n, fmt, args)
  108.     char *s, *fmt;
  109.     va_list args;
  110. {
  111.     FILE fakebuf;
  112.  
  113.     fakebuf._flag = _IOSTRG;    /* no _IOWRT: avoid stdio bug */
  114.     fakebuf._ptr = s;
  115.     fakebuf._cnt = n-1;
  116.     _doprnt(fmt, args, &fakebuf);
  117.     fakebuf._cnt++;
  118.     putc('\0', &fakebuf);
  119.     if (fakebuf._cnt<0)
  120.         fakebuf._cnt = 0;
  121.     return (n-fakebuf._cnt-1);
  122. }
  123.