Skip to content

Commit

Permalink
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions core/src/main/java/org/jruby/util/io/OpenFile.java
Original file line number Diff line number Diff line change
@@ -2029,20 +2029,26 @@ private void unreadWindows(ThreadContext context) {
return;
}

// io_fwrite
// MRI: io_fwrite
public long fwrite(ThreadContext context, IRubyObject str, boolean nosync) {
// TODO: Windows
// #ifdef _WIN32
// if (fptr->mode & FMODE_TTY) {
// long len = rb_w32_write_console(str, fptr->fd);
// if (len > 0) return len;
// }
// #endif
if (Platform.IS_WINDOWS && isStdio()) {
return rbW32WriteConsole((RubyString)str);
}

str = doWriteconv(context, str);
ByteList strByteList = ((RubyString)str).getByteList();
return binwrite(context, str, strByteList.unsafeBytes(), strByteList.begin(), strByteList.length(), nosync);
}

// MRI: rb_w32_write_console
public static long rbW32WriteConsole(RubyString buffer) {
// The actual port in MRI uses win32 APIs, but System.console seems to do what we want. See jruby/jruby#3292.
// FIXME: This assumes the System.console() is the right one to write to. Can you have multiple active?
System.console().printf("%s", buffer.asJavaString());

return buffer.size();
}

// do_writeconv
public IRubyObject doWriteconv(ThreadContext context, IRubyObject str)
{

0 comments on commit aae72b5

Please sign in to comment.