initial import
[platform/upstream/glibc.git] / posix / tstgetopt.c
1 #include <ansidecl.h>
2 #include <unistd.h>
3 #include <stdio.h>
4
5 int main (int argc, char **argv)
6 {
7   int aflag = 0;
8   int bflag = 0;
9   char *cvalue = NULL;
10   int index;
11   int c;
12
13   while ((c = getopt (argc, argv, "abc:")) >= 0)
14     switch (c) {
15     case 'a':
16       aflag = 1;
17       break;
18     case 'b':
19       bflag = 1;
20       break;
21     case 'c':
22       cvalue = optarg;
23       break;
24     case '?':
25 #if 0
26       fprintf (stderr, "Unknown option %c.\n", optopt);
27 #else
28       fputs ("Unknown option.\n", stderr);
29 #endif
30       return -1;
31     default:
32       fprintf (stderr, "This should never happen!\n");
33       return -1;
34     }
35
36   printf ("aflag = %d, bflag = %d, cvalue = %s\n", aflag, bflag, cvalue);
37
38   for (index = optind; index < argc; index++)
39     printf ("Non-option argument %s\n", argv[index]);
40   return 0;
41 }