libargs 0.1.2

Get CLI arguments in a library called from C
Documentation
  • Coverage
  • 100%
    2 out of 2 items documented0 out of 0 items with examples
  • Size
  • Source code size: 6.32 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.1 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 9s Average build duration of successful builds.
  • all releases: 9s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • leo60228/libargs
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • leo60228

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-standard
  • cfg(all(target_os = "linux", not(target_env = "gnu"))): The envp 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 find argc and argv. 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.