]> git.ipfire.org Git - thirdparty/qemu.git/commit
qemu-img: resize: do not always eat last argument
authorMichael Tokarev <mjt@tls.msk.ru>
Sat, 31 May 2025 17:16:01 +0000 (20:16 +0300)
committerKevin Wolf <kwolf@redhat.com>
Tue, 15 Jul 2025 18:49:01 +0000 (20:49 +0200)
commit8737b342e236c8cf5e4ae1f5cc0f519a23a6dd2b
tree2038a5b3c001934290c90c02f080325d51b78da4
parentc1563952521d4d5947b4279efe8dcc432791287e
qemu-img: resize: do not always eat last argument

'qemu-img resize --help' does not work, since it wants more
arguments.  Also -size is only recognized as a very last
argument, but it is common for tools to handle other options
after positional arguments too.

Tell getopt_long() to return non-options together with options,
and process filename and size in the loop, and check if there's
an argument right after filename which looks like -N (number),
and treat it as size (decrement).  This way we can handle --help,
and we can also have options after filename and size, and `--'
will be handled fine too.

The only case which is not handled right is when there's an option
between filename and size, and size is given as decrement, - in
this case -size will be treated as option, not as size.

Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
Message-ID: <20250531171609.197078-20-mjt@tls.msk.ru>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
qemu-img.c