From 0d40bf8ffec9c9431194ccb8f7c4dfc39446181e Mon Sep 17 00:00:00 2001 From: nobu Date: Mon, 27 Mar 2017 13:15:48 +0000 Subject: [PATCH] error.c: warning functions * error.c: define warning functions in all combinations of * no errno, system errno, argument * without/with encoding * enabled/disabled by default git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58150 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- error.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ internal.h | 8 +++++++ 2 files changed, 78 insertions(+) diff --git a/error.c b/error.c index f980f67b01..a2f780e5b2 100644 --- a/error.c +++ b/error.c @@ -2388,6 +2388,52 @@ syserr_warning(VALUE mesg, int err) rb_write_warning_str(mesg); } +#if 0 +void +rb_sys_warn(const char *fmt, ...) +{ + if (!NIL_P(ruby_verbose)) { + int errno_save = errno; + with_warning_string(mesg, 0, fmt) { + syserr_warning(mesg, errno_save); + } + errno = errno_save; + } +} + +void +rb_syserr_warn(int err, const char *fmt, ...) +{ + if (!NIL_P(ruby_verbose)) { + with_warning_string(mesg, 0, fmt) { + syserr_warning(mesg, err); + } + } +} + +void +rb_sys_enc_warn(rb_encoding *enc, const char *fmt, ...) +{ + if (!NIL_P(ruby_verbose)) { + int errno_save = errno; + with_warning_string(mesg, enc, fmt) { + syserr_warning(mesg, errno_save); + } + errno = errno_save; + } +} + +void +rb_syserr_enc_warn(int err, rb_encoding *enc, const char *fmt, ...) +{ + if (!NIL_P(ruby_verbose)) { + with_warning_string(mesg, enc, fmt) { + syserr_warning(mesg, err); + } + } +} +#endif + void rb_sys_warning(const char *fmt, ...) { @@ -2400,6 +2446,18 @@ rb_sys_warning(const char *fmt, ...) } } +#if 0 +void +rb_syserr_warning(int err, const char *fmt, ...) +{ + if (RTEST(ruby_verbose)) { + with_warning_string(mesg, 0, fmt) { + syserr_warning(mesg, err); + } + } +} +#endif + void rb_sys_enc_warning(rb_encoding *enc, const char *fmt, ...) { @@ -2412,6 +2470,18 @@ rb_sys_enc_warning(rb_encoding *enc, const char *fmt, ...) } } +#if 0 +void +rb_syserr_enc_warning(int err, rb_encoding *enc, const char *fmt, ...) +{ + if (RTEST(ruby_verbose)) { + with_warning_string(mesg, enc, fmt) { + syserr_warning(mesg, err); + } + } +} +#endif + void rb_load_fail(VALUE path, const char *err) { diff --git a/internal.h b/internal.h index 9537411ab4..e3d5dd8fb7 100644 --- a/internal.h +++ b/internal.h @@ -1100,9 +1100,17 @@ VALUE rb_check_backtrace(VALUE); NORETURN(void rb_async_bug_errno(const char *,int)); const char *rb_builtin_type_name(int t); const char *rb_builtin_class_name(VALUE x); +PRINTF_ARGS(void rb_sys_warn(const char *fmt, ...), 1, 2); +PRINTF_ARGS(void rb_syserr_warn(int err, const char *fmt, ...), 2, 3); PRINTF_ARGS(void rb_enc_warn(rb_encoding *enc, const char *fmt, ...), 2, 3); +PRINTF_ARGS(void rb_sys_enc_warn(rb_encoding *enc, const char *fmt, ...), 2, 3); +PRINTF_ARGS(void rb_syserr_enc_warn(int err, rb_encoding *enc, const char *fmt, ...), 3, 4); +PRINTF_ARGS(void rb_sys_warning(const char *fmt, ...), 1, 2); +PRINTF_ARGS(void rb_syserr_warning(int err, const char *fmt, ...), 2, 3); PRINTF_ARGS(void rb_enc_warning(rb_encoding *enc, const char *fmt, ...), 2, 3); PRINTF_ARGS(void rb_sys_enc_warning(rb_encoding *enc, const char *fmt, ...), 2, 3); +PRINTF_ARGS(void rb_syserr_enc_warning(int err, rb_encoding *enc, const char *fmt, ...), 3, 4); + VALUE rb_name_err_new(VALUE mesg, VALUE recv, VALUE method); #define rb_name_err_raise_str(mesg, recv, name) \ rb_exc_raise(rb_name_err_new(mesg, recv, name))