[ipxe-devel] [PATCH] Accept '--' as an end-of-options marker in getopt()

Marin Hannache mareo at mareo.fr
Tue Nov 1 15:59:18 UTC 2011


Hello,

I recently tried to print a full line of '-' with echo, which is
impossible due to option parsing in iPXE : actually, everything
beginning with a '-' is treated as an option.

So i wrote a little patch in order to recognize an empty long option
("--") as an end-of-options marker, in order to be able to echo such
lines.

With this four-line patch, you can now write "echo -- ----" which prints
"----" as expected.

I hope this will be useful to someone. :)

Regards
-- 
Marin "Mareo" Hannache
mareo at mareo.fr
-------------- next part --------------
--- ipxe/src/core/getopt.c	2011-11-01 17:09:37.892495885 +0100
+++ ./getopt.c	2011-11-01 17:09:55.635828985 +0100
@@ -239,6 +239,11 @@
 
 	/* Check for long options */
 	if ( *(opttext++) == '-' ) {
+		/* "--" indicate end of options */
+		if ( *opttext == '\0' ) {
+			++optind;
+			return -1;
+		}
 		for ( longopt = longopts ; longopt->name ; longopt++ ) {
 			if ( ! match_long_option ( argc, argv, opttext,
 						   longopt, &option ) )


More information about the ipxe-devel mailing list