58 lines
1.4 KiB
Diff
58 lines
1.4 KiB
Diff
--- a/src/header/stdio/ext.rs
|
|
+++ b/src/header/stdio/ext.rs
|
|
@@ -1,8 +1,15 @@
|
|
use crate::{
|
|
- header::stdio::{F_NORD, F_NOWR, FILE},
|
|
+ header::stdio::{F_ERR, F_NORD, F_NOWR, FILE},
|
|
platform::types::{c_int, size_t},
|
|
};
|
|
|
|
+#[unsafe(no_mangle)]
|
|
+pub extern "C" fn __freadahead(stream: *mut FILE) -> size_t {
|
|
+ let stream = unsafe { &mut *stream }.lock();
|
|
+
|
|
+ (stream.read_size.saturating_sub(stream.read_pos) + stream.unget.len()) as size_t
|
|
+}
|
|
+
|
|
#[unsafe(no_mangle)]
|
|
pub extern "C" fn __fpending(stream: *mut FILE) -> size_t {
|
|
let stream = unsafe { &mut *stream }.lock();
|
|
@@ -24,6 +31,13 @@ pub extern "C" fn __fwritable(stream: *mut FILE) -> c_int {
|
|
c_int::from(stream.flags & F_NOWR == 0)
|
|
}
|
|
|
|
+#[unsafe(no_mangle)]
|
|
+pub extern "C" fn __fseterr(stream: *mut FILE) {
|
|
+ let mut stream = unsafe { &mut *stream }.lock();
|
|
+
|
|
+ stream.flags |= F_ERR;
|
|
+}
|
|
+
|
|
//TODO: Check last operation when read-write
|
|
#[unsafe(no_mangle)]
|
|
pub extern "C" fn __freading(stream: *mut FILE) -> c_int {
|
|
--- a/include/stdio_ext.h
|
|
+++ b/include/stdio_ext.h
|
|
@@ -2,5 +2,21 @@
|
|
#define _STDIO_EXT_H
|
|
|
|
#include <stdio.h>
|
|
+
|
|
+#ifdef __cplusplus
|
|
+extern "C" {
|
|
+#endif
|
|
+
|
|
+size_t __freadahead(FILE *stream);
|
|
+size_t __fpending(FILE *stream);
|
|
+int __freadable(FILE *stream);
|
|
+int __freading(FILE *stream);
|
|
+void __fseterr(FILE *stream);
|
|
+int __fwritable(FILE *stream);
|
|
+int __fwriting(FILE *stream);
|
|
+
|
|
+#ifdef __cplusplus
|
|
+} // extern "C"
|
|
+#endif
|
|
|
|
#endif /* _STDIO_EXT_H */
|