mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
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
This commit is contained in:
parent
60e8cd2e68
commit
ce8e2d5404
6 changed files with 88 additions and 10 deletions
33
vsnprintf.c
33
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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue