ruby-changes:37602
From: nobu <ko1@a...>
Date: Sun, 22 Feb 2015 10:40:48 +0900 (JST)
Subject: [ruby-changes:37602] nobu:r49683 (trunk): sprintf.c: ruby specific functions
nobu 2015-02-22 10:40:40 +0900 (Sun, 22 Feb 2015) New Revision: 49683 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=49683 Log: sprintf.c: ruby specific functions * sprintf.c (ruby_vsnprintf, ruby_snprintf): move ruby specific functions from vsnprintf.c. Modified files: trunk/sprintf.c trunk/vsnprintf.c Index: vsnprintf.c =================================================================== --- vsnprintf.c (revision 49682) +++ vsnprintf.c (revision 49683) @@ -1311,43 +1311,3 @@ exponent(char *p0, int exp, int fmtch) https://github.com/ruby/ruby/blob/trunk/vsnprintf.c#L1311 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); -} Index: sprintf.c =================================================================== --- sprintf.c (revision 49682) +++ sprintf.c (revision 49683) @@ -1256,6 +1256,39 @@ fmt_setup(char *buf, size_t size, int c, https://github.com/ruby/ruby/blob/trunk/sprintf.c#L1256 #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; -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/