summaryrefslogtreecommitdiff
path: root/klibc/klibc/tests/getopttest.c
diff options
context:
space:
mode:
Diffstat (limited to 'klibc/klibc/tests/getopttest.c')
-rw-r--r--klibc/klibc/tests/getopttest.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/klibc/klibc/tests/getopttest.c b/klibc/klibc/tests/getopttest.c
new file mode 100644
index 0000000000..90ceaa2c58
--- /dev/null
+++ b/klibc/klibc/tests/getopttest.c
@@ -0,0 +1,31 @@
+/*
+ * getopttest.c
+ *
+ * Simple test for getopt, set the environment variable GETOPTTEST
+ * to give the argument string to getopt()
+ */
+
+#include <stdlib.h>
+#include <unistd.h>
+#include <stdio.h>
+
+int main(int argc, char * const *argv)
+{
+ const char *parser;
+ char showchar[] = "\'?\'";
+ int c;
+
+ parser = getenv("GETOPTTEST");
+ if ( !parser ) parser = "abzf:o:";
+
+ do {
+ c = getopt(argc, argv, parser);
+ showchar[1] = c;
+ printf("c = %s, optind = %d (%s), optarg = \"%s\", optopt = \'%c\'\n",
+ (c == EOF) ? "EOF" : showchar,
+ optind, argv[optind], optarg, optopt);
+ } while ( c != -1 );
+
+ return 0;
+}
+