2 releases
0.1.2 | Nov 20, 2019 |
---|---|
0.1.1 |
|
0.1.0 | Nov 20, 2019 |
#855 in Command-line interface
6KB
87 lines
libargs
On most Rust platforms, std::env::args
will work in a function called from a C program. However, this is not the case on Linux. The following platforms are supported:
cfg(all(target_os = "linux", target_env = "gnu"))
: glibc will pass command line arguments to static constructors, which is non-standardcfg(all(target_os = "linux", not(target_env = "gnu")))
: Theenvp
pointer passed to_start
is stored in the__environ
symbol. As command line arguments precede it in the stack, we can walk the stack backwards from__environ
to findargc
andargv
. This works on all platforms I've tested it on, however it takes linear time with regards to argc.cfg(not(target_os = "linux"))
:std::env::args
is used, which works on most platforms (including Windows and macOS). On unsupported platforms, an empty Vec will be returned.
lib.rs
:
See documentation on args
.
Dependencies
~49KB