forked from trussed-dev/littlefs2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Document no_std gotchas, provide c-stubs
- Loading branch information
Showing
4 changed files
with
54 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
[package] | ||
name = "littlefs2" | ||
description = "Idiomatic Rust API for littlefs" | ||
version = "0.3.1" | ||
version = "0.3.2" | ||
authors = ["Nicolas Stalder <[email protected]>", "Brandon Edens <[email protected]>"] | ||
edition = "2018" | ||
license = "Apache-2.0 OR MIT" | ||
|
@@ -43,6 +43,7 @@ dir-entry-path = [] | |
ll-assertions = ["littlefs2-sys/assertions"] | ||
# enable trace in backend C code | ||
ll-trace = ["littlefs2-sys/trace"] | ||
c-stubs = [] | ||
|
||
log-all = [] | ||
log-none = [] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
//! C functions not provided by compiler-builtins | ||
//! | ||
//! Use this instead of linking to libc if you only need a handful of free functions | ||
use cty::{c_char, c_void, size_t}; | ||
|
||
extern "C" { | ||
// provided by `compiler-builtins` | ||
fn memcpy(dst: *mut c_void, src: *const c_void, n: size_t) -> *mut c_void; | ||
} | ||
|
||
/// # Safety | ||
/// - `src` must be a valid C string (null terminated) | ||
/// - `dst` must be large enough to hold `src` | ||
#[no_mangle] | ||
unsafe fn strcpy(dst: *mut c_char, src: *const c_char) -> *mut c_char { | ||
memcpy(dst as *mut c_void, src as *const c_void, strlen(src)) as *mut c_char | ||
} | ||
|
||
/// # Safety | ||
/// `s` must point to valid memory; `s` will be treated as a null terminated string | ||
pub unsafe fn strlen(mut s: *const c_char) -> size_t { | ||
let mut n = 0; | ||
while *s != 0 { | ||
s = s.add(1); | ||
n += 1; | ||
} | ||
n | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters