[freetds] getopt compatibility
James K. Lowden
jklowden at freetds.org
Mon May 26 11:36:05 EDT 2008
ZIGLIO, Frediano, VF-IT wrote:
> In tsql
> getopt is restarted to read options. It's currently restarted using GNU
> getopt way, that is setting optind with 0. However under *BSD there is a
> optreset to reset status. However I mainly got problems with HP-UX
> getopt... as you can read from
> http://docs.hp.com/en/B2355-60105/getopt.3C.html getopt get reset with 1
> as optind. ... From HP-UX manual it seems also that behavior
> of this getopt implementation is quite different as from my
> understanding it stops reading parameters at the first no-options one...
> How to fix this problem??
Looking at the code, I think the most portable choice -- and probably the
least work -- is to refactor tsql.c: call getopt(3) in only one place, and
don't reset optind/optreset.
(Curiously, I use tsql on NetBSD and have never noticed any problem.
Maybe that's because of the sequence I usually put the options in.)
I think refactoring is best because otherwise you need an autoconf test
for behavior (testing for HP/UX isn't the Right Thing) and a tds_getopt
with a bunch of #define macros. It would look like src/tds/net.c. :-(
Besides, the code will be easier to understand when all the options are
parsed in one place.
More information about the FreeTDS