Implement getopt via getopt_long to support glibc-style non-options before options

Musl's getopt follows the POSIX standard and stops parsing options
when it finds the first non-option argument.  Glibc by default will
continue parsing options, permuting all non-option arguments to the
end of argv.  This behavior is visible to users of command line tools
that use getopt.  To avoid breaking existing usages of command line
tools reimplement getopt via getopt_long, which is a glibc extension
and already includes the permuting logic.  The original getopt is
renamed to __posix_getopt, replacing the existing __posix_getopt weak
symbol.

Test: debugfs_static foo -h prints help message
Test: POSIXLY_CORRECT=1 debugfs_static foo -h tries to open foo
Change-Id: I5890312a07659c3f0706a6ac8c4a49a43e9c84c8
2 files changed