Haven't found anything useful on this.
I'm porting C code to Rust and I need to use some functions like strncpy.
As I'm on no_std it's not easy to use FFI with those. I haven't found any working code for this.
-Is there any workaround?
-Are there equivalent functions I could use?
It’s not quite clear what exactly you imagine by “some function like strncpy”. Are you working with safe Rust code? What’s your string represenation? (Null-terminated strings aren’t really used all that much in Rust). Are you mentioning FFI because you consider using libc directly (the libc crate can be used with
no_std, so the low-level FFI bindings already exist; but I don’t know what kinds of platforms you’re targeting / I’m unfamiliar with Rust on embedded anyways and don’t know whether or not the libc crate works on embedded platforms).
In any case, if you could more accurately describe the kind of API you’re after (e.g. the function signature) then it’s probably straightforward, at least for simple stuff like a “strncpy equivalent”, to come up with a definition just in terms of
I'm targeting a Cortex M4
Don't know what string representation i use
Well, let's say I want to use strncpy
here from libc
pub unsafe extern "C" fn strncpy(
dst: *mut [c_char]
src: *const [c_char]
) -> *mut [c_char]
Sorry for being imprecise, I'm kinda new to the whole topic.
I want to copy a given key via strncpy (working with psa crypto r.n.)
In this case I thought i'll just straight use the copy mechanism via FFI(strncpy) or use a equivalent
This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.