[freetds] getopt reset fix

Christos Zoulas christos at zoulas.com
Mon Nov 30 15:09:31 EST 2009


Hello,

The options reset code seems to be busted. On systems that have optreset,
you need to set optreset = 1 and optind = 1 to properly restart parsing
options, for systems that don't, you need to only set optind = 0. To
duplicate

(echo select 1 && echo go) | tsql -o qh

The -o part will try to use getopt to parse the options and fail...

christos

Index: tsql.c
===================================================================
RCS file: freetds/src/apps/tsql.c,v
retrieving revision 1.15
diff -u -u -r1.15 tsql.c
--- tsql.c	17 Jun 2009 18:49:14 -0000	1.15
+++ tsql.c	30 Nov 2009 20:05:11 -0000
@@ -313,8 +313,10 @@
 {
 #ifdef HAVE_GETOPT_OPTRESET
 	optreset = 1;
-#endif
 	optind = 1;
+#else
+	optind = 0;
+#endif
 }
 
 /*



More information about the FreeTDS mailing list