summaryrefslogtreecommitdiff
path: root/io.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-01-07 04:10:06 (GMT)
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-01-07 04:10:06 (GMT)
commitf39ea3d189063d8c6cf4fee9783a99ba4db87303 (patch)
tree66109e0186e4d78005edda14e9b0534b4baa812c /io.c
parent707ab2c848f5c092781157a99d4ea20f729cd139 (diff)
io.c: rb_stderr_to_original_p
* io.c (rb_stderr_to_original_p): hoist out the condition to write messages to the stderr FD directly. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61646 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'io.c')
-rw-r--r--io.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/io.c b/io.c
index 1986d3e..eeaf0c0 100644
--- a/io.c
+++ b/io.c
@@ -7763,10 +7763,16 @@ rb_obj_display(int argc, VALUE *argv, VALUE self)
return Qnil;
}
+static int
+rb_stderr_to_original_p(void)
+{
+ return (rb_stderr == orig_stderr || RFILE(orig_stderr)->fptr->fd < 0);
+}
+
void
rb_write_error2(const char *mesg, long len)
{
- if (rb_stderr == orig_stderr || RFILE(orig_stderr)->fptr->fd < 0) {
+ if (rb_stderr_to_original_p()) {
#ifdef _WIN32
if (isatty(fileno(stderr))) {
if (rb_w32_write_console(rb_str_new(mesg, len), fileno(stderr)) > 0) return;
@@ -7792,7 +7798,7 @@ void
rb_write_error_str(VALUE mesg)
{
/* a stopgap measure for the time being */
- if (rb_stderr == orig_stderr || RFILE(orig_stderr)->fptr->fd < 0) {
+ if (rb_stderr_to_original_p()) {
size_t len = (size_t)RSTRING_LEN(mesg);
#ifdef _WIN32
if (isatty(fileno(stderr))) {
@@ -7813,7 +7819,7 @@ rb_write_error_str(VALUE mesg)
int
rb_stderr_tty_p(void)
{
- if (rb_stderr == orig_stderr || RFILE(orig_stderr)->fptr->fd < 0)
+ if (rb_stderr_to_original_p())
return isatty(fileno(stderr));
return 0;
}