Ensure gets stops on newline or bufchar

This commit is contained in:
Tom Almeida
2018-07-03 12:36:41 +08:00
parent bf6db91993
commit d7a0f3d526
+3
View File
@@ -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));