summaryrefslogtreecommitdiff
path: root/error.c
diff options
context:
space:
mode:
Diffstat (limited to 'error.c')
-rw-r--r--error.c36
1 files changed, 33 insertions, 3 deletions
diff --git a/error.c b/error.c
index 3a3bb749c4..a23232375d 100644
--- a/error.c
+++ b/error.c
@@ -18,12 +18,25 @@
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
+#include <errno.h>
+
#ifndef EXIT_SUCCESS
#define EXIT_SUCCESS 0
#endif
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 +249,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;
@@ -349,8 +376,6 @@ rb_check_typeddata(VALUE obj, const rb_data_type_t *data_type)
}
/* exception classes */
-#include <errno.h>
-
#if 0
VALUE rb_eException;
VALUE rb_eSystemExit;
@@ -1255,7 +1280,8 @@ rb_check_frozen(VALUE obj)
if (OBJ_FROZEN(obj)) rb_error_frozen(rb_obj_classname(obj));
}
-void Init_syserr(void)
+void
+Init_syserr(void)
{
}
@@ -1263,7 +1289,11 @@ void
InitVM_syserr(void)
{
rb_eNOERROR = set_syserr(0, "NOERROR");
+#define defined_error(name, num) set_syserr(num, name);
+#define undefined_error(name) set_syserr(0, name);
#include "known_errors.inc"
+#undef defined_error
+#undef undefined_error
}
static void