Skip to content
Snippets Groups Projects
Commit 1cdca489 authored by Astro's avatar Astro :gear:
Browse files

l0dable: depend on alloc as follow-up to str_to_cstr removal

parent ad10b054
Branches no-str_to_cstr
No related tags found
1 merge request!22Remove str_to_cstr
Pipeline #4022 failed
...@@ -98,6 +98,7 @@ dependencies = [ ...@@ -98,6 +98,7 @@ dependencies = [
name = "card10-l0dable" name = "card10-l0dable"
version = "0.3.0" version = "0.3.0"
dependencies = [ dependencies = [
"card10-alloc 0.1.1",
"card10-sys 1.10.0", "card10-sys 1.10.0",
"embedded-graphics 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", "embedded-graphics 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
......
...@@ -29,4 +29,5 @@ documentation = "https://docs.rs/card10-l0dable" ...@@ -29,4 +29,5 @@ documentation = "https://docs.rs/card10-l0dable"
[dependencies] [dependencies]
card10-sys = { path = "../card10-sys" } card10-sys = { path = "../card10-sys" }
card10-alloc = { path = "../card10-alloc" }
embedded-graphics = "0.5" embedded-graphics = "0.5"
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
use core::mem::uninitialized; use core::mem::uninitialized;
use core::str::from_utf8_unchecked; use core::str::from_utf8_unchecked;
use alloc::format;
use card10_sys::*; use card10_sys::*;
...@@ -30,7 +31,7 @@ impl From<i32> for Error { ...@@ -30,7 +31,7 @@ impl From<i32> for Error {
} }
pub fn read_dir(path: &str) -> Result<ReadDir> { pub fn read_dir(path: &str) -> Result<ReadDir> {
let pathbuf = crate::str_to_cstr(path); let pathbuf = format!("{}\0", path);
Error::check(|| unsafe { epic_file_opendir(pathbuf.as_ptr()) }).map(|fd| ReadDir { fd }) Error::check(|| unsafe { epic_file_opendir(pathbuf.as_ptr()) }).map(|fd| ReadDir { fd })
} }
...@@ -104,8 +105,8 @@ impl DirStat { ...@@ -104,8 +105,8 @@ impl DirStat {
} }
pub fn rename(from: &str, to: &str) -> Result<()> { pub fn rename(from: &str, to: &str) -> Result<()> {
let frombuf = crate::str_to_cstr(from); let frombuf = format!("{}\0", from);
let tobuf = crate::str_to_cstr(to); let tobuf = format!("{}\0", to);
Error::check(|| unsafe { epic_file_rename(frombuf.as_ptr(), tobuf.as_ptr()) }).map(|_| ()) Error::check(|| unsafe { epic_file_rename(frombuf.as_ptr(), tobuf.as_ptr()) }).map(|_| ())
} }
...@@ -115,7 +116,7 @@ pub struct File { ...@@ -115,7 +116,7 @@ pub struct File {
impl File { impl File {
pub fn open(path: &str) -> Result<File> { pub fn open(path: &str) -> Result<File> {
let pathbuf = crate::str_to_cstr(path); let pathbuf = format!("{}\0", path);
let modebuf = b"r\0"; let modebuf = b"r\0";
Error::check(|| unsafe { epic_file_open(pathbuf.as_ptr(), modebuf.as_ptr()) }) Error::check(|| unsafe { epic_file_open(pathbuf.as_ptr(), modebuf.as_ptr()) })
.map(|fd| File { fd }) .map(|fd| File { fd })
......
//! [Repository](https://git.card10.badge.events.ccc.de/astro/rust-card10) //! [Repository](https://git.card10.badge.events.ccc.de/astro/rust-card10)
#![no_std] #![no_std]
use card10_alloc as _;
extern crate alloc;
mod os; mod os;
pub use os::*; pub use os::*;
mod display; mod display;
......
use alloc::format;
use card10_sys::*; use card10_sys::*;
/// Execute Python script or ELF file /// Execute Python script or ELF file
pub fn exec(path: &str) -> ! { pub fn exec(path: &str) -> ! {
let mut pathbuf = super::str_to_cstr(path); let mut pathbuf = format!("{}\0", path);
unsafe { unsafe {
epic_exec(pathbuf.as_mut_ptr()); epic_exec(pathbuf.as_mut_ptr());
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment