Linux kernel module for left-padding strings. In Rust.
I've been contemplating making something in Rust for a while, and now that Rust in The Kernel is all the rage FOMO kicked in I guess?
So this is my Rust hello world.
On Ubuntu 20.04:
sudo apt install build-essential llvm clang-11 linux-headers-"$(uname -r)" curl
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
rustup default nightly
rustup component add --toolchain=nightly rust-src rustfmt
cd leftpad
make CC=clang-11
make loadWrite the target len, the padding char and the string-to-be-padded, separated by spaces into the leftpad file.
Read the padded string back from the file.
echo 3 0 7 > /dev/leftpad
cat /dev/leftpadMind the newline...
echo -n 3 0 7 > /dev/leftpad
cat /dev/leftpad; echoAkchually, the padding char can be a string.
echo 16 na ' batman!' > /dev/leftpad
cat /dev/leftpadIt supports UTF-8 at a certain extent: the target length is measured in Unicode Scalar Value units, so it might not does exactly what you expect, but it works if you dont push it too hard.
echo 16 💩 psicle > /dev/leftpad
cat /dev/leftpadThe general intent was to mimic the operation of JavaScrip padStart()
Q: But https://github.com/Rust-for-Linux/linux?
A: Yes!
Q: But the write ignores the offset!
A: Yes!
Q: But it's racy!
A: Yes!
Q: You should have used sysctl!
A: LOL!
https://lkml.org/lkml/2016/3/31/1176
https://github.com/fishinabarrel/linux-kernel-module-rust
jbaublitz/knock-out#9
jbaublitz/knock-out#11
lizhuohua/linux-kernel-module-rust#1