@@ -4,63 +4,45 @@ use core::{fmt, slice};
44use crate :: nr;
55
66/// Host's standard error
7+ /// A byte stream to the host (e.g. host's stdout or stderr).
78#[ derive( Clone , Copy ) ]
8- pub struct HStderr {
9+ pub struct HostStream {
910 fd : usize ,
1011}
1112
12- impl HStderr {
13+ impl HostStream {
1314 /// Attempts to write an entire `buffer` into this sink
1415 pub fn write_all ( & mut self , buffer : & [ u8 ] ) -> Result < ( ) , ( ) > {
1516 write_all ( self . fd , buffer)
1617 }
1718}
1819
19- impl fmt:: Write for HStderr {
20- fn write_str ( & mut self , s : & str ) -> fmt:: Result {
21- self . write_all ( s. as_bytes ( ) ) . map_err ( |_| fmt:: Error )
22- }
23- }
24-
25- /// Host's standard output
26- #[ derive( Clone , Copy ) ]
27- pub struct HStdout {
28- fd : usize ,
29- }
30-
31- impl HStdout {
32- /// Attempts to write an entire `buffer` into this sink
33- pub fn write_all ( & mut self , buffer : & [ u8 ] ) -> Result < ( ) , ( ) > {
34- write_all ( self . fd , buffer)
35- }
36- }
37-
38- impl fmt:: Write for HStdout {
20+ impl fmt:: Write for HostStream {
3921 fn write_str ( & mut self , s : & str ) -> fmt:: Result {
4022 self . write_all ( s. as_bytes ( ) ) . map_err ( |_| fmt:: Error )
4123 }
4224}
4325
4426/// Construct a new handle to the host's standard error.
45- pub fn hstderr ( ) -> Result < HStderr , ( ) > {
27+ pub fn hstderr ( ) -> Result < HostStream , ( ) > {
4628 // There is actually no stderr access in ARM Semihosting documentation. Use
4729 // convention used in libgloss.
4830 // See: libgloss/arm/syscalls.c, line 139.
4931 // https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;a=blob;f=libgloss/arm/syscalls.c#l139
50- open ( ":tt\0 " , nr:: open:: W_APPEND ) . map ( |fd| HStderr { fd } )
32+ open ( ":tt\0 " , nr:: open:: W_APPEND )
5133}
5234
5335/// Construct a new handle to the host's standard output.
54- pub fn hstdout ( ) -> Result < HStdout , ( ) > {
55- open ( ":tt\0 " , nr:: open:: W_TRUNC ) . map ( |fd| HStdout { fd } )
36+ pub fn hstdout ( ) -> Result < HostStream , ( ) > {
37+ open ( ":tt\0 " , nr:: open:: W_TRUNC )
5638}
5739
58- fn open ( name : & str , mode : usize ) -> Result < usize , ( ) > {
40+ fn open ( name : & str , mode : usize ) -> Result < HostStream , ( ) > {
5941 let name = name. as_bytes ( ) ;
6042 match unsafe { syscall ! ( OPEN , name. as_ptr( ) , mode, name. len( ) - 1 ) } as
6143 isize {
6244 -1 => Err ( ( ) ) ,
63- fd => Ok ( fd as usize ) ,
45+ fd => Ok ( HostStream { fd : fd as usize } ) ,
6446 }
6547}
6648
0 commit comments