summaryrefslogtreecommitdiff
path: root/missing/vsnprintf.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-07-23 01:02:18 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-07-23 01:02:18 +0000
commit6524f34a2688436249d111a3456a097c7111722c (patch)
treef9c83bf95a7873e01e38ff396a8bc5490b61162c /missing/vsnprintf.c
parente6a02b93747266925fd536a30715352bf2c60c07 (diff)
* sprintf.c (rb_vsprintf, rb_sprintf): new functions return new String,
using missing/vsnprintf.c. [ruby-dev:26580] * missing/vsnprintf.c: made the output changeable. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8825 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'missing/vsnprintf.c')
-rw-r--r--missing/vsnprintf.c28
1 files changed, 16 insertions, 12 deletions
diff --git a/missing/vsnprintf.c b/missing/vsnprintf.c
index e3362a91f9..1fcbb36bfd 100644
--- a/missing/vsnprintf.c
+++ b/missing/vsnprintf.c
@@ -65,8 +65,14 @@
#define u_short unsigned short
#define u_int unsigned int
-#undef __P
+#if !defined(HAVE_STDARG_PROTOTYPES)
#if defined(__STDC__)
+#define HAVE_STDARG_PROTOTYPES 1
+#endif
+#endif
+
+#undef __P
+#if defined(HAVE_STDARG_PROTOTYPES)
# include <stdarg.h>
# if !defined(__P)
# define __P(x) x
@@ -151,12 +157,15 @@ struct __sbuf {
*/
typedef struct __sFILE {
unsigned char *_p; /* current position in (some) buffer */
+#if 0
int _r; /* read space left for getc() */
+#endif
int _w; /* write space left for putc() */
short _flags; /* flags, below; this FILE is free if 0 */
short _file; /* fileno, if Unix descriptor, else -1 */
struct __sbuf _bf; /* the buffer (at least 1 byte, if !NULL) */
int _lbfsize; /* 0 or -_bf._size, for inline putc */
+ int (*vwrite)(/* struct __sFILE*, struct __suio * */);
} FILE;
@@ -673,10 +682,9 @@ reswitch: switch (ch) {
uqval = -uqval;
sign = '-';
}
- } else {
-#else /* _HAVE_SANE_QUAD_ */
- {
+ } else
#endif /* _HAVE_SANE_QUAD_ */
+ {
ulval = SARG();
if ((long)ulval < 0) {
ulval = -ulval;
@@ -1083,6 +1091,7 @@ vsnprintf(str, n, fmt, ap)
f._flags = __SWR | __SSTR;
f._bf._base = f._p = (unsigned char *)str;
f._bf._size = f._w = n - 1;
+ f.vwrite = BSD__sfvwrite;
ret = BSD_vfprintf(&f, fmt, ap);
*f._p = 0;
return (ret);
@@ -1092,14 +1101,8 @@ vsnprintf(str, n, fmt, ap)
static char sccsid[] = "@(#)snprintf.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
-#if defined(__STDC__)
-# include <stdarg.h>
-#else
-# include <varargs.h>
-#endif
-
int
-#if defined(__STDC__)
+#if defined(HAVE_STDARG_PROTOTYPES)
snprintf(char *str, size_t n, char const *fmt, ...)
#else
snprintf(str, n, fmt, va_alist)
@@ -1115,7 +1118,7 @@ va_dcl
if ((int)n < 1)
return (EOF);
-#if defined(__STDC__)
+#if defined(HAVE_STDARG_PROTOTYPES)
va_start(ap, fmt);
#else
va_start(ap);
@@ -1123,6 +1126,7 @@ va_dcl
f._flags = __SWR | __SSTR;
f._bf._base = f._p = (unsigned char *)str;
f._bf._size = f._w = n - 1;
+ f.vwrite = BSD__sfvwrite;
ret = BSD_vfprintf(&f, fmt, ap);
*f._p = 0;
va_end(ap);