зеркало из https://github.com/github/ruby.git
sprintf.c: ruby specific functions
* sprintf.c (ruby_vsnprintf, ruby_snprintf): move ruby specific functions from vsnprintf.c. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49683 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
c5d781dded
Коммит
6c801fc58f
33
sprintf.c
33
sprintf.c
|
@ -1256,6 +1256,39 @@ fmt_setup(char *buf, size_t size, int c, int flags, int width, int prec)
|
|||
#define upper_hexdigits (ruby_hexdigits+16)
|
||||
#include "vsnprintf.c"
|
||||
|
||||
int
|
||||
ruby_vsnprintf(char *str, size_t n, const char *fmt, va_list ap)
|
||||
{
|
||||
int ret;
|
||||
rb_printf_buffer f;
|
||||
|
||||
if ((int)n < 1)
|
||||
return (EOF);
|
||||
f._flags = __SWR | __SSTR;
|
||||
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;
|
||||
}
|
||||
|
||||
int
|
||||
ruby_snprintf(char *str, size_t n, char const *fmt, ...)
|
||||
{
|
||||
int ret;
|
||||
va_list ap;
|
||||
|
||||
if ((int)n < 1)
|
||||
return (EOF);
|
||||
|
||||
va_start(ap, fmt);
|
||||
ret = ruby_vsnprintf(str, n, fmt, ap);
|
||||
va_end(ap);
|
||||
return ret;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
rb_printf_buffer base;
|
||||
volatile VALUE value;
|
||||
|
|
40
vsnprintf.c
40
vsnprintf.c
|
@ -1311,43 +1311,3 @@ exponent(char *p0, int exp, int fmtch)
|
|||
return (int)(p - p0);
|
||||
}
|
||||
#endif /* FLOATING_POINT */
|
||||
|
||||
int
|
||||
ruby_vsnprintf(char *str, size_t n, const char *fmt, va_list ap)
|
||||
{
|
||||
int ret;
|
||||
FILE f;
|
||||
|
||||
if ((int)n < 1)
|
||||
return (EOF);
|
||||
f._flags = __SWR | __SSTR;
|
||||
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);
|
||||
}
|
||||
|
||||
int
|
||||
ruby_snprintf(char *str, size_t n, char const *fmt, ...)
|
||||
{
|
||||
int ret;
|
||||
va_list ap;
|
||||
FILE f;
|
||||
|
||||
if ((int)n < 1)
|
||||
return (EOF);
|
||||
|
||||
va_start(ap, fmt);
|
||||
f._flags = __SWR | __SSTR;
|
||||
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);
|
||||
return (ret);
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче