On Jan 16, 2008 2:35 PM, Sebastian Reitenbach
<[EMAIL PROTECTED]> wrote:
> I run into troubles with getopt(3). the test program below shows the
> problem. It produces different output on Linux and OpenBSD, when it is
> called like this on Linux it looks like this:
>
> ./a.out asdf -n
> option char: 110, n

That behavior does not comply with the POSIX and Single Unix
specifications.  In particular, it violates the logic described at
    http://www.opengroup.org/onlinepubs/000095399/functions/getopt.html

(c.f. the text that start "If, when getopt() is called:")

The good news is that the getopt() in GNU libc will conform if your
environment contains the variable POSIXLY_CORRECT.  The bad news is
that it isn't the default.


> on OpenBSD, getopt returns -1 and no output is shown.

Right, because OpenBSD's getopt() always conforms to the standard.


> what would be the best way to make it work on OpenBSD?

Since "make it work" would involve violating the POSIX standard, the
answer is "you can't".

The real solution is to generate portable command invocations by
passing options before operands.


Philip Guenther

Reply via email to