1
1
#![ deny( unsafe_op_in_unsafe_fn) ]
2
2
3
+ #[ expect( dead_code) ]
4
+ #[ path = "unsupported.rs" ]
5
+ mod unsupported_stdio;
6
+
3
7
use core:: arch:: asm;
4
8
5
9
use crate :: io;
6
10
7
- pub struct Stdin ;
11
+ pub type Stdin = unsupported_stdio :: Stdin ;
8
12
pub struct Stdout ;
9
- pub struct Stderr ;
13
+ pub type Stderr = Stdout ;
10
14
11
15
const KCALL_DEBUG_CMD_PUT_BYTES : i64 = 2 ;
12
16
@@ -25,27 +29,6 @@ unsafe fn debug_call(cap_ref: u64, call_no: i64, arg1: u64, arg2: u64) -> i32 {
25
29
ret as i32
26
30
}
27
31
28
- fn print_buf ( s : & [ u8 ] ) -> io:: Result < usize > {
29
- // Corresponds to `HM_DEBUG_PUT_BYTES_LIMIT`.
30
- const MAX_LEN : usize = 512 ;
31
- let len = if s. len ( ) > MAX_LEN { MAX_LEN } else { s. len ( ) } ;
32
- let result = unsafe { debug_call ( 0 , KCALL_DEBUG_CMD_PUT_BYTES , s. as_ptr ( ) as u64 , len as u64 ) } ;
33
-
34
- if result == 0 { Ok ( len) } else { Err ( io:: Error :: from ( io:: ErrorKind :: InvalidInput ) ) }
35
- }
36
-
37
- impl Stdin {
38
- pub const fn new ( ) -> Stdin {
39
- Stdin
40
- }
41
- }
42
-
43
- impl io:: Read for Stdin {
44
- fn read ( & mut self , _buf : & mut [ u8 ] ) -> io:: Result < usize > {
45
- Ok ( 0 )
46
- }
47
- }
48
-
49
32
impl Stdout {
50
33
pub const fn new ( ) -> Stdout {
51
34
Stdout
@@ -54,31 +37,21 @@ impl Stdout {
54
37
55
38
impl io:: Write for Stdout {
56
39
fn write ( & mut self , buf : & [ u8 ] ) -> io:: Result < usize > {
57
- print_buf ( buf)
58
- }
59
-
60
- fn flush ( & mut self ) -> io:: Result < ( ) > {
61
- Ok ( ( ) )
62
- }
63
- }
40
+ // Corresponds to `HM_DEBUG_PUT_BYTES_LIMIT`.
41
+ const MAX_LEN : usize = 512 ;
42
+ let len = buf. len ( ) . min ( MAX_LEN ) ;
43
+ let result =
44
+ unsafe { debug_call ( 0 , KCALL_DEBUG_CMD_PUT_BYTES , buf. as_ptr ( ) as u64 , len as u64 ) } ;
64
45
65
- impl Stderr {
66
- pub const fn new ( ) -> Stderr {
67
- Stderr
68
- }
69
- }
70
-
71
- impl io:: Write for Stderr {
72
- fn write ( & mut self , buf : & [ u8 ] ) -> io:: Result < usize > {
73
- print_buf ( buf)
46
+ if result == 0 { Ok ( len) } else { Err ( io:: Error :: from ( io:: ErrorKind :: InvalidInput ) ) }
74
47
}
75
48
76
49
fn flush ( & mut self ) -> io:: Result < ( ) > {
77
50
Ok ( ( ) )
78
51
}
79
52
}
80
53
81
- pub const STDIN_BUF_SIZE : usize = 0 ;
54
+ pub const STDIN_BUF_SIZE : usize = unsupported_stdio :: STDIN_BUF_SIZE ;
82
55
83
56
pub fn is_ebadf ( err : & io:: Error ) -> bool {
84
57
err. raw_os_error ( ) == Some ( libc:: EBADF as i32 )
0 commit comments