chiark / gitweb /
[PATCH] added klibc version 0.82 (cvs tree) to the udev tree.
[elogind.git] / klibc / klibc / tests / getopttest.c
1 /*
2  * getopttest.c
3  *
4  * Simple test for getopt, set the environment variable GETOPTTEST
5  * to give the argument string to getopt()
6  */
7
8 #include <stdlib.h>
9 #include <unistd.h>
10 #include <stdio.h>
11
12 int main(int argc, char * const *argv)
13 {
14   const char *parser;
15   char showchar[] = "\'?\'";
16   int c;
17
18   parser = getenv("GETOPTTEST");
19   if ( !parser ) parser = "abzf:o:";
20
21   do {
22     c = getopt(argc, argv, parser);
23     showchar[1] = c;
24     printf("c = %s, optind = %d (%s), optarg = \"%s\", optopt = \'%c\'\n",
25            (c == EOF) ? "EOF" : showchar,
26            optind, argv[optind], optarg, optopt);
27   } while ( c != -1 );
28   
29   return 0;
30 }
31