Skip to content

Commit b5bc1e8

Browse files
committed
vexos: clean up Stdin read impl, use explicit cast in fs
1 parent 48c9a1c commit b5bc1e8

File tree

4 files changed

+12
-11
lines changed

4 files changed

+12
-11
lines changed

library/std/src/sys/fs/vexos.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::ffi::OsString;
1+
use crate::ffi::{OsString, c_char};
22
use crate::fmt;
33
use crate::fs::TryLockError;
44
use crate::hash::Hash;
@@ -342,9 +342,9 @@ impl File {
342342
}
343343

344344
pub fn read(&self, buf: &mut [u8]) -> io::Result<usize> {
345-
let len = buf.len() as _;
345+
let len = buf.len() as u32;
346346
let buf_ptr = buf.as_mut_ptr();
347-
let read = unsafe { vex_sdk::vexFileRead(buf_ptr.cast(), 1, len, self.fd.0) };
347+
let read = unsafe { vex_sdk::vexFileRead(buf_ptr.cast::<c_char>(), 1, len, self.fd.0) };
348348

349349
if read < 0 {
350350
Err(io::const_error!(io::ErrorKind::Other, "Could not read from file"))
@@ -367,10 +367,11 @@ impl File {
367367
}
368368

369369
pub fn write(&self, buf: &[u8]) -> io::Result<usize> {
370-
let len = buf.len();
370+
let len = buf.len() as u32;
371371
let buf_ptr = buf.as_ptr();
372-
let written =
373-
unsafe { vex_sdk::vexFileWrite(buf_ptr.cast_mut().cast(), 1, len as _, self.fd.0) };
372+
let written = unsafe {
373+
vex_sdk::vexFileWrite(buf_ptr.cast_mut().cast::<c_char>(), 1, len, self.fd.0)
374+
};
374375

375376
if written < 0 {
376377
Err(io::const_error!(io::ErrorKind::Other, "Could not write to file"))
@@ -516,9 +517,12 @@ pub fn lstat(p: &Path) -> io::Result<FileAttr> {
516517
stat(p)
517518
}
518519

520+
// NOTE: Cannot use `copy` from `common` here, since we have no support
521+
// for `File::set_permissions`.
519522
pub fn copy(from: &Path, to: &Path) -> io::Result<u64> {
520523
use crate::fs::File;
521524

525+
// If `from` is a directory, this call should fail.
522526
let mut reader = File::open(from)?;
523527
let mut writer = File::create(to)?;
524528

library/std/src/sys/stdio/vexos.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@ impl io::Read for Stdin {
1616
fn read(&mut self, mut buf: &mut [u8]) -> io::Result<usize> {
1717
let mut count = 0;
1818

19-
while let Some((out_byte, new_buf)) = buf.split_first_mut() {
20-
buf = new_buf;
21-
19+
for out_byte in buf.iter_mut() {
2220
let byte = unsafe { vex_sdk::vexSerialReadChar(STDIO_CHANNEL) };
2321
if byte < 0 {
2422
break;

library/std/src/sys/thread/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,6 @@ cfg_select! {
145145
target_os = "dragonfly",
146146
target_os = "hurd",
147147
target_os = "fuchsia",
148-
target_os = "vexos",
149148
target_os = "vxworks",
150149
all(target_os = "wasi", target_env = "p2"),
151150
)))]

library/std/src/sys/thread/vexos.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::time::Duration;
1+
use crate::time::{Duration, Instant};
22

33
pub fn yield_now() {
44
unsafe {

0 commit comments

Comments
 (0)