public void NEED_NEWLINE_DECORATOR_ON_READ_CHECK() { if (NEED_NEWLINE_DECORATOR_ON_READ()) { if (isReadable() && (encs.ecflags & EConvFlags.NEWLINE_DECORATOR_MASK) == 0) { SET_BINARY_MODE(); } else { SET_TEXT_MODE(); } } }
public void NEED_NEWLINE_DECORATOR_ON_READ_CHECK() { if (NEED_NEWLINE_DECORATOR_ON_READ()) { if (isReadable() && (encs.ecflags & EConvFlags.NEWLINE_DECORATOR_MASK) == 0) { SET_BINARY_MODE(); } else { SET_TEXT_MODE(); } } }
private static void checkSharedExclusive(Ruby runtime, OpenFile openFile, int lockMode) { // This logic used to attempt a shared lock instead of an exclusive // lock, because LOCK_EX on some systems (as reported in JRUBY-1214) // allow exclusively locking a read-only file. However, the JDK // APIs do not allow acquiring an exclusive lock on files that are // not open for read, and there are other platforms (such as Solaris, // see JRUBY-5627) that refuse at an *OS* level to exclusively lock // files opened only for read. As a result, this behavior is platform- // dependent, and so we will obey the JDK's policy of disallowing // exclusive locks on files opened only for read. if (!openFile.isWritable() && (lockMode & LOCK_EX) > 0) { throw runtime.newErrnoEBADFError("cannot acquire exclusive lock on File not opened for write"); } // Likewise, JDK does not allow acquiring a shared lock on files // that have not been opened for read. We comply here. if (!openFile.isReadable() && (lockMode & LOCK_SH) > 0) { throw runtime.newErrnoEBADFError("cannot acquire shared lock on File not opened for read"); } }
private static void checkSharedExclusive(Ruby runtime, OpenFile openFile, int lockMode) { // This logic used to attempt a shared lock instead of an exclusive // lock, because LOCK_EX on some systems (as reported in JRUBY-1214) // allow exclusively locking a read-only file. However, the JDK // APIs do not allow acquiring an exclusive lock on files that are // not open for read, and there are other platforms (such as Solaris, // see JRUBY-5627) that refuse at an *OS* level to exclusively lock // files opened only for read. As a result, this behavior is platform- // dependent, and so we will obey the JDK's policy of disallowing // exclusive locks on files opened only for read. if (!openFile.isWritable() && (lockMode & LOCK_EX) > 0) { throw runtime.newErrnoEBADFError("cannot acquire exclusive lock on File not opened for write"); } // Likewise, JDK does not allow acquiring a shared lock on files // that have not been opened for read. We comply here. if (!openFile.isReadable() && (lockMode & LOCK_SH) > 0) { throw runtime.newErrnoEBADFError("cannot acquire shared lock on File not opened for read"); } }
private void trySelectRead(ThreadContext context, Map<Character,Integer> attachment, OpenFile fptr) throws IOException { if (fptr.selectChannel() != null && registerSelect(getSelector(context, fptr.selectChannel()), attachment, fptr.selectChannel(), READ_ACCEPT_OPS)) { selectedReads++; if (fptr.READ_CHAR_PENDING() || fptr.READ_DATA_PENDING()) { getPendingReads()[attachment.get('r')] = true; } } else { if (fptr.isReadable()) { getUnselectableReads()[attachment.get('r')] = true; } } }
private void trySelectRead(ThreadContext context, Map<Character,Integer> attachment, OpenFile fptr) throws IOException { if (fptr.selectChannel() != null && registerSelect(getSelector(context, fptr.selectChannel()), attachment, fptr.selectChannel(), READ_ACCEPT_OPS)) { selectedReads++; if (fptr.READ_CHAR_PENDING() || fptr.READ_DATA_PENDING()) { getPendingReads()[attachment.get('r')] = true; } } else { if (fptr.isReadable()) { getUnselectableReads()[attachment.get('r')] = true; } } }
@Override @JRubyMethod public IRubyObject close_write(ThreadContext context) { Ruby runtime = context.runtime; if (!openFile.isWritable()) { return runtime.getNil(); } if (openFile.getPipeStream() == null && openFile.isReadable()) { throw runtime.newIOError("closing non-duplex IO for writing"); } if (!openFile.isReadable()) { close(); } else { // shutdown write try { shutdownInternal(context, 1); } catch (BadDescriptorException e) { throw runtime.newErrnoEBADFError(); } } return context.nil; }
@Override @JRubyMethod public IRubyObject close_write(ThreadContext context) { Ruby runtime = context.runtime; if (!openFile.isWritable()) { return runtime.getNil(); } if (openFile.getPipeStream() == null && openFile.isReadable()) { throw runtime.newIOError("closing non-duplex IO for writing"); } if (!openFile.isReadable()) { close(); } else { // shutdown write try { shutdownInternal(context, 1); } catch (BadDescriptorException e) { throw runtime.newErrnoEBADFError(); } } return context.nil; }
openFile.setProcess(process); if (openFile.isReadable()) { Channel inChannel; if (process.getInput() != null) { if (openFile.isReadable()) { RubyIO writeIO = new RubyIO(runtime, runtime.getIO()); writeIO.initializeCommon(runtime.getCurrentContext(), pipe, runtime.newFixnum(OpenFlags.O_WRONLY), runtime.getNil());
openFile.setProcess(process); if (openFile.isReadable()) { Channel inChannel; if (process.getInput() != null) { if (openFile.isReadable()) { RubyIO writeIO = new RubyIO(runtime, runtime.getIO()); writeIO.initializeCommon(runtime.getCurrentContext(), pipe, runtime.newFixnum(OpenFlags.O_WRONLY), runtime.getNil());
if (!fptr.isReadable()) return write_io.rbIoClose(context); return context.nil; if (fptr.isReadable() && !fptr.isDuplex()) { throw runtime.newIOError("closing non-duplex IO for writing");
@JRubyMethod(name = "close_write") public IRubyObject close_write(ThreadContext context) { try { OpenFile myOpenFile = getOpenFileChecked(); if (myOpenFile.getPipeStream() == null && myOpenFile.isReadable()) { throw context.runtime.newIOError("closing non-duplex IO for writing"); } if (myOpenFile.getPipeStream() == null) { close(); } else{ myOpenFile.getPipeStream().fclose(); myOpenFile.setPipeStream(null); myOpenFile.setMode(myOpenFile.getMode() & ~OpenFile.WRITABLE); // TODO // n is result of fclose; but perhaps having a SysError below is enough? // if (n != 0) rb_sys_fail(fptr->path); } } catch (BadDescriptorException bde) { throw context.runtime.newErrnoEBADFError(); } catch (IOException ioe) { // hmmmm } return this; }
@JRubyMethod(name = "close_write") public IRubyObject close_write(ThreadContext context) { try { OpenFile myOpenFile = getOpenFileChecked(); if (myOpenFile.getPipeStream() == null && myOpenFile.isReadable()) { throw context.runtime.newIOError("closing non-duplex IO for writing"); } if (myOpenFile.getPipeStream() == null) { close(); } else{ myOpenFile.getPipeStream().fclose(); myOpenFile.setPipeStream(null); myOpenFile.setMode(myOpenFile.getMode() & ~OpenFile.WRITABLE); // TODO // n is result of fclose; but perhaps having a SysError below is enough? // if (n != 0) rb_sys_fail(fptr->path); } } catch (BadDescriptorException bde) { throw context.runtime.newErrnoEBADFError(); } catch (IOException ioe) { // hmmmm } return this; }
if (!fptr.isReadable()) return write_io.rbIoClose(context); return context.nil; if (fptr.isReadable() && !fptr.isDuplex()) { throw runtime.newIOError("closing non-duplex IO for writing");
if (openFile.isReadable()) { Channel inChannel; if (process.getInput() != null) {
if (openFile.isReadable()) { Channel inChannel; if (process.getInput() != null) {
if ((fptr.isReadable()) && (fptr.READ_DATA_BUFFERED() || fptr.READ_CHAR_PENDING())) { throw runtime.newIOError("sysseek for buffered IO");
if (myOpenFile.isReadable() && myOpenFile.isReadBuffered()) { throw context.runtime.newIOError("sysseek for buffered IO");
if (myOpenFile.isReadable() && myOpenFile.isReadBuffered()) { throw context.runtime.newIOError("sysseek for buffered IO");
if ((fptr.isReadable()) && (fptr.READ_DATA_BUFFERED() || fptr.READ_CHAR_PENDING())) { throw runtime.newIOError("sysseek for buffered IO");