Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

io.readLine() unusable because EOF doesn't return current line #1579

Closed
shawnl opened this issue Sep 23, 2018 · 2 comments
Closed

io.readLine() unusable because EOF doesn't return current line #1579

shawnl opened this issue Sep 23, 2018 · 2 comments
Labels
standard library This issue involves writing Zig code for the standard library.
Milestone

Comments

@shawnl
Copy link
Contributor

shawnl commented Sep 23, 2018

this patch isn't working for me either:

diff --git a/std/io.zig b/std/io.zig
index c10fdcb..a4d6094 100644
--- a/std/io.zig
+++ b/std/io.zig
@@ -626,11 +626,20 @@ pub fn readLine(buf: []u8) !usize {
     var stream = &adapter.stream;
     var index: usize = 0;
     while (true) {
-        const byte = stream.readByte() catch return error.EndOfFile;
+        var byte: u8 = undefined;
+        if (stream.readByte()) |b| {
+            byte = b;
+        } else |_| {
+            if (index == 0) {
+                return error.EndOfFile;
+            } else {
+                return index;
+            }
+        }
         switch (byte) {
             '\r' => {
                 // trash the following \n
-                _ = stream.readByte() catch return error.EndOfFile;
+                _ = stream.readByte() catch undefined;
                 return index;
             },
             '\n' => return index,
@andrewrk andrewrk added this to the 0.4.0 milestone Sep 23, 2018
@andrewrk andrewrk added the standard library This issue involves writing Zig code for the standard library. label Sep 23, 2018
@shawnl
Copy link
Contributor Author

shawnl commented Sep 23, 2018

hmm, maybe this is normal. ruby's gets does the same thing.

@Hejsil
Copy link
Contributor

Hejsil commented Nov 30, 2018

Fixed in #1801

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
standard library This issue involves writing Zig code for the standard library.
Projects
None yet
Development

No branches or pull requests

3 participants