]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Suppress messages if first character of optstring is a colon.
authorUlrich Drepper <drepper@redhat.com>
Fri, 11 Feb 2000 20:37:24 +0000 (20:37 +0000)
committerUlrich Drepper <drepper@redhat.com>
Fri, 11 Feb 2000 20:37:24 +0000 (20:37 +0000)
posix/getopt.c

index efd822358f86859ab7b2cf79a44810961edad018..dfff5212498b4702058d5315db5b70efbeab4f93 100644 (file)
@@ -3,7 +3,7 @@
    "Keep this file name-space clean" means, talk to drepper@gnu.org
    before changing it!
 
-   Copyright (C) 1987, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99
+   Copyright (C) 1987, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 2000
        Free Software Foundation, Inc.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -517,6 +517,12 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
      int *longind;
      int long_only;
 {
+  /* POSIX.2 requires that messages are not only suppressed if `opterr' is
+     zero but also if the first character of the `optstring' is a colon.  */
+  int print_errors = opterr;
+  if (optstring[0] == ':')
+    print_errors = 0;
+
   optarg = NULL;
 
   if (optind == 0 || !__getopt_initialized)
@@ -673,7 +679,7 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
 
       if (ambig && !exact)
        {
-         if (opterr)
+         if (print_errors)
            fprintf (stderr, _("%s: option `%s' is ambiguous\n"),
                     argv[0], argv[optind]);
          nextchar += strlen (nextchar);
@@ -694,7 +700,7 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
                optarg = nameend + 1;
              else
                {
-                 if (opterr)
+                 if (print_errors)
                    {
                      if (argv[optind - 1][1] == '-')
                        /* --option */
@@ -720,7 +726,7 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
                optarg = argv[optind++];
              else
                {
-                 if (opterr)
+                 if (print_errors)
                    fprintf (stderr,
                           _("%s: option `%s' requires an argument\n"),
                           argv[0], argv[optind - 1]);
@@ -747,7 +753,7 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
       if (!long_only || argv[optind][1] == '-'
          || my_index (optstring, *nextchar) == NULL)
        {
-         if (opterr)
+         if (print_errors)
            {
              if (argv[optind][1] == '-')
                /* --option */
@@ -777,7 +783,7 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
 
     if (temp == NULL || c == ':')
       {
-       if (opterr)
+       if (print_errors)
          {
            if (posixly_correct)
              /* 1003.2 specifies the format of this message.  */
@@ -811,7 +817,7 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
          }
        else if (optind == argc)
          {
-           if (opterr)
+           if (print_errors)
              {
                /* 1003.2 specifies the format of this message.  */
                fprintf (stderr, _("%s: option requires an argument -- %c\n"),
@@ -860,7 +866,7 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
            }
        if (ambig && !exact)
          {
-           if (opterr)
+           if (print_errors)
              fprintf (stderr, _("%s: option `-W %s' is ambiguous\n"),
                       argv[0], argv[optind]);
            nextchar += strlen (nextchar);
@@ -878,7 +884,7 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
                  optarg = nameend + 1;
                else
                  {
-                   if (opterr)
+                   if (print_errors)
                      fprintf (stderr, _("\
 %s: option `-W %s' doesn't allow an argument\n"),
                               argv[0], pfound->name);
@@ -893,7 +899,7 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
                  optarg = argv[optind++];
                else
                  {
-                   if (opterr)
+                   if (print_errors)
                      fprintf (stderr,
                               _("%s: option `%s' requires an argument\n"),
                               argv[0], argv[optind - 1]);
@@ -940,7 +946,7 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
              }
            else if (optind == argc)
              {
-               if (opterr)
+               if (print_errors)
                  {
                    /* 1003.2 specifies the format of this message.  */
                    fprintf (stderr,