summaryrefslogtreecommitdiffstats
path: root/include/getopt.h
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2007-07-05 18:01:39 +0200
committerSascha Hauer <sha@octopus.labnet.pengutronix.de>2007-07-05 18:01:39 +0200
commit488afcc90d921b3f4f954b044ae4bbd87d090beb (patch)
tree2978aaff32bbe9ebaf583d3cf59005a7d89fb880 /include/getopt.h
parenteaff0679f342d9dd36827b4df0326aa54747812e (diff)
downloadbarebox-488afcc90d921b3f4f954b044ae4bbd87d090beb.tar.gz
barebox-488afcc90d921b3f4f954b044ae4bbd87d090beb.tar.xz
svn_rev_282
add getopt(3) implementation
Diffstat (limited to 'include/getopt.h')
-rw-r--r--include/getopt.h49
1 files changed, 49 insertions, 0 deletions
diff --git a/include/getopt.h b/include/getopt.h
new file mode 100644
index 0000000000..4f43ac4098
--- /dev/null
+++ b/include/getopt.h
@@ -0,0 +1,49 @@
+/*
+ * getopt.h - a simple getopt(3) implementation.
+ *
+ * Copyright (c) 2007 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef __GETOPT_H
+#define __GETOPT_H
+
+extern int opterr;
+extern int optind;
+extern int optopt;
+extern char *optarg;
+
+/*
+ * Simple getopt(3) implementation.
+ * This version of getopt does not take long options but should
+ * otherwise behave like one expects.
+ *
+ * - It takes ':' in optstring for required arguments and '::'
+ * for optional arguments.
+ * - arguments can be followed directly by optargs (like -loptarg)
+ * or in the next argv[] element (like -l optarg).
+ * - arguments can be grouped together (like ls -alR)
+ * - options can be mixed with nonoptions (like ls /bin -R)
+ */
+
+int getopt(int argc, char *argv[], char *optstring);
+
+/*
+ * We do not start a new process for each getopt() run, so we
+ * need this function to reset the static variables.
+ */
+void getopt_reset(void);
+
+#endif /* __GETOPT_H */