On Mon, Jan 07, 2019 at 06:50:53PM +0100, Max Reitz wrote: [...] I don't particularly care how we fix this, but it breaks the nbdkit tests on FreeBSD so I am keen to fix it one way or another.
> And if optreset not being available for glibc is the only issue, I'd say > adding it as a weak global variable would work without #ifdefs. The weak global variable doesn't make the code "#ifdef free". I tried a patch like this: +int optreset __attribute__((weak)); ... static int command(...) { ... optind = 0; + optreset = 1; ... } but that still doesn't work on FreeBSD. You have to set optind=1 apparently. So if we want to set optreset=1 we still end up with #ifdef __FreeBSD__. The final patch will end up looking something like: static int command(...) { ... +#ifdef __FreeBSD__ + optind = 1; + optreset = 1; +#else optind = 0; +#endif ... } If you want me to submit a formal patch like this let me know. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com libguestfs lets you edit virtual machines. Supports shell scripting, bindings from many languages. http://libguestfs.org