bump for release
[uclibc-ng.git] / test / unistd / getopt.c
blob401765cc82b708b80034f097504dbc60a6ceb902
1 /* Getopt tests */
3 #include <stdio.h>
4 #include <string.h>
5 #include <stdlib.h>
6 #include <getopt.h>
9 int main (int argc, char **argv)
11 int c;
12 int digit_optind = 0;
14 while (1)
16 int this_option_optind = optind ? optind : 1;
18 c = getopt (argc, argv, "abc:d:0123456789");
19 if (c == EOF)
20 break;
22 switch (c)
24 case '0':
25 case '1':
26 case '2':
27 case '3':
28 case '4':
29 case '5':
30 case '6':
31 case '7':
32 case '8':
33 case '9':
34 if (digit_optind != 0 && digit_optind != this_option_optind)
35 printf ("digits occur in two different argv-elements.\n");
36 digit_optind = this_option_optind;
37 printf ("option %c\n", c);
38 break;
40 case 'a':
41 printf ("option a\n");
42 break;
44 case 'b':
45 printf ("option b\n");
46 break;
48 case 'c':
49 printf ("option c with value `%s'\n", optarg);
50 break;
52 case '?':
53 break;
55 default:
56 printf ("?? getopt returned character code 0%o ??\n", c);
60 if (optind < argc)
62 printf ("non-option ARGV-elements: ");
63 while (optind < argc)
64 printf ("%s ", argv[optind++]);
65 printf ("\n");
67 exit (0);