Clean up fpathconf(3)/pathconf(3).

fpathconf(3) and pathconf(3) can share code. There's no such
header file as <pathconf.h>. glibc/POSIX and BSD disagree about where
the _POSIX_* definitions should go.

Change-Id: I4a67f1595c9f5fbb26700a131178eedebd6bf712
diff --git a/libc/include/limits.h b/libc/include/limits.h
index f9f0c79..69df082 100644
--- a/libc/include/limits.h
+++ b/libc/include/limits.h
@@ -37,40 +37,6 @@
 
 #include <sys/cdefs.h>
 
-#if __POSIX_VISIBLE
-#define	_POSIX_ARG_MAX		4096
-#define	_POSIX_CHILD_MAX	25
-#define	_POSIX_LINK_MAX		8
-#define	_POSIX_MAX_CANON	255
-#define	_POSIX_MAX_INPUT	255
-#define	_POSIX_NAME_MAX		14
-#define	_POSIX_NGROUPS_MAX	0
-#define	_POSIX_OPEN_MAX		16
-#define	_POSIX_PATH_MAX		256
-#define _POSIX_PIPE_BUF		512
-#define	_POSIX_RE_DUP_MAX	255
-#define	_POSIX_SEM_VALUE_MAX	32767
-#define _POSIX_SSIZE_MAX	32767
-#define _POSIX_STREAM_MAX	8
-#define _POSIX_SYMLINK_MAX	255
-#define _POSIX_SYMLOOP_MAX	8
-#define _POSIX_TZNAME_MAX	3
-
-#define	_POSIX2_BC_BASE_MAX	99
-#define	_POSIX2_BC_DIM_MAX	2048
-#define	_POSIX2_BC_SCALE_MAX	99
-#define	_POSIX2_BC_STRING_MAX	1000
-#define	_POSIX2_COLL_WEIGHTS_MAX	2
-#define	_POSIX2_EXPR_NEST_MAX	32
-#define	_POSIX2_LINE_MAX	2048
-#define	_POSIX2_RE_DUP_MAX	_POSIX_RE_DUP_MAX
-
-#if __POSIX_VISIBLE >= 200112
-#define _POSIX_TTY_NAME_MAX	9	/* includes trailing NUL */
-#define _POSIX_LOGIN_NAME_MAX	9	/* includes trailing NUL */
-#endif /* __POSIX_VISIBLE >= 200112 */
-#endif /* __POSIX_VISIBLE */
-
 #if __XPG_VISIBLE
 #define PASS_MAX		128	/* _PASSWORD_LEN from <pwd.h> */
 
@@ -126,7 +92,9 @@
 /* glibc's PAGE_MASK is the bitwise negation of BSD's! TODO: remove? */
 #define PAGE_MASK (~(PAGE_SIZE - 1))
 
-#define _POSIX_SEMAPHORES 200809L
 #define SEM_VALUE_MAX 0x3fffffff
 
+/* POSIX says these belong in <unistd.h> but BSD has some in <limits.h>. */
+#include <machine/posix_limits.h>
+
 #endif /* !_LIMITS_H_ */
diff --git a/libc/include/machine/posix_limits.h b/libc/include/machine/posix_limits.h
new file mode 100644
index 0000000..f906e3b
--- /dev/null
+++ b/libc/include/machine/posix_limits.h
@@ -0,0 +1,73 @@
+/*
+ * Copyright (C) 2014 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 _POSIX_LIMITS_H_
+#define _POSIX_LIMITS_H_
+
+/* TODO: complete and check these. */
+#define _POSIX2_LINE_MAX            2048
+#define _POSIX2_RE_DUP_MAX          _POSIX_RE_DUP_MAX
+#define _POSIX_ARG_MAX              4096
+#define _POSIX_CHILD_MAX            25
+#define _POSIX_CHOWN_RESTRICTED     1  /* yes, chown requires appropriate privileges */
+#define _POSIX_FSYNC                1  /* fdatasync() supported */
+#define _POSIX_JOB_CONTROL          1  /* job control is a Linux feature */
+#define _POSIX_LINK_MAX             8
+#define _POSIX_LOGIN_NAME_MAX       9  /* includes trailing NUL */
+#define _POSIX_MAPPED_FILES         1  /* mmap-ed files supported */
+#define _POSIX_MAX_CANON            255
+#define _POSIX_MAX_INPUT            255
+#define _POSIX_MONOTONIC_CLOCK      0  /* the monotonic clock may be available; ask sysconf */
+#define _POSIX_NAME_MAX             14
+#define _POSIX_NGROUPS_MAX          0
+#define _POSIX_NO_TRUNC             1  /* very long pathnames generate an error */
+#define _POSIX_OPEN_MAX             16
+#define _POSIX_PATH_MAX             256
+#define _POSIX_PIPE_BUF             512
+#define _POSIX_PRIORITY_SCHEDULING  1  /* priority scheduling is a Linux feature */
+#define _POSIX_REALTIME_SIGNALS     -1 /* for now, this is not supported */
+#define _POSIX_RE_DUP_MAX           255
+#define _POSIX_SAVED_IDS            1  /* saved user ids is a Linux feature */
+#define _POSIX_SEMAPHORES           200809L
+#define _POSIX_SEM_VALUE_MAX        32767
+#define _POSIX_SSIZE_MAX            32767
+#define _POSIX_STREAM_MAX           8
+#define _POSIX_SYMLINK_MAX          255
+#define _POSIX_SYMLOOP_MAX          8
+#define _POSIX_SYNCHRONIZED_IO      1  /* synchronized i/o supported */
+#define _POSIX_THREAD_PRIO_INHERIT  200112L  /* linux feature */
+#define _POSIX_THREAD_PRIO_PROTECT  200112L  /* linux feature */
+#define _POSIX_THREADS              1  /* we support threads */
+#define _POSIX_THREAD_STACKADDR     1  /* we support thread stack address */
+#define _POSIX_THREAD_STACKSIZE     1  /* we support thread stack size */
+#define _POSIX_TIMERS               1  /* Posix timers are supported */
+#define _POSIX_TTY_NAME_MAX         9  /* includes trailing NUL */
+#define _POSIX_TZNAME_MAX           3
+#define _POSIX_VDISABLE             '\0'
+
+#endif /* _POSIX_LIMITS_H_ */
diff --git a/libc/include/pathconf.h b/libc/include/pathconf.h
deleted file mode 100644
index 94f9787..0000000
--- a/libc/include/pathconf.h
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * Copyright (C) 2008 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 _PATHCONF_H_
-#define _PATHCONF_H_
-
-#include <sys/cdefs.h>
-
-__BEGIN_DECLS
-
-/* constants to be used for the 'name' paremeter of pathconf/fpathconf */
-
-#define  _PC_FILESIZEBITS       0x0000
-#define  _PC_LINK_MAX           0x0001
-#define  _PC_MAX_CANON          0x0002
-#define  _PC_MAX_INPUT          0x0003
-#define  _PC_NAME_MAX           0x0004
-#define  _PC_PATH_MAX           0x0005
-#define  _PC_PIPE_BUF           0x0006
-#define  _PC_2_SYMLINKS         0x0007
-#define  _PC_ALLOC_SIZE_MIN     0x0008
-#define  _PC_REC_INCR_XFER_SIZE 0x0009
-#define  _PC_REC_MAX_XFER_SIZE  0x000a
-#define  _PC_REC_MIN_XFER_SIZE  0x000b
-#define  _PC_REC_XFER_ALIGN     0x000c
-#define  _PC_SYMLINK_MAX        0x000d
-#define  _PC_CHOWN_RESTRICTED   0x000e
-#define  _PC_NO_TRUNC           0x000f
-#define  _PC_VDISABLE           0x0010
-#define  _PC_ASYNC_IO           0x0011
-#define  _PC_PRIO_IO            0x0012
-#define  _PC_SYNC_IO            0x0013
-
-extern long fpathconf(int fildes, int name);
-extern long pathconf(const char *path, int name);
-
-__END_DECLS
-
-#endif /* _PATHCONF_H_ */
-
diff --git a/libc/include/sys/limits.h b/libc/include/sys/limits.h
index c50eb10..edb8c47 100644
--- a/libc/include/sys/limits.h
+++ b/libc/include/sys/limits.h
@@ -135,31 +135,6 @@
 #define  _XOPEN_REALTIME          -1 /* we don't support all these functions */
 #define  _XOPEN_REALTIME_THREADS  -1  /* same here */
 
-#define  _POSIX_REALTIME_SIGNALS    -1  /* for now, this is not supported */
-#define  _POSIX_PRIORITY_SCHEDULING  1  /* priority scheduling is a Linux feature */
-#define  _POSIX_TIMERS               1  /* Posix timers are supported */
-#undef   _POSIX_ASYNCHRONOUS_IO         /* aio_ functions are not supported */
-#define  _POSIX_SYNCHRONIZED_IO      1  /* synchronized i/o supported */
-#define  _POSIX_FSYNC                1  /* fdatasync() supported */
-#define  _POSIX_MAPPED_FILES         1  /* mmap-ed files supported */
-
-/* XXX: TODO: complete and check list here */
-
-
-#define  _POSIX_THREADS             1    /* we support threads */
-#define  _POSIX_THREAD_STACKADDR    1    /* we support thread stack address */
-#define  _POSIX_THREAD_STACKSIZE    1    /* we support thread stack size */
-#define  _POSIX_THREAD_PRIO_INHERIT 200112L   /* linux feature */
-#define  _POSIX_THREAD_PRIO_PROTECT 200112L   /* linux feature */
-
-#undef   _POSIX_PROCESS_SHARED           /* we don't support process-shared synchronization */
-#undef   _POSIX_THREAD_SAFE_FUNCTIONS    /* most functions are, but not everything yet */
-#define  _POSIX_CHOWN_RESTRICTED    1    /* yes, chown requires appropriate privileges */
-#define  _POSIX_MONOTONIC_CLOCK     0    /* the monotonic clock may be available; ask sysconf */
-#define  _POSIX_NO_TRUNC            1    /* very long pathnames generate an error */
-#define  _POSIX_SAVED_IDS           1    /* saved user ids is a Linux feature */
-#define  _POSIX_JOB_CONTROL         1    /* job control is a Linux feature */
-
 #define _POSIX_THREAD_DESTRUCTOR_ITERATIONS 4 /* the minimum mandated by POSIX */
 #define PTHREAD_DESTRUCTOR_ITERATIONS _POSIX_THREAD_DESTRUCTOR_ITERATIONS
 #define _POSIX_THREAD_KEYS_MAX 128            /* the minimum mandated by POSIX */
@@ -167,5 +142,4 @@
 #define _POSIX_THREAD_THREADS_MAX 64          /* the minimum mandated by POSIX */
 #define PTHREAD_THREADS_MAX                   /* bionic has no specific limit */
 
-
 #endif
diff --git a/libc/include/unistd.h b/libc/include/unistd.h
index 34ae2bc..20bc1a3 100644
--- a/libc/include/unistd.h
+++ b/libc/include/unistd.h
@@ -34,7 +34,6 @@
 #include <sys/types.h>
 #include <sys/select.h>
 #include <sys/sysconf.h>
-#include <pathconf.h>
 
 __BEGIN_DECLS
 
@@ -48,6 +47,29 @@
 #define SEEK_CUR 1
 #define SEEK_END 2
 
+#define _PC_FILESIZEBITS 0
+#define _PC_LINK_MAX 1
+#define _PC_MAX_CANON 2
+#define _PC_MAX_INPUT 3
+#define _PC_NAME_MAX 4
+#define _PC_PATH_MAX 5
+#define _PC_PIPE_BUF 6
+#define _PC_2_SYMLINKS 7
+#define _PC_ALLOC_SIZE_MIN 8
+#define _PC_REC_INCR_XFER_SIZE 9
+#define _PC_REC_MAX_XFER_SIZE 10
+#define _PC_REC_MIN_XFER_SIZE 11
+#define _PC_REC_XFER_ALIGN 12
+#define _PC_SYMLINK_MAX 13
+#define _PC_CHOWN_RESTRICTED 14
+#define _PC_NO_TRUNC 15
+#define _PC_VDISABLE 16
+#define _PC_ASYNC_IO 17
+#define _PC_PRIO_IO 18
+#define _PC_SYNC_IO 19
+
+#include <machine/posix_limits.h>
+
 extern char** environ;
 
 extern __noreturn void _exit(int);
@@ -96,6 +118,9 @@
 extern void endusershell(void);
 
 
+extern long fpathconf(int, int);
+extern long pathconf(const char*, int);
+
 
 /* Macros for access() */
 #define R_OK  4  /* Read */