summaryrefslogtreecommitdiffstats
path: root/error.c
diff options
context:
space:
mode:
Diffstat (limited to 'error.c')
-rw-r--r--error.c37
1 files changed, 25 insertions, 12 deletions
diff --git a/error.c b/error.c
index 9633e9e25..55834a3cd 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)
{
@@ -236,6 +247,20 @@ rb_bug(const char *fmt, ...)
}
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, ...)
{
va_list args;
@@ -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)
{