summaryrefslogtreecommitdiff
path: root/error.c
diff options
context:
space:
mode:
Diffstat (limited to 'error.c')
-rw-r--r--error.c38
1 files changed, 28 insertions, 10 deletions
diff --git a/error.c b/error.c
index e2d14304db..d9c673c807 100644
--- a/error.c
+++ b/error.c
@@ -26,26 +26,33 @@
int ruby_nerrs;
-static void
-err_snprintf(buf, len, fmt, args)
+static int
+err_position(buf, len)
char *buf;
long len;
- const char *fmt;
- va_list args;
{
- long n;
-
ruby_set_current_source();
if (!ruby_sourcefile) {
- vsnprintf(buf, len, fmt, args);
- return;
+ return 0;
}
else if (ruby_sourceline == 0) {
- n = snprintf(buf, len, "%s: ", ruby_sourcefile);
+ return snprintf(buf, len, "%s: ", ruby_sourcefile);
}
else {
- n = snprintf(buf, len, "%s:%d: ", ruby_sourcefile, ruby_sourceline);
+ return snprintf(buf, len, "%s:%d: ", ruby_sourcefile, ruby_sourceline);
}
+}
+
+static void
+err_snprintf(buf, len, fmt, args)
+ char *buf;
+ long len;
+ const char *fmt;
+ va_list args;
+{
+ long n;
+
+ n = err_position(buf, len);
if (len > n) {
vsnprintf((char*)buf+n, len-n, fmt, args);
}
@@ -151,6 +158,15 @@ rb_warning(fmt, va_alist)
va_end(args);
}
+static VALUE
+rb_warn_m(self, mesg)
+ VALUE self, mesg;
+{
+ rb_io_write(rb_deferr, mesg);
+ rb_io_write(rb_deferr, rb_default_rs);
+ return mesg;
+}
+
void
#ifdef HAVE_STDARG_PROTOTYPES
rb_bug(const char *fmt, ...)
@@ -653,6 +669,8 @@ Init_Exception()
rb_eNoMemError = rb_define_class("NoMemoryError", rb_eException);
init_syserr();
+
+ rb_define_global_function("warn", rb_warn_m, 1);
}
void