| 1 | /* | 
|---|
| 2 |  * Copyright (c) 1990 The Regents of the University of California. | 
|---|
| 3 |  * All rights reserved. | 
|---|
| 4 |  * | 
|---|
| 5 |  * Redistribution and use in source and binary forms are permitted | 
|---|
| 6 |  * provided that the above copyright notice and this paragraph are | 
|---|
| 7 |  * duplicated in all such forms and that any documentation, | 
|---|
| 8 |  * advertising materials, and other materials related to such | 
|---|
| 9 |  * distribution and use acknowledge that the software was developed | 
|---|
| 10 |  * by the University of California, Berkeley.  The name of the | 
|---|
| 11 |  * University may not be used to endorse or promote products derived | 
|---|
| 12 |  * from this software without specific prior written permission. | 
|---|
| 13 |  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR | 
|---|
| 14 |  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED | 
|---|
| 15 |  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 
|---|
| 16 |  */ | 
|---|
| 17 |  | 
|---|
| 18 | /* | 
|---|
| 19 | FUNCTION | 
|---|
| 20 | <<viprintf>>, <<vfiprintf>>, <<vsiprintf>>, <<vsniprintf>>, <<vasiprintf>>, <<vasniprintf>>---format argument list (integer only) | 
|---|
| 21 |  | 
|---|
| 22 | INDEX | 
|---|
| 23 |         viprintf | 
|---|
| 24 | INDEX | 
|---|
| 25 |         _viprintf_r | 
|---|
| 26 | INDEX | 
|---|
| 27 |         vfiprintf | 
|---|
| 28 | INDEX | 
|---|
| 29 |         _vfiprintf_r | 
|---|
| 30 | INDEX | 
|---|
| 31 |         vsiprintf | 
|---|
| 32 | INDEX | 
|---|
| 33 |         _vsiprintf_r | 
|---|
| 34 | INDEX | 
|---|
| 35 |         vsniprintf | 
|---|
| 36 | INDEX | 
|---|
| 37 |         _vsniprintf_r | 
|---|
| 38 | INDEX | 
|---|
| 39 |         vasiprintf | 
|---|
| 40 | INDEX | 
|---|
| 41 |         _vasiprintf_r | 
|---|
| 42 | INDEX | 
|---|
| 43 |         vasniprintf | 
|---|
| 44 | INDEX | 
|---|
| 45 |         _vasniprintf_r | 
|---|
| 46 |  | 
|---|
| 47 | SYNOPSIS | 
|---|
| 48 |         #include <stdio.h> | 
|---|
| 49 |         #include <stdarg.h> | 
|---|
| 50 |         int viprintf(const char *<[fmt]>, va_list <[list]>); | 
|---|
| 51 |         int vfiprintf(FILE *<[fp]>, const char *<[fmt]>, va_list <[list]>); | 
|---|
| 52 |         int vsiprintf(char *<[str]>, const char *<[fmt]>, va_list <[list]>); | 
|---|
| 53 |         int vsniprintf(char *<[str]>, size_t <[size]>, const char *<[fmt]>, | 
|---|
| 54 |                        va_list <[list]>); | 
|---|
| 55 |         int vasiprintf(char **<[strp]>, const char *<[fmt]>, va_list <[list]>); | 
|---|
| 56 |         char *vasniprintf(char *<[str]>, size_t *<[size]>, const char *<[fmt]>, | 
|---|
| 57 |                           va_list <[list]>); | 
|---|
| 58 |  | 
|---|
| 59 |         int _viprintf_r(struct _reent *<[reent]>, const char *<[fmt]>, | 
|---|
| 60 |                         va_list <[list]>); | 
|---|
| 61 |         int _vfiprintf_r(struct _reent *<[reent]>, FILE *<[fp]>, | 
|---|
| 62 |                         const char *<[fmt]>, va_list <[list]>); | 
|---|
| 63 |         int _vsiprintf_r(struct _reent *<[reent]>, char *<[str]>, | 
|---|
| 64 |                         const char *<[fmt]>, va_list <[list]>); | 
|---|
| 65 |         int _vsniprintf_r(struct _reent *<[reent]>, char *<[str]>, | 
|---|
| 66 |                           size_t <[size]>, const char *<[fmt]>, va_list <[list]>); | 
|---|
| 67 |         int _vasiprintf_r(struct _reent *<[reent]>, char **<[str]>, | 
|---|
| 68 |                           const char *<[fmt]>, va_list <[list]>); | 
|---|
| 69 |         char *_vasniprintf_r(struct _reent *<[reent]>, char *<[str]>, | 
|---|
| 70 |                              size_t *<[size]>, const char *<[fmt]>, va_list <[list]>); | 
|---|
| 71 |  | 
|---|
| 72 | DESCRIPTION | 
|---|
| 73 | <<viprintf>>, <<vfiprintf>>, <<vasiprintf>>, <<vsiprintf>>, | 
|---|
| 74 | <<vsniprintf>>, and <<vasniprintf>> are (respectively) variants of | 
|---|
| 75 | <<iprintf>>, <<fiprintf>>, <<asiprintf>>, <<siprintf>>, <<sniprintf>>, | 
|---|
| 76 | and <<asniprintf>>.  They differ only in allowing their caller to pass | 
|---|
| 77 | the variable argument list as a <<va_list>> object (initialized by | 
|---|
| 78 | <<va_start>>) rather than directly accepting a variable number of | 
|---|
| 79 | arguments.  The caller is responsible for calling <<va_end>>. | 
|---|
| 80 |  | 
|---|
| 81 | <<_viprintf_r>>, <<_vfiprintf_r>>, <<_vasiprintf_r>>, | 
|---|
| 82 | <<_vsiprintf_r>>, <<_vsniprintf_r>>, and <<_vasniprintf_r>> are | 
|---|
| 83 | reentrant versions of the above. | 
|---|
| 84 |  | 
|---|
| 85 | RETURNS | 
|---|
| 86 | The return values are consistent with the corresponding functions: | 
|---|
| 87 |  | 
|---|
| 88 | PORTABILITY | 
|---|
| 89 | All of these functions are newlib extensions. | 
|---|
| 90 |  | 
|---|
| 91 | Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>, | 
|---|
| 92 | <<lseek>>, <<read>>, <<sbrk>>, <<write>>. | 
|---|
| 93 | */ | 
|---|
| 94 |  | 
|---|
| 95 | #include <_ansi.h> | 
|---|
| 96 | #include <reent.h> | 
|---|
| 97 | #include <stdio.h> | 
|---|
| 98 | #include <stdarg.h> | 
|---|
| 99 | #include "local.h" | 
|---|
| 100 |  | 
|---|
| 101 | #ifndef _REENT_ONLY | 
|---|
| 102 |  | 
|---|
| 103 | int | 
|---|
| 104 | viprintf (const char *fmt, | 
|---|
| 105 |        va_list ap) | 
|---|
| 106 | { | 
|---|
| 107 |   struct _reent *reent = _REENT; | 
|---|
| 108 |  | 
|---|
| 109 |   _REENT_SMALL_CHECK_INIT (reent); | 
|---|
| 110 |   return _vfiprintf_r (reent, _stdout_r (reent), fmt, ap); | 
|---|
| 111 | } | 
|---|
| 112 |  | 
|---|
| 113 | #endif /* !_REENT_ONLY */ | 
|---|
| 114 |  | 
|---|
| 115 | int | 
|---|
| 116 | _viprintf_r (struct _reent *ptr, | 
|---|
| 117 |        const char *fmt, | 
|---|
| 118 |        va_list ap) | 
|---|
| 119 | { | 
|---|
| 120 |   _REENT_SMALL_CHECK_INIT (ptr); | 
|---|
| 121 |   return _vfiprintf_r (ptr, _stdout_r (ptr), fmt, ap); | 
|---|
| 122 | } | 
|---|