This is the mail archive of the
newlib@sourceware.org
mailing list for the newlib project.
Re: [PATCH] getopt: Bug fix. Initialize optind
On 7/18/06, Dave Korn <dave.korn@artimi.com> wrote:
On 17 July 2006 23:58, Shaun Jackman wrote:
> On 7/7/06, Shaun Jackman <sjackman@gmail> wrote:
>> If getopt is called with optind == 0 and argc == 1, the EOF case is
>> not detected. optind should be initialized before testing for EOF.
>
> Comments?
:) How about a testcase?
I didn't even know newlib had a testsuite. What do you know. The
following is untested, but might do the trick.
Cheers,
Shaun
--- /dev/null 2006-07-17 08:59:47.153805432 -0600
+++ getopt.c 2006-07-18 11:25:43.000000000 -0600
@@ -0,0 +1,12 @@
+#include <getopt.h>
+#include <stdio.h>
+
+int main()
+{
+ int argc = 1;
+ char *argv[] = { "", NULL };
+ printf("%d\n", getopt(argc, argv, ""));
+ optind = 0;
+ printf("%d\n", getopt(argc, argv, ""));
+ return 0;
+}
--- /dev/null 2006-07-17 08:59:47.153805432 -0600
+++ getopt.exp 2006-07-18 11:27:10.000000000 -0600
@@ -0,0 +1,13 @@
+# Copyright (C) 2002 by Red Hat, Incorporated. All rights reserved.
+#
+# Permission to use, copy, modify, and distribute this software
+# is freely granted, provided that this notice is preserved.
+#
+
+load_lib checkoutput.exp
+
+set output {
+"-1\n-1\n"
+}
+
+newlib_check_output "getopt.c" "$output"