From b919cb1d9359121eef893afd1b8af710ed2384bd Mon Sep 17 00:00:00 2001 From: naruse Date: Sun, 4 Apr 2010 01:10:53 +0000 Subject: [PATCH] * include/ruby/ruby.h: replace snprintf and vsnprintf by ruby_snprintf and ruby_vsnprintf. [ruby-dev:40909] * configure.in: don't check snprintf(3) and vsnprintf(3). * include/ruby/missing.h: don't delare snprintf and vsnprintf. * include/ruby/ruby.h: include stdarg.h. * sprintf.c: include vsnprintf.c * vsnprintf.c: renamed from missing/vsnprintf.c. * vsnprintf.c: remove useless ifdefs. * win32/mkexports.rb: use ruby_snprintf and ruby_vsnprintf. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27214 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 19 +++++++++++++++++++ configure.in | 5 +---- include/ruby/missing.h | 16 ---------------- include/ruby/ruby.h | 8 ++++++++ sprintf.c | 3 +-- missing/vsnprintf.c => vsnprintf.c | 29 ++--------------------------- win32/mkexports.rb | 4 ++-- 7 files changed, 33 insertions(+), 51 deletions(-) rename missing/vsnprintf.c => vsnprintf.c (98%) diff --git a/ChangeLog b/ChangeLog index 1c35bfe6d7..64588f6b06 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,22 @@ +Sun Apr 4 10:04:28 2010 NARUSE, Yui + + * include/ruby/ruby.h: replace snprintf and vsnprintf by + ruby_snprintf and ruby_vsnprintf. [ruby-dev:40909] + + * configure.in: don't check snprintf(3) and vsnprintf(3). + + * include/ruby/missing.h: don't delare snprintf and vsnprintf. + + * include/ruby/ruby.h: include stdarg.h. + + * sprintf.c: include vsnprintf.c + + * vsnprintf.c: renamed from missing/vsnprintf.c. + + * vsnprintf.c: remove useless ifdefs. + + * win32/mkexports.rb: use ruby_snprintf and ruby_vsnprintf. + Sun Apr 4 09:44:01 2010 Tanaka Akira * time.c (lt): call <=> instead of <. diff --git a/configure.in b/configure.in index d195f7521a..5047e9e054 100644 --- a/configure.in +++ b/configure.in @@ -888,8 +888,6 @@ main() ac_cv_func_times=yes ac_cv_func_waitpid=yes ac_cv_func_fsync=yes - ac_cv_func_snprintf=no - ac_cv_func_vsnprintf=no ac_cv_func_seekdir=yes ac_cv_func_telldir=yes ac_cv_func_isinf=yes @@ -1116,7 +1114,6 @@ main() rb_cv_broken_glibc_ia64_erfc=no)]) AS_CASE([$rb_cv_broken_glibc_ia64_erfc],[yes],[ac_cv_func_erf=no]) -AS_CASE(["$target_os"],[mingw*],[],[AC_REPLACE_FUNCS(vsnprintf)]) AC_REPLACE_FUNCS(dup2 memmove strerror\ strchr strstr crypt flock\ isnan finite isinf hypot acosh erf tgamma lgamma_r cbrt signbit \ @@ -1128,7 +1125,7 @@ AC_CHECK_FUNCS(fmod killpg wait4 waitpid fork spawnv syscall chroot getcwd eacce setrgid setegid setregid setresgid issetugid pause lchown lchmod\ getpgrp setpgrp getpgid setpgid initgroups getgroups setgroups\ getpriority getrlimit setrlimit sysconf \ - dlopen sigprocmask sigaction sigsetjmp _setjmp _longjmp snprintf\ + dlopen sigprocmask sigaction sigsetjmp _setjmp _longjmp\ setsid telldir seekdir fchmod cosh sinh tanh log2 round\ setuid setgid daemon select_large_fdset setenv unsetenv\ mktime timegm gmtime_r clock_gettime gettimeofday\ diff --git a/include/ruby/missing.h b/include/ruby/missing.h index 4a90032632..e4ac07018f 100644 --- a/include/ruby/missing.h +++ b/include/ruby/missing.h @@ -151,22 +151,6 @@ RUBY_EXTERN long strtol(const char *, char **, int); #endif */ -#if defined HAVE_VSNPRINTF || defined HAVE_SNPRINTF -# include -#endif -#ifndef HAVE_SNPRINTF -RUBY_EXTERN int snprintf(char *, size_t n, char const *, ...); -#endif -#ifndef HAVE_VSNPRINTF -# if _MSC_VER >= 1300 -# pragma warning(disable: 4273) -# endif -RUBY_EXTERN int vsnprintf(char *, size_t n, char const *, va_list); -# if _MSC_VER >= 1300 -# pragma warning(default: 4273) -# endif -#endif - #ifndef HAVE_STRLCPY RUBY_EXTERN size_t strlcpy(char *, const char*, size_t); #endif diff --git a/include/ruby/ruby.h b/include/ruby/ruby.h index 5c00c8d155..20f45aee4e 100644 --- a/include/ruby/ruby.h +++ b/include/ruby/ruby.h @@ -67,6 +67,7 @@ extern "C" { # include #endif +#include #include #include @@ -1403,6 +1404,13 @@ unsigned long ruby_strtoul(const char *str, char **endptr, int base); #define InitVM(ext) {void InitVM_##ext(void);InitVM_##ext();} +int ruby_snprintf(char *str, size_t n, char const *fmt, ...); +int ruby_vsnprintf(char *str, size_t n, char const *fmt, va_list ap); +#undef snprintf +#undef vsnprintf +#define snprintf ruby_snprintf +#define vsnprintf ruby_vsnprintf + #if defined(__cplusplus) #if 0 { /* satisfy cc-mode */ diff --git a/sprintf.c b/sprintf.c index e26b833598..1fa49e734c 100644 --- a/sprintf.c +++ b/sprintf.c @@ -1113,10 +1113,9 @@ fmt_setup(char *buf, size_t size, int c, int flags, int width, int prec) # define u_quad_t unsigned LONG_LONG # endif #endif -#undef snprintf #define FLOATING_POINT 1 #define BSD__dtoa ruby_dtoa -#include "missing/vsnprintf.c" +#include "vsnprintf.c" static int ruby__sfvwrite(register rb_printf_buffer *fp, register struct __suio *uio) diff --git a/missing/vsnprintf.c b/vsnprintf.c similarity index 98% rename from missing/vsnprintf.c rename to vsnprintf.c index acb09c9454..6385aa1aa7 100644 --- a/missing/vsnprintf.c +++ b/vsnprintf.c @@ -230,7 +230,6 @@ struct __suio { size_t uio_resid; }; -#if !defined(HAVE_VSNPRINTF) || !defined(HAVE_SNPRINTF) /* * Write some memory regions. Return zero on success, EOF on error. * @@ -305,7 +304,6 @@ static int BSD__sfvwrite(fp, uio) } return (0); } -#endif /* * Actual printf innards. @@ -1219,13 +1217,8 @@ exponent(p0, exp, fmtch) } #endif /* FLOATING_POINT */ -#ifndef HAVE_VSNPRINTF int -vsnprintf(str, n, fmt, ap) - char *str; - size_t n; - const char *fmt; - _BSD_VA_LIST_ ap; +ruby_vsnprintf(char *str, size_t n, const char *fmt, va_list ap) { int ret; FILE f; @@ -1240,22 +1233,9 @@ vsnprintf(str, n, fmt, ap) *f._p = 0; return (ret); } -#endif -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)snprintf.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ - -#ifndef HAVE_SNPRINTF int -#if defined(HAVE_STDARG_PROTOTYPES) -snprintf(char *str, size_t n, char const *fmt, ...) -#else -snprintf(str, n, fmt, va_alist) -char *str, *fmt; -size_t n; -va_dcl -#endif +ruby_snprintf(char *str, size_t n, char const *fmt, ...) { int ret; va_list ap; @@ -1264,11 +1244,7 @@ va_dcl if ((int)n < 1) return (EOF); -#if defined(HAVE_STDARG_PROTOTYPES) va_start(ap, fmt); -#else - va_start(ap); -#endif f._flags = __SWR | __SSTR; f._bf._base = f._p = (unsigned char *)str; f._bf._size = f._w = n - 1; @@ -1278,4 +1254,3 @@ va_dcl va_end(ap); return (ret); } -#endif diff --git a/win32/mkexports.rb b/win32/mkexports.rb index 951429e35a..2fac64bea3 100755 --- a/win32/mkexports.rb +++ b/win32/mkexports.rb @@ -51,8 +51,8 @@ class Exports end end syms["NtInitialize"] ||= "ruby_sysinit" if syms["ruby_sysinit"] - syms["rb_w32_vsnprintf"] ||= "vsnprintf" - syms["rb_w32_snprintf"] ||= "snprintf" + syms["rb_w32_vsnprintf"] ||= "ruby_vsnprintf" + syms["rb_w32_snprintf"] ||= "ruby_snprintf" @syms = syms end