Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libc/stdlib Be SUS-conformant regarding return value whe...



details:   https://anonhg.NetBSD.org/src/rev/a4adc9b38020
branches:  trunk
changeset: 499684:a4adc9b38020
user:      wiz <wiz%NetBSD.org@localhost>
date:      Sun Nov 26 23:39:11 2000 +0000

description:
Be SUS-conformant regarding return value when option argument is missing.
Handle "-" correctly.

diffstat:

 lib/libc/stdlib/getopt_long.c |  14 ++++++--------
 1 files changed, 6 insertions(+), 8 deletions(-)

diffs (70 lines):

diff -r a56b8b4f4bd3 -r a4adc9b38020 lib/libc/stdlib/getopt_long.c
--- a/lib/libc/stdlib/getopt_long.c     Sun Nov 26 22:35:53 2000 +0000
+++ b/lib/libc/stdlib/getopt_long.c     Sun Nov 26 23:39:11 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: getopt_long.c,v 1.8 2000/08/25 17:05:49 thorpej Exp $  */
+/*     $NetBSD: getopt_long.c,v 1.9 2000/11/26 23:39:11 wiz Exp $      */
 
 /*-
  * Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -38,7 +38,7 @@
 
 #include <sys/cdefs.h>
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: getopt_long.c,v 1.8 2000/08/25 17:05:49 thorpej Exp $");
+__RCSID("$NetBSD: getopt_long.c,v 1.9 2000/11/26 23:39:11 wiz Exp $");
 #endif /* LIBC_SCCS and not lint */
 
 #include "namespace.h"
@@ -76,7 +76,8 @@
 
 /* return values */
 #define        BADCH   (int)'?'
-#define        BADARG  (int)':'
+#define        BADARG          ((IGNORE_FIRST && options[1] == ':') \
+                        || (*options == ':') ? (int)':' : (int)'?')
 #define INORDER (int)1
 
 #define        EMSG    ""
@@ -212,7 +213,8 @@
                        nonopt_start = nonopt_end = -1;
                        return -1;
                }
-               if (*(place = nargv[optind]) != '-') {  /* found non-option */
+               if ((*(place = nargv[optind]) != '-')
+                   || (place[1] == '\0')) {    /* found non-option */
                        place = EMSG;
                        if (IN_ORDER) {
                                /*
@@ -270,7 +272,6 @@
                        if (PRINT_ERROR)
                                warnx(recargchar, optchar);
                        optopt = optchar;
-                       /* XXX: GNU returns '?' if options[0] != ':' */
                        return BADARG;
                } else                          /* white space */
                        place = nargv[optind];
@@ -294,7 +295,6 @@
                                if (PRINT_ERROR)
                                        warnx(recargchar, optchar);
                                optopt = optchar;
-                               /* XXX: GNU returns '?' if options[0] != ':' */
                                return BADARG;
                        } else
                                optarg = nargv[optind];
@@ -426,7 +426,6 @@
                                        optopt = long_options[match].val;
                                else
                                        optopt = 0;
-                               /* XXX: GNU returns '?' if options[0] != ':' */
                                return BADARG;
                        }
                        if (long_options[match].has_arg == required_argument ||
@@ -458,7 +457,6 @@
                                        optopt = long_options[match].val;
                                else
                                        optopt = 0;
-                               /* XXX: GNU returns '?' if options[0] != ':' */
                                --optind;
                                return BADARG;
                        }



Home | Main Index | Thread Index | Old Index