Eric Blake <ebl...@redhat.com> writes: > On 3/1/21 9:28 AM, Paolo Bonzini wrote: >> If the first character of optstring is '-', then each nonoption argv >> element is handled as if it were the argument of an option with character >> code 1. This removes the reordering of the argv array, and enables usage >> of loc_set_cmdline to provide better error messages. >> >> Signed-off-by: Paolo Bonzini <pbonz...@redhat.com> >> --- >> storage-daemon/qemu-storage-daemon.c | 9 ++++----- >> 1 file changed, 4 insertions(+), 5 deletions(-) > > Nice. The man page for 'getopt_long' is unclear whether setting > POSIXLY_CORRECT in the environment would break this (that is, setting > POSIXLY_CORRECT has the same effect as a leading '+'; but you can't have > both leading '+' and leading '-' and when both are set, it is not clear > which one wins). But that's a corner case that I don't think will ever > bite us in real life. > > Reviewed-by: Eric Blake <ebl...@redhat.com>
I'd consider environment overruling the programmer's express intent a bug. GLibc's _getopt_initialize(): /* Determine how to handle the ordering of options and nonoptions. */ if (optstring[0] == '-') { d->__ordering = RETURN_IN_ORDER; ++optstring; } else if (optstring[0] == '+') { d->__ordering = REQUIRE_ORDER; ++optstring; } else if (posixly_correct || !!getenv ("POSIXLY_CORRECT")) d->__ordering = REQUIRE_ORDER; else d->__ordering = PERMUTE; No surprises here.