[freetds] getopt compatibility

ZIGLIO, Frediano, VF-IT Frediano.Ziglio at vodafone.com
Mon May 26 10:45:01 EDT 2008


Hi,
  I found a portability problem using getopt in src/apps/tsql.c. 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. This cause options to not get readed. I tried to write a
small test under Linux (which should use GNU getopt) and initial optind
is 1. It seems that initial value of optind is 1 however to correctly
restart getopt you have to set optind to 0 (there are some additional
status variable to reset). 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?? 
- try to detect HP-UX and reset optind with 1?
- use GNU getopt library under HP-UX?
- do not use getopt in get_opt_flags function cause it just support only
parameters without arguments?
- reset optind to 0 and set argv[0] to argv[1] (I have still to test
this cheat..) ?

Frediano



More information about the FreeTDS mailing list