|
|
Subscribe / Log in / New account

Ushering out strlcpy()

Ushering out strlcpy()

Posted Aug 30, 2022 15:26 UTC (Tue) by mathstuf (subscriber, #69389)
In reply to: Ushering out strlcpy() by andy_shev
Parent article: Ushering out strlcpy()

I don't see the connection. The general purpose `std::string::String` might not work in all contexts, but there is a *lot* of code that doesn't work in such contexts anyways. The kernel is certainly free to make its own String which can be used from interrupts and such (with appropriate error handling of course); there's nothing magic about String in Rust and is "just" library code.


to post comments

Ushering out strlcpy()

Posted Aug 30, 2022 17:33 UTC (Tue) by tialaramex (subscriber, #21167) [Link]

The kernel does have its own String:

https://rust-for-linux.github.io/docs/alloc/string/struct.String.html

Here's the equivalent Rust standard String (well, alloc::string::String, userspace Rust programmers would use it from std but it's equivalent)

https://doc.rust-lang.org/alloc/string/struct.String.html

You'll notice that the standard String has a lot of stuff that the kernel doesn't. And the kernel only has try_reserve() so you can't just go around reserve()ing memory which might not exist as userspace programmers often do.

The kernel has (or will eventually get) all of core, the Rust library where core language features that are not just inside the compiler live, so that's stuff like an Option type, a Result type, most of the methods you think about for built-in types. But it doesn't have std, the library where OS depending features like File I/O and Networking live, and it has its own rather different alloc, a library where the allocator and related features (such as a growable String) live.


Copyright © 2025, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds