Browse Source

Ensure gets stops on newline or bufchar

Tom Almeida 6 years ago
parent
commit
d7a0f3d526
1 changed files with 3 additions and 0 deletions
  1. 3 0
      src/stdio/src/lib.rs

+ 3 - 0
src/stdio/src/lib.rs

@@ -351,6 +351,9 @@ pub extern "C" fn fgets(s: *mut c_char, n: c_int, stream: &mut FILE) -> *mut c_c
     if let Some((rpos, rend)) = stream.read {
         for _ in (0..(n-1) as usize).take_while(|x| rpos + x < rend) {
             st[diff] = stream.buf[rpos + diff] as i8;
+            if st[diff] == b'\n' as i8 || st[diff] == stream.buf_char {
+                break;
+            }
             diff += 1;
         }
         stream.read = Some((rpos+diff, rend));