From 66013e8440dbaddd01711e4aefca2601746581e4 Mon Sep 17 00:00:00 2001 From: pfg Date: Sun, 22 Jun 2014 20:13:57 +0000 Subject: getopt(3): recognize option:: as GNU extension for "optional options". Also ANSIfy a function declaration. While here update the OpenBSD patch level in getopt_long.c as we already have the corresponding change. Obtained from: NetBSD MFC after: 2 weeks --- lib/libc/stdlib/getopt.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'lib/libc/stdlib/getopt.c') diff --git a/lib/libc/stdlib/getopt.c b/lib/libc/stdlib/getopt.c index b9d2ae3..3929b32 100644 --- a/lib/libc/stdlib/getopt.c +++ b/lib/libc/stdlib/getopt.c @@ -1,4 +1,4 @@ -/* $NetBSD: getopt.c,v 1.26 2003/08/07 16:43:40 agc Exp $ */ +/* $NetBSD: getopt.c,v 1.29 2014/06/05 22:00:22 christos Exp $ */ /* * Copyright (c) 1987, 1993, 1994 @@ -59,10 +59,7 @@ char *optarg; /* argument associated with option */ * Parse argc/argv argument vector. */ int -getopt(nargc, nargv, ostr) - int nargc; - char * const nargv[]; - const char *ostr; +getopt(int nargc, char * const nargv[], const char *ostr) { static char *place = EMSG; /* option letter processing */ char *oli; /* option letter list index */ @@ -115,6 +112,12 @@ getopt(nargc, nargv, ostr) entire next argument. */ if (*place) optarg = place; + else if (oli[2] == ':') + /* + * GNU Extension, for optional arguments if the rest of + * the argument is empty, we return NULL + */ + optarg = NULL; else if (nargc > ++optind) optarg = nargv[optind]; else { -- cgit v1.1