In POSIX, can a main(void) recover command line arguments?
In C, is int main(int argc, char *argv[])
really needed to receive program arguments? In other words, when defining the main function with the signature int main(void)
, is it possible to recover the program arguments using only POSIX interfaces?
I feel like I'm missing something, seeing that:
unsetenv()
) and host identification ( gethostid()
). GetCommandLineW
and CommandLineToArgvW
functions, and HP-UX supplies the global variables __argc_value
and __argv_value
. Linux has /proc/self/cmdline
, which can be parsed into argv
and argc
. POSIX specifications do not include functions that can retrieve command line arguments. All of the specified functions require, essentially, main()
to orchestrate passing argc
and argv
to be parsed.
POSIX specifications (IEEE 1003.1, 2013 edition - the current version as I write this) has a section describing the command line syntax used by the Standard Utilities (which are described in the "Shell and Utilities" volume). However, those utilities - naturally enough - would use POSIX functions, so would be implemented with a main(argc, argv)
that calls them.