[klibc] [PATCH] getopt

Thayne Harbaugh tharbaugh at lnxi.com
Tue Jan 4 22:34:10 PST 2005


Patch to guarantee __optptr initialization and to correctly increment
optind for missing arguments.

--- klibc-0.194/klibc/getopt.c.orig	2005-01-04 23:18:50.229222640 -0700
+++ klibc-0.194/klibc/getopt.c	2005-01-04 23:17:05.236184008 -0700
@@ -11,7 +11,7 @@
 char *optarg;
 int optind = 1;
 int opterr, optopt;
-static const char *__optptr;
+static const char *__optptr = NULL;
 
 int getopt(int argc, char * const *argv, const char *optstring)
 {
@@ -51,6 +51,7 @@
 	  optind += 2;
 	} else {
 	  /* Missing argument */
+	  optind++;
 	  return (optstring[0] == ':') ? ':' : '?';
 	}
       }


-- 
Thayne Harbaugh
Linux Networx
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : http://www.zytor.com/pipermail/klibc/attachments/20050104/06d024a0/attachment.bin


More information about the klibc mailing list