summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--error.c32
-rw-r--r--file.c16
-rw-r--r--internal.h4
3 files changed, 30 insertions, 22 deletions
diff --git a/error.c b/error.c
index 5f8b98c1ed..57784b6077 100644
--- a/error.c
+++ b/error.c
@@ -1224,12 +1224,12 @@ syserr_initialize(int argc, VALUE *argv, VALUE self)
char *strerror();
#endif
const char *err;
- VALUE mesg, error;
+ VALUE mesg, error, func;
VALUE klass = rb_obj_class(self);
if (klass == rb_eSystemCallError) {
st_data_t data = (st_data_t)klass;
- rb_scan_args(argc, argv, "11", &mesg, &error);
+ rb_scan_args(argc, argv, "12", &mesg, &error, &func);
if (argc == 1 && FIXNUM_P(mesg)) {
error = mesg; mesg = Qnil;
}
@@ -1243,7 +1243,7 @@ syserr_initialize(int argc, VALUE *argv, VALUE self)
}
}
else {
- rb_scan_args(argc, argv, "01", &mesg);
+ rb_scan_args(argc, argv, "02", &mesg, &func);
error = rb_const_get(klass, rb_intern("Errno"));
}
if (!NIL_P(error)) err = strerror(NUM2INT(error));
@@ -1253,7 +1253,10 @@ syserr_initialize(int argc, VALUE *argv, VALUE self)
VALUE str = StringValue(mesg);
rb_encoding *me = rb_enc_get(mesg);
- mesg = rb_sprintf("%s - %"PRIsVALUE, err, mesg);
+ if (NIL_P(func))
+ mesg = rb_sprintf("%s - %"PRIsVALUE, err, mesg);
+ else
+ mesg = rb_sprintf("%s @ %"PRIsVALUE" - %"PRIsVALUE, err, func, mesg);
if (le != me && rb_enc_asciicompat(me)) {
le = me;
}/* else assume err is non ASCII string. */
@@ -1907,6 +1910,27 @@ rb_sys_fail_str(VALUE mesg)
rb_exc_raise(make_errno_exc_str(mesg));
}
+#ifdef RUBY_FUNCTION_NAME_STRING
+void
+rb_sys_fail_path_in(const char *func_name, VALUE path)
+{
+ int n = errno;
+ VALUE args[2];
+
+ errno = 0;
+ if (!path) path = Qnil;
+ if (n == 0) {
+ const char *s = !NIL_P(path) ? RSTRING_PTR(path) : "";
+ if (!func_name) func_name = "(null)";
+ rb_bug("rb_sys_fail_path_in(%s, %s) - errno == 0",
+ func_name, s);
+ }
+ args[0] = path;
+ args[1] = rb_str_new_cstr(func_name);
+ rb_exc_raise(rb_class_new_instance(2, args, get_syserr(n)));
+}
+#endif
+
void
rb_mod_sys_fail(VALUE mod, const char *mesg)
{
diff --git a/file.c b/file.c
index 6e30c067f3..fa96c2388d 100644
--- a/file.c
+++ b/file.c
@@ -102,22 +102,6 @@ int flock(int, int);
#define STAT(p, s) stat((p), (s))
#endif
-#ifdef RUBY_FUNCTION_NAME_STRING
-void
-rb_sys_fail_path_with_func(const char *func_name, VALUE path)
-{
- VALUE mesg = rb_str_new_cstr(func_name);
- if (!NIL_P(path)) {
- /* RUBY_FUNCTION_NAME_STRING, aka __func__/__FUNCTION__ is not a
- * preprocessor macro but a static constant array, so string
- * literal concatenation is not allowed */
- rb_str_buf_cat2(mesg, ": ");
- rb_str_buf_append(mesg, path);
- }
- rb_sys_fail_str(mesg);
-}
-#endif
-
#if defined(__BEOS__) || defined(__HAIKU__) /* should not change ID if -1 */
static int
be_chown(const char *path, uid_t owner, gid_t group)
diff --git a/internal.h b/internal.h
index 56c096a009..b099f24352 100644
--- a/internal.h
+++ b/internal.h
@@ -126,11 +126,11 @@ void Init_File(void);
# if defined __GNUC__ && __GNUC__ >= 4
# pragma GCC visibility push(default)
# endif
-NORETURN(void rb_sys_fail_path_with_func(const char *func_name, VALUE path));
+NORETURN(void rb_sys_fail_path_in(const char *func_name, VALUE path));
# if defined __GNUC__ && __GNUC__ >= 4
# pragma GCC visibility pop
# endif
-# define rb_sys_fail_path(path) rb_sys_fail_path_with_func(RUBY_FUNCTION_NAME_STRING, path)
+# define rb_sys_fail_path(path) rb_sys_fail_path_in(RUBY_FUNCTION_NAME_STRING, path)
#else
# define rb_sys_fail_path(path) rb_sys_fail_str(path)
#endif