aboutsummaryrefslogtreecommitdiffstats
path: root/sprintf.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-02-22 01:40:40 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-02-22 01:40:40 +0000
commit6c801fc58f39085ea5e71fc9b07e4fa52427b5e5 (patch)
treecd2b6c3543efa3b64c076a9886e61b03d7cfdd85 /sprintf.c
parentc5d781dded856a86609ebd9fd4904c3e9f3474fd (diff)
downloadruby-6c801fc58f39085ea5e71fc9b07e4fa52427b5e5.tar.gz
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
Diffstat (limited to 'sprintf.c')
-rw-r--r--sprintf.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/sprintf.c b/sprintf.c
index 376285476d..9770a00008 100644
--- a/sprintf.c
+++ b/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;