How about this one? Add a generic osdep function for reinitializing optind, which does optreset on FreeBSD (but is identical on all other OSes). Use it from qemu-io and qemu-img.
I have tested this on Linux, FreeBSD and OpenBSD. checkpatch complains: WARNING: Block comments use a leading /* on a separate line #69: FILE: include/qemu/osdep.h:591: +/** WARNING: architecture specific defines should be avoided #78: FILE: include/qemu/osdep.h:600: +#ifdef __FreeBSD__ total: 0 errors, 2 warnings, 44 lines checked but as far as I'm aware I've followed the correct formatting and guidelines. Rich.