getopt and dbus

Axel Liljencrantz liljencrantz at gmail.com
Thu Dec 28 09:00:25 PST 2006


On 12/28/06, Havoc Pennington <hp at redhat.com> wrote:
> Axel Liljencrantz wrote:
> > Would patches for using getopt be accepted?
> >
>
> You can't just use getopt because at least getopt_long is not portable.
> The minimum patch would be to include some kind of portable option
> parser and fall back to the system copy. I imagine the GNU tools are set
> up in the usual "replacement copy of gnu libc stuff" way to do this. For
> dbus you'd probably need to arrange to have an additional tiny libtool
> convenience library with getopt_long in it.

Plain getopt is part of Posix (See
http://www.opengroup.org/onlinepubs/009695399/functions/getopt.html).
getopt_long is originally a GNU extension but is supported by various
OSes, including NetBSD and FreeBSD.

In my opinion, using getopt_long and writing a fallback implementation
that uses 'plain' getopt and hence does not support long switches
should be good enough, portability wise. In order to implement this,
one would have to make sure that every long-style switch has a
short-style equivalent, something that is a good idea to do anyway.

If that solution is in fact not good enough, it is also possible to
include the GNU implementation of getopt_long with dbus and compile it
into every dbus program if the os does not supply you with a
getopt_long version of its own.

>
> Havoc
>

-- 
Axel


More information about the dbus mailing list