From a6d201d844b81a487e42e7b67793c4f98250090e Mon Sep 17 00:00:00 2001
From: Sascha Wildner <saw@online.de>
Date: Sat, 28 Oct 2017 21:48:20 +0200
Subject: [PATCH] WIP next round of namespace cleanup

---
 include/netdb.h   | 42 ++++++++++++++++++++++++++++++++++++++++--
 include/spawn.h   | 11 ++---------
 sys/sys/statvfs.h | 35 ++++++++++++++++++++++++++---------
 sys/sys/types.h   |  6 ++++++
 sys/sys/uuid.h    | 18 +++++++++++-------
 5 files changed, 85 insertions(+), 27 deletions(-)

diff --git a/include/netdb.h b/include/netdb.h
index 8db0f35892..76ab263c14 100644
--- a/include/netdb.h
+++ b/include/netdb.h
@@ -58,7 +58,17 @@
 #define _NETDB_H_
 
 #include <sys/cdefs.h>
-#include <sys/types.h>
+#include <stdint.h>
+
+#ifndef _IN_ADDR_T_DECLARED
+typedef	__uint32_t	in_addr_t;	/* base type for internet address */
+#define	_IN_ADDR_T_DECLARED
+#endif
+
+#ifndef _IN_PORT_T_DECLARED
+typedef	__uint16_t	in_port_t;
+#define	_IN_PORT_T_DECLARED
+#endif
 
 #ifndef _SIZE_T_DECLARED
 typedef	__size_t	size_t;
@@ -78,7 +88,9 @@ typedef	__socklen_t	socklen_t;
 #define	_PATH_PROTOCOLS	"/etc/protocols"
 #define	_PATH_SERVICES	"/etc/services"
 
+#if __BSD_VISIBLE || (__POSIX_VISIBLE && __POSIX_VISIBLE <= 200112)
 #define	h_errno (*__h_errno())
+#endif
 
 /*
  * Structures returned by network data base library.  All addresses are
@@ -91,7 +103,9 @@ struct hostent {
 	int	h_addrtype;	/* host address type */
 	int	h_length;	/* length of address */
 	char	**h_addr_list;	/* list of addresses from name server */
+#if __BSD_VISIBLE
 #define	h_addr	h_addr_list[0]	/* address, for backward compatibility */
+#endif
 };
 
 struct netent {
@@ -130,34 +144,48 @@ struct addrinfo {
  * (left in h_errno).
  */
 
+#if __BSD_VISIBLE
 #define	NETDB_INTERNAL	-1	/* see errno */
 #define	NETDB_SUCCESS	0	/* no problem */
+#endif
+#if __BSD_VISIBLE || (__POSIX_VISIBLE && __POSIX_VISIBLE <= 200112)
 #define	HOST_NOT_FOUND	1 /* Authoritative Answer Host not found */
 #define	TRY_AGAIN	2 /* Non-Authoritative Host not found, or SERVERFAIL */
 #define	NO_RECOVERY	3 /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */
 #define	NO_DATA		4 /* Valid name, no data record of requested type */
+#endif
+#if __BSD_VISIBLE
 #define	NO_ADDRESS	NO_DATA		/* no address, look for MX record */
+#endif
 
 /*
  * Error return codes from getaddrinfo()
  */
+#if __BSD_VISIBLE
 /* XXX deprecated */
 #define	EAI_ADDRFAMILY	 1	/* address family for hostname not supported */
+#endif
 #define	EAI_AGAIN	 2	/* temporary failure in name resolution */
 #define	EAI_BADFLAGS	 3	/* invalid value for ai_flags */
 #define	EAI_FAIL	 4	/* non-recoverable failure in name resolution */
 #define	EAI_FAMILY	 5	/* ai_family not supported */
 #define	EAI_MEMORY	 6	/* memory allocation failure */
+#if __BSD_VISIBLE
 /* XXX deprecated */
 #define	EAI_NODATA	 7	/* no address associated with hostname */
+#endif
 #define	EAI_NONAME	 8	/* hostname nor servname provided, or not known */
 #define	EAI_SERVICE	 9	/* servname not supported for ai_socktype */
 #define	EAI_SOCKTYPE	10	/* ai_socktype not supported */
 #define	EAI_SYSTEM	11	/* system error returned in errno */
+#if __BSD_VISIBLE
 #define	EAI_BADHINTS	12	/* invalid value for hints */
 #define	EAI_PROTOCOL	13	/* resolved protocol is unknown */
+#endif
 #define	EAI_OVERFLOW	14	/* argument buffer overflow */
+#if __BSD_VISIBLE
 #define	EAI_MAX		15
+#endif
 
 /*
  * Flag values for getaddrinfo()
@@ -166,15 +194,20 @@ struct addrinfo {
 #define	AI_CANONNAME	0x00000002 /* fill ai_canonname */
 #define	AI_NUMERICHOST	0x00000004 /* prevent host name resolution */
 #define	AI_NUMERICSERV	0x00000008 /* prevent service name resolution */
+#if __BSD_VISIBLE
 /* valid flags for addrinfo (not a standard def, apps should not use it) */
 #define AI_MASK \
     (AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST | AI_NUMERICSERV | \
     AI_ADDRCONFIG)
+#endif
 
 #define	AI_ALL		0x00000100 /* IPv6 and IPv4-mapped (with AI_V4MAPPED) */
+#if __BSD_VISIBLE
 #define	AI_V4MAPPED_CFG	0x00000200 /* accept IPv4-mapped if kernel supports */
+#endif
 #define	AI_ADDRCONFIG	0x00000400 /* only if any address is assigned */
 #define	AI_V4MAPPED	0x00000800 /* accept IPv4-mapped IPv6 address */
+#if __BSD_VISIBLE
 /* special recommended flags for getipnodebyname */
 #define	AI_DEFAULT	(AI_V4MAPPED_CFG | AI_ADDRCONFIG)
 
@@ -183,6 +216,7 @@ struct addrinfo {
  */
 #define	NI_MAXHOST	1025
 #define	NI_MAXSERV	32
+#endif
 
 /*
  * Flag values for getnameinfo()
@@ -192,14 +226,17 @@ struct addrinfo {
 #define	NI_NAMEREQD	0x00000004
 #define	NI_NUMERICSERV	0x00000008
 #define	NI_DGRAM	0x00000010
+#if __BSD_VISIBLE
 #define	NI_WITHSCOPEID	0x00000020	/* XXX deprecated */
+#endif
 #define	NI_NUMERICSCOPE	0x00000040
 
-
+#if __BSD_VISIBLE
 /*
  * Scope delimit character
  */
 #define	SCOPE_DELIMITER	'%'
+#endif
 
 __BEGIN_DECLS
 void		endhostent(void);
@@ -226,6 +263,7 @@ void		setnetent(int);
 void		setprotoent(int);
 int		getaddrinfo(const char *, const char *,
 			    const struct addrinfo *, struct addrinfo **);
+/* XXX nodeLen and serviceLen should be socklen_t */
 int		getnameinfo(const struct sockaddr *, socklen_t, char *,
 			    size_t, char *, size_t, int);
 void		freeaddrinfo(struct addrinfo *);
diff --git a/include/spawn.h b/include/spawn.h
index 0911695a04..02c75644d4 100644
--- a/include/spawn.h
+++ b/include/spawn.h
@@ -30,12 +30,11 @@
 #define _SPAWN_H_
 
 #include <sys/cdefs.h>
-#include <sys/types.h>
 #include <sys/signal.h>
+#include <sys/stdint.h>
 
-#if 0
 #ifndef _MODE_T_DECLARED
-typedef	__mode_t	mode_t;
+typedef	__uint16_t	mode_t;
 #define	_MODE_T_DECLARED
 #endif
 
@@ -44,12 +43,6 @@ typedef	__pid_t		pid_t;
 #define	_PID_T_DECLARED
 #endif
 
-#ifndef _SIGSET_T_DECLARED
-#define	_SIGSET_T_DECLARED
-typedef	__sigset_t	sigset_t;
-#endif
-#endif
-
 struct sched_param;
 
 typedef struct __posix_spawnattr		*posix_spawnattr_t;
diff --git a/sys/sys/statvfs.h b/sys/sys/statvfs.h
index a8be93c874..7d6675edec 100644
--- a/sys/sys/statvfs.h
+++ b/sys/sys/statvfs.h
@@ -30,18 +30,31 @@
  * 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.
- * 
- * $DragonFly: src/sys/sys/statvfs.h,v 1.10 2008/06/02 16:55:08 dillon Exp $
  */
 
 #ifndef _SYS_STATVFS_H_
 #define _SYS_STATVFS_H_
 
-#include <sys/types.h>
+#include <machine/stdint.h>
 #include <sys/uuid.h>
 
+#ifndef _FSBLKCNT_T_DECLARED
+typedef	__uint64_t	fsblkcnt_t;	/* filesystem block count */
+#define	_FSBLKCNT_T_DECLARED
+#endif
+#ifndef _FSFILCNT_T_DECLARED
+typedef	__uint64_t	fsfilcnt_t;	/* filesystem file count */
+#define	_FSFILCNT_T_DECLARED
+#endif
+#ifndef _UID_T_DECLARED
+typedef	__uint32_t	uid_t;		/* user id */
+#define	_UID_T_DECLARED
+#endif
+
+#if __BSD_VISIBLE
 struct fhandle;
 struct statfs;
+#endif
 
 /*
  * The POSIX 1003.1 standard uses free and available nomenclature to mean the
@@ -65,11 +78,11 @@ struct statvfs {
 	uid_t		f_owner;	/* user that mounted the filesystem */
 	unsigned int	f_type;		/* filesystem type */
 
-	uint64_t  	f_syncreads;	/* count of sync reads since mount */
-	uint64_t  	f_syncwrites;	/* count of sync writes since mount */
+	__uint64_t  	f_syncreads;	/* count of sync reads since mount */
+	__uint64_t  	f_syncwrites;	/* count of sync writes since mount */
 
-	uint64_t  	f_asyncreads;	/* count of async reads since mount */
-	uint64_t  	f_asyncwrites;	/* count of async writes since mount */
+	__uint64_t  	f_asyncreads;	/* count of async reads since mount */
+	__uint64_t  	f_asyncwrites;	/* count of async writes since mount */
 
 	/*
 	 * DragonFly extensions - full uuid FSID and owner
@@ -84,18 +97,22 @@ struct statvfs {
 #define ST_RDONLY	0x00000001	/* fs is read-only */
 #define ST_NOSUID	0x00000002	/* ST_ISUID or ST_ISGID not supported */
 
+#if __BSD_VISIBLE
 /*
  * DragonFly specific flags
  */
 #define ST_FSID_UUID	0x40000000	/* f_fsid_uuid field is valid */
 #define ST_OWNER_UUID	0x80000000	/* f_owner_uuid field is valid */
+#endif
 
 __BEGIN_DECLS
 int	fstatvfs(int, struct statvfs *);
 int	statvfs(const char * __restrict, struct statvfs * __restrict);
-int     fhstatvfs (const struct fhandle *, struct statvfs * __restrict);
-int	getvfsstat (struct statfs * __restrict, struct statvfs * __restrict, long, int);
 
+#if __BSD_VISIBLE
+int	fhstatvfs(const struct fhandle *, struct statvfs * __restrict);
+int	getvfsstat(struct statfs * __restrict, struct statvfs * __restrict, long, int);
+#endif
 __END_DECLS
 
 #endif /* _SYS_STATVFS_H_ */
diff --git a/sys/sys/types.h b/sys/sys/types.h
index 47bcd48ea2..0be11fb0d1 100644
--- a/sys/sys/types.h
+++ b/sys/sys/types.h
@@ -84,8 +84,14 @@ typedef	volatile char *	v_caddr_t;	/* core address, pointer to volatile */
 typedef	__int32_t	daddr_t;	/* disk address */
 typedef	__uint32_t	u_daddr_t;	/* unsigned disk address */
 typedef	__uint32_t	fixpt_t;	/* fixed point number */
+#ifndef _FSBLKCNT_T_DECLARED
 typedef	__uint64_t	fsblkcnt_t;	/* filesystem block count */
+#define	_FSBLKCNT_T_DECLARED
+#endif
+#ifndef _FSFILCNT_T_DECLARED
 typedef	__uint64_t	fsfilcnt_t;	/* filesystem file count */
+#define	_FSFILCNT_T_DECLARED
+#endif
 #ifndef _GID_T_DECLARED
 typedef	__uint32_t	gid_t;		/* group id */
 #define	_GID_T_DECLARED
diff --git a/sys/sys/uuid.h b/sys/sys/uuid.h
index 5f1c05f564..e320f1ece3 100644
--- a/sys/sys/uuid.h
+++ b/sys/sys/uuid.h
@@ -24,13 +24,17 @@
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
  * $FreeBSD: src/sys/sys/uuid.h,v 1.6 2005/10/07 13:37:10 marcel Exp $
- * $DragonFly: src/sys/sys/uuid.h,v 1.5 2007/10/09 17:19:09 dillon Exp $
  */
 
 #ifndef _SYS_UUID_H_
 #define	_SYS_UUID_H_
 
 #include <sys/cdefs.h>
+#ifndef _KERNEL
+#include <machine/stdint.h>
+#else
+#include <sys/types.h>
+#endif
 
 /* Length of a node address (an IEEE 802 address). */
 #define	_UUID_NODE_LEN		6
@@ -43,12 +47,12 @@
  * A DCE 1.1 compatible source representation of UUIDs.
  */
 struct uuid {
-	uint32_t	time_low;
-	uint16_t	time_mid;
-	uint16_t	time_hi_and_version;
-	uint8_t		clock_seq_hi_and_reserved;
-	uint8_t		clock_seq_low;
-	uint8_t		node[_UUID_NODE_LEN];
+	__uint32_t	time_low;
+	__uint16_t	time_mid;
+	__uint16_t	time_hi_and_version;
+	__uint8_t	clock_seq_hi_and_reserved;
+	__uint8_t	clock_seq_low;
+	__uint8_t	node[_UUID_NODE_LEN];
 };
 
 #ifdef _KERNEL
-- 
2.14.1

