aboutsummaryrefslogtreecommitdiffstats
path: root/vsnprintf.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-05-24 14:36:54 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-05-24 14:36:54 +0000
commitce8e2d54049ddbe4947ed90295b1b4d11ebaaa52 (patch)
treeb06c84e6da75e1a9821f6decc192299e5be8101c /vsnprintf.c
parent60e8cd2e686efd3a965cb43ae5963ce31fc90d71 (diff)
downloadruby-ce8e2d54049ddbe4947ed90295b1b4d11ebaaa52.tar.gz
Feature #5896
* vsnprintf.c (BSD_vfprintf): [EXPERIMENTAL] object representation in rb_enc_vsprintf(). [Feature #5896] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35776 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'vsnprintf.c')
-rw-r--r--vsnprintf.c33
1 files changed, 32 insertions, 1 deletions
diff --git a/vsnprintf.c b/vsnprintf.c
index 5df4ffae6d..bb6a0e139a 100644
--- a/vsnprintf.c
+++ b/vsnprintf.c
@@ -183,6 +183,7 @@ typedef struct __sFILE {
struct __sbuf _bf; /* the buffer (at least 1 byte, if !NULL) */
size_t _lbfsize; /* 0 or -_bf._size, for inline putc */
int (*vwrite)(/* struct __sFILE*, struct __suio * */);
+ char *(*vextra)(/* struct __sFILE*, size_t, void*, long* */);
} FILE;
@@ -793,11 +794,39 @@ reswitch: switch (ch) {
size = 1;
sign = '\0';
break;
+ case 'i':
+#ifdef _HAVE_SANE_QUAD_
+# define INTPTR_MASK (QUADINT|LONGINT|SHORTINT)
+#else
+# define INTPTR_MASK (LONGINT|SHORTINT)
+#endif
+#if defined _HAVE_SANE_QUAD_ && SIZEOF_VOIDP == SIZEOF_LONG_LONG
+# define INTPTR_FLAG QUADINT
+#elif SIZEOF_VOIDP == SIZEOF_LONG
+# define INTPTR_FLAG LONGINT
+#else
+# define INTPTR_FLAG 0
+#endif
+ if (fp->vextra && (flags & INTPTR_MASK) == INTPTR_FLAG) {
+ FLUSH();
+#if defined _HAVE_SANE_QUAD_ && SIZEOF_VOIDP == SIZEOF_LONG_LONG
+ uqval = va_arg(ap, u_quad_t);
+ cp = (*fp->vextra)(fp, sizeof(uqval), &uqval, &fieldsz);
+#else
+ ulval = va_arg(ap, u_long);
+ cp = (*fp->vextra)(fp, sizeof(ulval), &ulval, &fieldsz);
+#endif
+ if (!cp) goto error;
+ if (prec < 0) goto long_len;
+ size = fieldsz < prec ? (int)fieldsz : prec;
+ break;
+ }
+ goto decimal;
case 'D':
flags |= LONGINT;
/*FALLTHROUGH*/
case 'd':
- case 'i':
+ decimal:
#ifdef _HAVE_SANE_QUAD_
if (flags & QUADINT) {
uqval = va_arg(ap, quad_t);
@@ -1269,6 +1298,7 @@ ruby_vsnprintf(char *str, size_t n, const char *fmt, va_list ap)
f._bf._base = f._p = (unsigned char *)str;
f._bf._size = f._w = n - 1;
f.vwrite = BSD__sfvwrite;
+ f.vextra = 0;
ret = (int)BSD_vfprintf(&f, fmt, ap);
*f._p = 0;
return (ret);
@@ -1289,6 +1319,7 @@ ruby_snprintf(char *str, size_t n, char const *fmt, ...)
f._bf._base = f._p = (unsigned char *)str;
f._bf._size = f._w = n - 1;
f.vwrite = BSD__sfvwrite;
+ f.vextra = 0;
ret = (int)BSD_vfprintf(&f, fmt, ap);
*f._p = 0;
va_end(ap);