And we made a short program with it, that simply opened a file, mapped it in
memory, and read part of it.
But we have a slight problem. Normally we'd use a crate to parse arguments,
that would in turn use something like
std::env::args
, which
is provided by libstd
, which we don't have.
We know where command-line arguments are hiding though! Much like regular
function arguments, they're hiding... on the stack. Well... beneath the stack.
Or above it, since it grows down. It's all about perspective.
First, since both CLI (command-line interface) arguments and environment
variables are null-terminated strings, and we only want to deal with &str
,
which are nice, fast, and safe slices, we're going to want some sort of
conversion routine.
The conversion itself is not that safe: our input is a random memory address
which we directly start reading from. We can't tell what we're reading, we
just stop at the first null byte. We might even be reading past mapped
memory, and could cause a segmentation fault.
This is just one of those case where we'll have to, as they say, "just wing it".
I know, I know. We normally go about these things iteratively. But there's not
much mystery left to this part. We've done the fancy diagram before: