| 1 | /* |
| 2 | Copyright (C) 1990 Free Software Foundation |
| 3 | written by Doug Lea (dl@rocky.oswego.edu) |
| 4 | |
| 5 | This file is part of GNU CC. |
| 6 | |
| 7 | GNU CC is distributed in the hope that it will be useful, |
| 8 | but WITHOUT ANY WARRANTY. No author or distributor |
| 9 | accepts responsibility to anyone for the consequences of using it |
| 10 | or for whether it serves any particular purpose or works at all, |
| 11 | unless he says so in writing. Refer to the GNU CC General Public |
| 12 | License for full details. |
| 13 | |
| 14 | Everyone is granted permission to copy, modify and redistribute |
| 15 | GNU CC, but only under the conditions described in the |
| 16 | GNU CC General Public License. A copy of this license is |
| 17 | supposed to have been given to you along with GNU CC so you |
| 18 | can know your rights and responsibilities. It should be in a |
| 19 | file named COPYING. Among other things, the copyright notice |
| 20 | and this notice must be preserved on all copies. |
| 21 | */ |
| 22 | |
| 23 | #ifdef __GNUG__ |
| 24 | #pragma implementation |
| 25 | #endif |
| 26 | #include <builtin.h> |
| 27 | #include <stdio.h> |
| 28 | #include <stdarg.h> |
| 29 | #include <AllocRing.h> |
| 30 | |
| 31 | extern AllocRing _libgxx_fmtq; |
| 32 | |
| 33 | char* form(const char* fmt ...) |
| 34 | { |
| 35 | va_list args; |
| 36 | va_start(args, fmt); |
| 37 | char* fmtbase = (char *) _libgxx_fmtq.alloc(BUFSIZ); |
| 38 | #ifndef HAVE_VPRINTF |
| 39 | FILE b; |
| 40 | #ifdef VMS |
| 41 | b->_flag = _IOWRT|_IOSTRG; |
| 42 | b->_ptr = fmtbase; |
| 43 | b->_cnt = BUFSIZ-1; |
| 44 | #else |
| 45 | b._flag = _IOWRT|_IOSTRG; |
| 46 | b._ptr = fmtbase; |
| 47 | b._cnt = BUFSIZ-1; |
| 48 | #endif |
| 49 | _doprnt(fmt, args, &b); |
| 50 | putc('\0', &b); |
| 51 | #else |
| 52 | vsprintf(fmtbase, fmt, args); |
| 53 | #endif |
| 54 | va_end(args); |
| 55 | return fmtbase; |
| 56 | } |