Index: src/org/jruby/util/IOHandlerSeekable.java
===================================================================
RCS file: /cvsroot/jruby/jruby/src/org/jruby/util/IOHandlerSeekable.java,v
retrieving revision 1.19
diff -u -r1.19 IOHandlerSeekable.java
--- src/org/jruby/util/IOHandlerSeekable.java	30 May 2006 17:52:48 -0000	1.19
+++ src/org/jruby/util/IOHandlerSeekable.java	18 Jun 2006 14:52:37 -0000
@@ -51,6 +51,9 @@
 public class IOHandlerSeekable extends IOHandlerJavaIO {
     protected RandomAccessFile file;
     protected String path;
+
+    private boolean shouldReplace = false;
+    private boolean isWin = true;
     
     public IOHandlerSeekable(IRuby runtime, String path, IOModes modes) 
     	throws IOException, InvalidValueException {
@@ -88,6 +91,13 @@
         if (modes.isAppendable()) {
             seek(0, SEEK_END);
         }
+        final String ls = System.getProperty("line.separator");
+        if(!modes.isBinary() && !"\n".equals(ls)) {
+            shouldReplace = true;
+            if("\r".equals(ls)) {
+                isWin = false;
+            }
+        }
 
         // We give a fileno last so that we do not consume these when
         // we have a problem opening a file.
@@ -233,7 +243,24 @@
      * @see org.jruby.util.IOHandler#sysread()
      */
     public int sysread() throws IOException {
-        return file.read();
+        if(!shouldReplace) {
+            return file.read();
+        } else {
+            final int curr = file.read();
+            if(curr != '\r') {
+                return curr;
+            } else if(!isWin) {
+                return '\n';
+            } else {
+                final int next = file.read();
+                if(next == '\n') {
+                    return next;
+                } else {
+                    file.seek(file.getFilePointer()-1);
+                    return curr;
+                }
+            }
+        }
     }
     
     /**
Index: src/org/jruby/util/IOModes.java
===================================================================
RCS file: /cvsroot/jruby/jruby/src/org/jruby/util/IOModes.java,v
retrieving revision 1.10
diff -u -r1.10 IOModes.java
--- src/org/jruby/util/IOModes.java	24 May 2006 01:34:04 -0000	1.10
+++ src/org/jruby/util/IOModes.java	18 Jun 2006 14:40:49 -0000
@@ -46,6 +46,7 @@
     public static final int TRUNC = 512;
     public static final int APPEND = 1024;
     public static final int NONBLOCK = 2048;
+    public static final int BINARY = 4096;
     
     private IRuby runtime;
     private int modes;
@@ -67,13 +68,17 @@
     }
     
     public boolean isReadable() {
-        return (modes & RDWR) != 0 || modes == RDONLY;
+        return (modes & RDWR) != 0 || modes == RDONLY || modes == BINARY;
     }
 
     public boolean isWriteable() {
         return isWritable();
     }
 
+    public boolean isBinary() {
+        return (modes & BINARY) == BINARY;
+    }
+
     public boolean isWritable() {
     	return (modes & RDWR) != 0 || (modes & WRONLY) != 0 || (modes & CREAT) != 0;
     }
@@ -81,7 +86,7 @@
     public boolean isAppendable() {
     	return (modes & APPEND) != 0;
     }
-    
+
     public boolean shouldTruncate() {
     	return (modes & TRUNC) != 0;
     }
@@ -140,6 +145,10 @@
                     throw runtime.newArgumentError("illegal access mode " + modes);
                 }
             }
+            if(i == 2) {
+                modes |= BINARY;
+            }
+
         }
     	return modes;
     }
