bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Bug-gnulib] getopt fix to prevent it from lying to the compiler abo


From: Paul Eggert
Subject: Re: [Bug-gnulib] getopt fix to prevent it from lying to the compiler about const
Date: Fri, 12 Nov 2004 12:57:33 -0800
User-agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (gnu/linux)

Bruno Haible <address@hidden> writes:

> Any ideas?

One simple solution would be to have different interfaces for the two
getopt cases.  E.g.:

int getopt (int, char * const *, char const *);
int getopt_long (int, char * const *, char const *,
                 struct option const *, int *);
int getopt_long_only (int, char * const *, char const *,
                      struct option const *, int *);

int getopt_permute (int, char **, char const *);
int getopt_long_permute (int, char **, char const *
                         struct option const *, int *);
int getopt_long_only_permute (int, char **, char const *,
                              struct option const *, int *);

Here I'm assuming that getopt, getopt_long, and getopt_long_only have
the signature and behavior as now (for backward compatibility
reasons), and that getopt_permute, getopt_long_permute, and
getopt_long_only_permute behave just like their existing cousins, but
have the correct prototype.

If we do this, programs that invoke getopt etc. with a leading "+" can
stay the way they are, and other programs (the majority of them) can
call getopt_permute etc.

> Can we detect whether the first character of the options string is a '+'
> through a ___builtin_constant_p call and use a function with appropriate
> prototype?

That sounds a bit tricky.  And in a few cases (e.g., date, sort) the
option string is not a constant.

> Is getopt() worth fiddling with at all? Most GNU programs use getopt_long,
> which doesn't have a semantics dictated by POSIX.

Several GNU programs call getopt() because they don't have long
options.  They include basename, chroot, cksum, dd, dirname, factor,
hostid, hostname, link, logname, nohup, printenv, pwd, sleep, sync,
tsort, unlink, uptime, users, whoami, and yes.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]