From ff9d9088329fc8270d1d9b89faf9187c33a854ac Mon Sep 17 00:00:00 2001 From: akr Date: Tue, 24 Nov 2009 11:03:51 +0000 Subject: * include/ruby/ruby.h (rb_bug_errno): declared. * include/ruby/intern.h (rb_strerrno): declaration removed. * error.c (rb_strerrno): make it static. return NULL for unknown errors. (rb_bug_errno): defined. * thread_pthread.c: use rb_bug_errno. * signal.c (ruby_signal): use rb_bug_errno. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25904 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- error.c | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) (limited to 'error.c') diff --git a/error.c b/error.c index 9633e9e252..55834a3cd8 100644 --- a/error.c +++ b/error.c @@ -24,6 +24,17 @@ extern const char ruby_description[]; +static const char * +rb_strerrno(int err) +{ +#define defined_error(name, num) if (err == num) return name; +#define undefined_error(name) +#include "known_errors.inc" +#undef defined_error +#undef undefined_error + return NULL; +} + static int err_position_0(char *buf, long len, const char *file, int line) { @@ -235,6 +246,20 @@ rb_bug(const char *fmt, ...) abort(); } +void +rb_bug_errno(const char *mesg, int errno_arg) +{ + if (errno_arg == 0) + rb_bug("%s: errno == 0 (NOERROR)", mesg); + else { + const char *errno_str = rb_strerrno(errno_arg); + if (errno_str) + rb_bug("%s: %s (%s)", mesg, strerror(errno_arg), errno_str); + else + rb_bug("%s: %s (%d)", mesg, strerror(errno_arg), errno_arg); + } +} + void rb_compile_bug(const char *file, int line, const char *fmt, ...) { @@ -1258,18 +1283,6 @@ Init_syserr(void) #undef undefined_error } -const char * -rb_strerrno(int err) -{ - if (err == 0) return "NOERROR"; -#define defined_error(name, num) if (err == num) return name; -#define undefined_error(name) -#include "known_errors.inc" -#undef defined_error -#undef undefined_error - return "UNKNOWNERROR"; -} - static void err_append(const char *s) { -- cgit v1.2.3