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

Bug#411635: libc6-i686: getopt_long_only: short vs long option ambiguity



Package: libc6-i686
Version: 2.3.6.ds1-11
Severity: normal

Hi,

`getopt_long_only' sees a long option where there is a short one.

A program handling both `-m' and `--mask' options, should never interpret
`-m' (`-mas' or `-ma') as `--mask'.

$ cat test.c
#include <getopt.h>
#include <stdio.h>

int
main(int argc, char *argv[])
{
 int c = 0;
 struct option long_options[] = {
   {"mask", no_argument, NULL, 0},
   {0, 0, 0, 0}
 };
 int option_index = 0;

 printf("Received options:\n");
 while ((c = getopt_long_only(argc, argv, "am", long_options,
			       &option_index)) != -1) {
   switch (c) {
   case 0:
     printf("  --%s\n", long_options[option_index].name);
     break;

   default:
     printf("  -%c\n", c);
   }
 }

 if (optind < argc) {
   printf("Non-option arguments:\n");
   while (optind < argc)
     printf("  %s\n", argv[optind++]);
 }

 return 0;
}

$ gcc -g -Wall -W -o test test.c && ./test -am
Received options:
 -a
 --mask

Expected options are `-a' and `-m'. No `--mask' was passed.

Regards,

VVV


-- System Information:
Debian Release: 4.0
 APT prefers testing
 APT policy: (500, 'testing')
Architecture: i386 (i686)
Shell:  /bin/sh linked to /bin/bash
Kernel: Linux 2.6.18-3-686
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)

Versions of packages libc6-i686 depends on:
ii  libc6                       2.3.6.ds1-11 GNU C Library: Shared libraries

libc6-i686 recommends no packages.

-- no debconf information



Reply to: