diff options
Diffstat (limited to 'error.c')
-rw-r--r-- | error.c | 48 |
1 files changed, 48 insertions, 0 deletions
@@ -1633,11 +1633,31 @@ make_errno_exc(const char *mesg) return rb_syserr_new(n, mesg); } +static VALUE +make_errno_exc_str(VALUE mesg) +{ + int n = errno; + + errno = 0; + if (!mesg) mesg = Qnil; + if (n == 0) { + const char *s = !NIL_P(mesg) ? RSTRING_PTR(mesg) : ""; + rb_bug("rb_sys_fail_str(%s) - errno == 0", s); + } + return rb_syserr_new_str(n, mesg); +} + VALUE rb_syserr_new(int n, const char *mesg) { VALUE arg; arg = mesg ? rb_str_new2(mesg) : Qnil; + return rb_syserr_new_str(n, arg); +} + +VALUE +rb_syserr_new_str(int n, VALUE arg) +{ return rb_class_new_instance(1, &arg, get_syserr(n)); } @@ -1648,12 +1668,24 @@ rb_syserr_fail(int e, const char *mesg) } void +rb_syserr_fail_str(int e, VALUE mesg) +{ + rb_exc_raise(rb_syserr_new_str(e, mesg)); +} + +void rb_sys_fail(const char *mesg) { rb_exc_raise(make_errno_exc(mesg)); } void +rb_sys_fail_str(VALUE mesg) +{ + rb_exc_raise(make_errno_exc_str(mesg)); +} + +void rb_mod_sys_fail(VALUE mod, const char *mesg) { VALUE exc = make_errno_exc(mesg); @@ -1662,6 +1694,14 @@ rb_mod_sys_fail(VALUE mod, const char *mesg) } void +rb_mod_sys_fail_str(VALUE mod, VALUE mesg) +{ + VALUE exc = make_errno_exc_str(mesg); + rb_extend_object(exc, mod); + rb_exc_raise(exc); +} + +void rb_mod_syserr_fail(VALUE mod, int e, const char *mesg) { VALUE exc = rb_syserr_new(e, mesg); @@ -1670,6 +1710,14 @@ rb_mod_syserr_fail(VALUE mod, int e, const char *mesg) } void +rb_mod_syserr_fail_str(VALUE mod, int e, VALUE mesg) +{ + VALUE exc = rb_syserr_new_str(e, mesg); + rb_extend_object(exc, mod); + rb_exc_raise(exc); +} + +void rb_sys_warning(const char *fmt, ...) { char buf[BUFSIZ]; |