Extract getopt and friends to <bits/getopt.h>

Bug: http://b/28067717
Change-Id: If19653d0da8b964c43768aa1051f9c926b3c6acb
diff --git a/libc/include/bits/getopt.h b/libc/include/bits/getopt.h
new file mode 100644
index 0000000..7153d48
--- /dev/null
+++ b/libc/include/bits/getopt.h
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef _BITS_GETOPT_H_
+#define _BITS_GETOPT_H_
+
+#include <sys/cdefs.h>
+
+__BEGIN_DECLS
+
+int	 getopt(int, char * const [], const char *);
+
+extern char *optarg;			/* getopt(3) external variables */
+extern int optind, opterr, optopt;
+
+__END_DECLS
+
+#endif
diff --git a/libc/include/getopt.h b/libc/include/getopt.h
index 4451941..46d2eb7 100644
--- a/libc/include/getopt.h
+++ b/libc/include/getopt.h
@@ -35,9 +35,10 @@
 
 #include <sys/cdefs.h>
 
+#include <bits/getopt.h>
+
 /*
  * GNU-like getopt_long()/getopt_long_only() with 4.4BSD optreset extension.
- * getopt() is declared here too for GNU programs.
  */
 #define no_argument        0
 #define required_argument  1
@@ -62,13 +63,7 @@
 	const struct option *, int *);
 int	getopt_long_only(int, char * const *, const char *,
 	const struct option *, int *);
-#ifndef _GETOPT_DECLARED
-#define	_GETOPT_DECLARED
-int	 getopt(int, char * const [], const char *);
 
-extern char *optarg;			/* getopt(3) external variables */
-extern int optind, opterr, optopt;
-#endif
 #ifndef _OPTRESET_DECLARED
 #define	_OPTRESET_DECLARED
 extern int optreset;			/* getopt(3) external variable */
diff --git a/libc/include/unistd.h b/libc/include/unistd.h
index b6046be..725cef5 100644
--- a/libc/include/unistd.h
+++ b/libc/include/unistd.h
@@ -36,6 +36,7 @@
 #include <sys/sysconf.h>
 
 #include <bits/fcntl.h>
+#include <bits/getopt.h>
 #include <bits/ioctl.h>
 #include <bits/lockf.h>
 #include <bits/posix_limits.h>
@@ -207,10 +208,6 @@
 extern int brk(void* __addr);
 extern void* sbrk(ptrdiff_t __increment);
 
-extern int getopt(int __argc, char* const* __argv, const char* __argstring);
-extern char* optarg;
-extern int optind, opterr, optopt;
-
 extern int isatty(int __fd);
 extern char* ttyname(int __fd);
 extern int ttyname_r(int __fd, char* __buf, size_t __buflen) __INTRODUCED_IN(8);