qemu-e2k/include/qemu
Richard W.M. Jones d339d766d1 qemu-io: Add generic function for reinitializing optind.
On FreeBSD 11.2:

  $ nbdkit memory size=1M --run './qemu-io -f raw -c "aio_write 0 512" $nbd'
  Parsing error: non-numeric argument, or extraneous/unrecognized suffix -- aio_write

After main option parsing, we reinitialize optind so we can parse each
command.  However reinitializing optind to 0 does not work on FreeBSD.
What happens when you do this is optind remains 0 after the option
parsing loop, and the result is we try to parse argv[optind] ==
argv[0] == "aio_write" as if it was the first parameter.

The FreeBSD manual page says:

  In order to use getopt() to evaluate multiple sets of arguments, or to
  evaluate a single set of arguments multiple times, the variable optreset
  must be set to 1 before the second and each additional set of calls to
  getopt(), and the variable optind must be reinitialized.

(From the rest of the man page it is clear that optind must be
reinitialized to 1).

The glibc man page says:

  A program that scans multiple argument vectors,  or  rescans  the  same
  vector  more than once, and wants to make use of GNU extensions such as
  '+' and '-' at  the  start  of  optstring,  or  changes  the  value  of
  POSIXLY_CORRECT  between scans, must reinitialize getopt() by resetting
  optind to 0, rather than the traditional value of 1.  (Resetting  to  0
  forces  the  invocation  of  an  internal  initialization  routine that
  rechecks POSIXLY_CORRECT and checks for GNU extensions in optstring.)

This commit introduces an OS-portability function called
qemu_reset_optind which provides a way of resetting optind that works
on FreeBSD and platforms that use optreset, while keeping it the same
as now on other platforms.

Note that the qemu codebase sets optind in many other places, but in
those other places it's setting a local variable and not using getopt.
This change is only needed in places where we are using getopt and the
associated global variable optind.

Signed-off-by: Richard W.M. Jones <rjones@redhat.com>
Message-id: 20190118101114.11759-2-rjones@redhat.com
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Max Reitz <mreitz@redhat.com>
2019-01-31 00:38:19 +01:00
..
acl.h avoid TABs in files that only contain a few 2019-01-11 15:46:56 +01:00
atomic128.h
atomic.h atomics: Set ATOMIC_REG_SIZE=8 for MIPS n32 2019-01-03 17:52:52 +01:00
base64.h
bcd.h
bitmap.h bitmap: provide to_le/from_le helpers 2017-09-22 14:11:25 +02:00
bitops.h
bswap.h
buffer.h
compiler.h linux-user: Fix compilation with clang 3.4 2019-01-22 06:26:31 +01:00
config-file.h
coroutine_int.h
coroutine.h
cpuid.h
crc32c.h
cutils.h cutils: Fix qemu_strtosz() & friends to reject non-finite sizes 2018-12-13 19:10:06 +01:00
drm.h
envlist.h
error-report.h
event_notifier.h
fifo8.h
fifo32.h
fprintf-fn.h
futex.h
hbitmap.h Revert "hbitmap: Add @advance param to hbitmap_iter_next()" 2019-01-15 18:26:50 -05:00
help_option.h
host-utils.h includes: Replace QEMU_GNUC_PREREQ with "__has_builtin || !defined(__clang__)" 2018-12-12 10:01:13 +01:00
id.h
int128.h
iov.h avoid TABs in files that only contain a few 2019-01-11 15:46:56 +01:00
iova-tree.h
jhash.h
job.h
lockable.h
log-for-trace.h
log.h
main-loop.h
memfd.h
mmap-alloc.h
module.h xen: add a mechanism to automatically create XenDevice-s... 2019-01-14 13:45:40 +00:00
notify.h
option_int.h qemu/queue.h: simplify reverse access to QTAILQ 2019-01-11 15:46:55 +01:00
option.h option: Make option help nicer to read 2018-11-05 15:17:48 +01:00
osdep.h qemu-io: Add generic function for reinitializing optind. 2019-01-31 00:38:19 +01:00
path.h
pmem.h
processor.h
qdist.h
qht.h
qsp.h
queue.h qemu/queue.h: simplify reverse access to QTAILQ 2019-01-11 15:46:55 +01:00
range.h range: add some more functions 2019-01-09 22:09:31 -02:00
ratelimit.h
rcu_queue.h qemu/queue.h: reimplement QTAILQ without pointer-to-pointers 2019-01-11 15:46:55 +01:00
rcu.h
readline.h
seqlock.h
sockets.h
stats64.h
sys_membarrier.h
systemd.h
thread-posix.h
thread-win32.h
thread.h include/qemu/thread.h: Document qemu_thread_atexit* API 2018-11-06 21:35:06 +01:00
throttle-options.h
throttle.h
timed-average.h
timer.h
typedefs.h ui/console: Remove PixelFormat from qemu/typedefs.h 2019-01-22 05:14:33 +01:00
unicode.h
units.h include: Add a comment to explain the origin of sizes' lookup table 2018-11-05 15:29:59 +01:00
uri.h
uuid.h
vfio-helpers.h Clean up includes 2018-12-20 10:29:08 +01:00
win_dump_defs.h
xattr.h
xxhash.h xxhash: match output against the original xxhash32 2018-12-17 06:04:44 +03:00