From 95522e75975853d26b8d026ca1d4a10d86ba4988 Mon Sep 17 00:00:00 2001
From: Sascha Wildner <saw@online.de>
Date: Sat, 3 Mar 2018 16:05:53 +0100
Subject: [PATCH] WIP headers and pthread changes.

---
 include/arpa/inet.h                            | 34 +++++++++++++++-----------
 include/pthread.h                              |  8 +++---
 include/stdio.h                                | 20 ---------------
 include/unistd.h                               |  9 -------
 lib/libc_r/uthread/uthread_mattr_kind_np.c     |  2 +-
 lib/libc_r/uthread/uthread_mutex_prioceiling.c |  4 +--
 lib/libc_r/uthread/uthread_mutex_protocol.c    |  2 +-
 lib/libpthread/pthread.3                       |  6 ++---
 lib/libpthread/pthread_mutexattr.3             |  6 ++---
 lib/libstand/stand.h                           |  1 +
 lib/libthread_xu/thread/thr_mutex.c            |  2 +-
 lib/libthread_xu/thread/thr_mutexattr.c        |  6 ++---
 sys/sys/mman.h                                 |  3 ---
 sys/sys/types.h                                | 31 +++++------------------
 test/sysmsg/syscall.h                          |  8 ------
 15 files changed, 45 insertions(+), 97 deletions(-)

diff --git a/include/arpa/inet.h b/include/arpa/inet.h
index 9fac1bf515..871956f297 100644
--- a/include/arpa/inet.h
+++ b/include/arpa/inet.h
@@ -59,8 +59,8 @@
 
 /* External definitions for functions in inet(3) */
 
-#include <sys/types.h>
 #include <sys/cdefs.h>
+#include <stdint.h>
 
 /* Required for byteorder(3) functions. */
 #include <machine/endian.h>
@@ -68,6 +68,23 @@
 #define	INET_ADDRSTRLEN		16
 #define	INET6_ADDRSTRLEN	46
 
+#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
+
+#if __BSD_VISIBLE
+#ifndef _SIZE_T_DECLARED
+#define	_SIZE_T_DECLARED
+typedef	__size_t	size_t;
+#endif
+#endif
+
 /*
  * XXX socklen_t is used by a POSIX.1-2001 interface, but not required by
  * POSIX.1-2001.
@@ -84,17 +101,6 @@ struct in_addr {
 #define	_STRUCT_IN_ADDR_DECLARED
 #endif
 
-#ifndef _STRUCT_IN6_ADDR_DECLARED
-struct in6_addr {
-	union {
-		uint8_t   __u6_addr8[16];
-		uint16_t  __u6_addr16[8];
-		uint32_t  __u6_addr32[4];
-	} __u6_addr;                    /* 128-bit IP6 address */
-};
-#define _STRUCT_IN6_ADDR_DECLARED
-#endif
-
 /* XXX all new diversions!! argh!! */
 #if __BSD_VISIBLE
 #define	inet_addr	__inet_addr
@@ -118,14 +124,14 @@ struct in6_addr {
 
 __BEGIN_DECLS
 in_addr_t	 inet_addr(const char *);
-/*const*/ char	*inet_ntoa(struct in_addr);
-char		*inet_ntoa_r(struct in_addr, char *buf, socklen_t size);
+char		*inet_ntoa(struct in_addr);
 const char	*inet_ntop(int, const void * __restrict, char * __restrict,
 		    socklen_t);
 int		 inet_pton(int, const char * __restrict, void * __restrict);
 
 #if __BSD_VISIBLE
 int		 inet_aton(const char *, struct in_addr *);
+char		*inet_ntoa_r(struct in_addr, char *buf, socklen_t size);
 in_addr_t	 inet_lnaof(struct in_addr);
 struct in_addr	 inet_makeaddr(in_addr_t, in_addr_t);
 char		*inet_neta(in_addr_t, char *, size_t);
diff --git a/include/pthread.h b/include/pthread.h
index 03646c75cc..a2192dfb5c 100644
--- a/include/pthread.h
+++ b/include/pthread.h
@@ -206,7 +206,7 @@ int	pthread_mutexattr_init(pthread_mutexattr_t *) __nonnull(1);
 int	pthread_mutexattr_destroy(pthread_mutexattr_t *);
 int	pthread_mutexattr_getpshared(const pthread_mutexattr_t * __restrict,
 	    int * __restrict) __nonnull(2);
-int	pthread_mutexattr_gettype(pthread_mutexattr_t * __restrict,
+int	pthread_mutexattr_gettype(const pthread_mutexattr_t * __restrict,
 	    int * __restrict) __nonnull(2);
 int	pthread_mutexattr_setpshared(pthread_mutexattr_t *, int);
 int	pthread_mutexattr_settype(pthread_mutexattr_t *, int);
@@ -260,15 +260,15 @@ int	pthread_setprio(pthread_t, int);
 void	pthread_yield(void);
 #endif
 
-int	pthread_mutexattr_getprioceiling(pthread_mutexattr_t * __restrict,
+int	pthread_mutexattr_getprioceiling(const pthread_mutexattr_t * __restrict,
 	    int * __restrict);
 int	pthread_mutexattr_setprioceiling(pthread_mutexattr_t *, int);
 
-int	pthread_mutexattr_getprotocol(pthread_mutexattr_t * __restrict,
+int	pthread_mutexattr_getprotocol(const pthread_mutexattr_t * __restrict,
 	    int * __restrict);
 int	pthread_mutexattr_setprotocol(pthread_mutexattr_t *, int);
 
-int	pthread_mutex_getprioceiling(pthread_mutex_t * __restrict,
+int	pthread_mutex_getprioceiling(const pthread_mutex_t * __restrict,
 	    int * __restrict);
 int	pthread_mutex_setprioceiling(pthread_mutex_t * __restrict, int,
 	    int * __restrict);
diff --git a/include/stdio.h b/include/stdio.h
index 05bb31257f..25cf82428a 100644
--- a/include/stdio.h
+++ b/include/stdio.h
@@ -348,26 +348,6 @@ FILE	*funopen(const void *, int (*)(void *, char *, int),
 		 fpos_t (*)(void *, fpos_t, int), int (*)(void *));
 #define	fropen(cookie, fn) funopen(cookie, fn, 0, 0, 0)
 #define	fwopen(cookie, fn) funopen(cookie, 0, fn, 0, 0)
-
-/*
- * Portability hacks.  See <sys/types.h>.
- */
-#ifndef _FTRUNCATE_DECLARED
-#define	_FTRUNCATE_DECLARED
-int	 ftruncate(int, __off_t);
-#endif
-#ifndef _LSEEK_DECLARED
-#define	_LSEEK_DECLARED
-__off_t	 lseek(int, __off_t, int);
-#endif
-#ifndef _MMAP_DECLARED
-#define	_MMAP_DECLARED
-void	*mmap(void *, size_t, int, int, int, __off_t);
-#endif
-#ifndef _TRUNCATE_DECLARED
-#define	_TRUNCATE_DECLARED
-int	 truncate(const char *, __off_t);
-#endif
 #endif /* __BSD_VISIBLE */
 
 /*
diff --git a/include/unistd.h b/include/unistd.h
index 915ff3e4df..c7f5fe8093 100644
--- a/include/unistd.h
+++ b/include/unistd.h
@@ -386,10 +386,7 @@ pid_t	 getppid(void);
 uid_t	 getuid(void);
 int	 isatty(int);
 int	 link(const char *, const char *);
-#ifndef _LSEEK_DECLARED
-#define	_LSEEK_DECLARED
 off_t	 lseek(int, off_t, int);
-#endif
 long	 pathconf(const char *, int);
 int	 pause(void);
 int	 pipe(int *);
@@ -429,11 +426,8 @@ int	 fsync(int);
  * ftruncate() was in the POSIX Realtime Extension (it's used for shared
  * memory), but truncate() was not.
  */
-#ifndef _FTRUNCATE_DECLARED
-#define	_FTRUNCATE_DECLARED
 int	 ftruncate(int, off_t);
 #endif
-#endif
 
 #if __POSIX_VISIBLE >= 199506
 int	 getlogin_r(char *, int);
@@ -468,10 +462,7 @@ ssize_t	 pread(int, void *, size_t, off_t);
 ssize_t	 pwrite(int, const void *, size_t, off_t);
 
 /* See comment at ftruncate() above. */
-#ifndef _TRUNCATE_DECLARED
-#define	_TRUNCATE_DECLARED
 int	 truncate(const char *, off_t);
-#endif
 #endif /* __POSIX_VISIBLE >= 200809 || __XSI_VISIBLE */
 
 #if __POSIX_VISIBLE >= 200809
diff --git a/lib/libc_r/uthread/uthread_mattr_kind_np.c b/lib/libc_r/uthread/uthread_mattr_kind_np.c
index 9414a825c5..45d12dd505 100644
--- a/lib/libc_r/uthread/uthread_mattr_kind_np.c
+++ b/lib/libc_r/uthread/uthread_mattr_kind_np.c
@@ -77,7 +77,7 @@ _pthread_mutexattr_settype(pthread_mutexattr_t *attr, int type)
 }
 
 int
-_pthread_mutexattr_gettype(pthread_mutexattr_t * __restrict attr,
+_pthread_mutexattr_gettype(const pthread_mutexattr_t * __restrict attr,
     int * __restrict type)
 {
 	int	ret;
diff --git a/lib/libc_r/uthread/uthread_mutex_prioceiling.c b/lib/libc_r/uthread/uthread_mutex_prioceiling.c
index 1f1c7e376e..c60d09d002 100644
--- a/lib/libc_r/uthread/uthread_mutex_prioceiling.c
+++ b/lib/libc_r/uthread/uthread_mutex_prioceiling.c
@@ -38,7 +38,7 @@
 #include "pthread_private.h"
 
 int
-_pthread_mutexattr_getprioceiling(pthread_mutexattr_t * __restrict mattr,
+_pthread_mutexattr_getprioceiling(const pthread_mutexattr_t * __restrict mattr,
     int * __restrict prioceiling)
 {
 	int ret = 0;
@@ -69,7 +69,7 @@ _pthread_mutexattr_setprioceiling(pthread_mutexattr_t *mattr, int prioceiling)
 }
 
 int
-_pthread_mutex_getprioceiling(pthread_mutex_t * __restrict mutex,
+_pthread_mutex_getprioceiling(const pthread_mutex_t * __restrict mutex,
     int * __restrict prioceiling)
 {
 	int ret;
diff --git a/lib/libc_r/uthread/uthread_mutex_protocol.c b/lib/libc_r/uthread/uthread_mutex_protocol.c
index 21be9143d0..34a337193a 100644
--- a/lib/libc_r/uthread/uthread_mutex_protocol.c
+++ b/lib/libc_r/uthread/uthread_mutex_protocol.c
@@ -38,7 +38,7 @@
 #include "pthread_private.h"
 
 int
-_pthread_mutexattr_getprotocol(pthread_mutexattr_t * __restrict mattr,
+_pthread_mutexattr_getprotocol(const pthread_mutexattr_t * __restrict mattr,
     int * __restrict protocol)
 {
 	int ret = 0;
diff --git a/lib/libpthread/pthread.3 b/lib/libpthread/pthread.3
index 0f7a3e9715..8fb6ac13d8 100644
--- a/lib/libpthread/pthread.3
+++ b/lib/libpthread/pthread.3
@@ -294,12 +294,12 @@ Set the detach state in a thread attributes object.
 Destroy a mutex attributes object.
 .It Xo
 .Ft int
-.Fn pthread_mutexattr_getprioceiling "pthread_mutexattr_t * restrict attr" "int * restrict ceiling"
+.Fn pthread_mutexattr_getprioceiling "const pthread_mutexattr_t * restrict attr" "int * restrict ceiling"
 .Xc
 Obtain priority ceiling attribute of mutex attribute object.
 .It Xo
 .Ft int
-.Fn pthread_mutexattr_getprotocol "pthread_mutexattr_t * restrict attr" "int * restrict protocol"
+.Fn pthread_mutexattr_getprotocol "const pthread_mutexattr_t * restrict attr" "int * restrict protocol"
 .Xc
 Obtain protocol attribute of mutex attribute object.
 .It Xo
@@ -309,7 +309,7 @@ Obtain protocol attribute of mutex attribute object.
 Get the process shared setting from a mutex attributes object.
 .It Xo
 .Ft int
-.Fn pthread_mutexattr_gettype "pthread_mutexattr_t * restrict attr" "int * restrict type"
+.Fn pthread_mutexattr_gettype "const pthread_mutexattr_t * restrict attr" "int * restrict type"
 .Xc
 Obtain the mutex type attribute in the specified mutex attributes object.
 .It Xo
diff --git a/lib/libpthread/pthread_mutexattr.3 b/lib/libpthread/pthread_mutexattr.3
index 53d15ed000..23c0276da4 100644
--- a/lib/libpthread/pthread_mutexattr.3
+++ b/lib/libpthread/pthread_mutexattr.3
@@ -53,15 +53,15 @@
 .Ft int
 .Fn pthread_mutexattr_setprioceiling "pthread_mutexattr_t *attr" "int prioceiling"
 .Ft int
-.Fn pthread_mutexattr_getprioceiling "pthread_mutexattr_t * restrict attr" "int * restrict prioceiling"
+.Fn pthread_mutexattr_getprioceiling "const pthread_mutexattr_t * restrict attr" "int * restrict prioceiling"
 .Ft int
 .Fn pthread_mutexattr_setprotocol "pthread_mutexattr_t *attr" "int protocol"
 .Ft int
-.Fn pthread_mutexattr_getprotocol "pthread_mutexattr_t * restrict attr" "int * restrict protocol"
+.Fn pthread_mutexattr_getprotocol "const pthread_mutexattr_t * restrict attr" "int * restrict protocol"
 .Ft int
 .Fn pthread_mutexattr_settype "pthread_mutexattr_t *attr" "int type"
 .Ft int
-.Fn pthread_mutexattr_gettype "pthread_mutexattr_t * restrict attr" "int * restrict type"
+.Fn pthread_mutexattr_gettype "const pthread_mutexattr_t * restrict attr" "int * restrict type"
 .Ft int
 .Fn pthread_mutexattr_setpshared "pthread_mutexattr_t *attr" "int pshared"
 .Ft int
diff --git a/lib/libstand/stand.h b/lib/libstand/stand.h
index c2fd08cad3..126df34b1a 100644
--- a/lib/libstand/stand.h
+++ b/lib/libstand/stand.h
@@ -266,6 +266,7 @@ extern int	open(const char *, int);
 #define O_RDWR		0x2
 extern int	close(int);
 extern void	closeall(void);
+extern off_t	lseek(int, off_t, int);
 extern ssize_t	read(int, void *, size_t);
 extern ssize_t	write(int, void *, size_t);
 extern struct	dirent *readdirfd(int);
diff --git a/lib/libthread_xu/thread/thr_mutex.c b/lib/libthread_xu/thread/thr_mutex.c
index 2c4dabd592..3ed503c265 100644
--- a/lib/libthread_xu/thread/thr_mutex.c
+++ b/lib/libthread_xu/thread/thr_mutex.c
@@ -680,7 +680,7 @@ mutex_unlock_common(pthread_mutex_t *mutex)
 }
 
 int
-_pthread_mutex_getprioceiling(pthread_mutex_t * __restrict mutex,
+_pthread_mutex_getprioceiling(const pthread_mutex_t * __restrict mutex,
     int * __restrict prioceiling)
 {
 	if ((mutex == NULL) || (*mutex == NULL))
diff --git a/lib/libthread_xu/thread/thr_mutexattr.c b/lib/libthread_xu/thread/thr_mutexattr.c
index 84fc86b15a..25a6966b3e 100644
--- a/lib/libthread_xu/thread/thr_mutexattr.c
+++ b/lib/libthread_xu/thread/thr_mutexattr.c
@@ -101,7 +101,7 @@ _pthread_mutexattr_settype(pthread_mutexattr_t *attr, int type)
 }
 
 int
-_pthread_mutexattr_gettype(pthread_mutexattr_t * __restrict attr,
+_pthread_mutexattr_gettype(const pthread_mutexattr_t * __restrict attr,
     int * __restrict type)
 {
 	int	ret;
@@ -156,7 +156,7 @@ _pthread_mutexattr_setpshared(pthread_mutexattr_t *attr, int pshared)
 }
 
 int
-_pthread_mutexattr_getprotocol(pthread_mutexattr_t * __restrict mattr,
+_pthread_mutexattr_getprotocol(const pthread_mutexattr_t * __restrict mattr,
     int * __restrict protocol)
 {
 	int ret = 0;
@@ -185,7 +185,7 @@ _pthread_mutexattr_setprotocol(pthread_mutexattr_t *mattr, int protocol)
 }
 
 int
-_pthread_mutexattr_getprioceiling(pthread_mutexattr_t * __restrict mattr,
+_pthread_mutexattr_getprioceiling(const pthread_mutexattr_t * __restrict mattr,
     int * __restrict prioceiling)
 {
 	int ret = 0;
diff --git a/sys/sys/mman.h b/sys/sys/mman.h
index fb94431da9..c2bacacdd8 100644
--- a/sys/sys/mman.h
+++ b/sys/sys/mman.h
@@ -188,10 +188,7 @@ int	shm_open(const char *, int, mode_t);
 int	shm_unlink(const char *);
 #endif /* __POSIX_VISIBLE >= 199309 */
 int	mlock(const void *, size_t);
-#ifndef _MMAP_DECLARED
-#define	_MMAP_DECLARED
 void *	mmap(void *, size_t, int, int, int, off_t);
-#endif
 int	mprotect(void *, size_t, int);
 int	msync(void *, size_t, int);
 int	munlock(const void *, size_t);
diff --git a/sys/sys/types.h b/sys/sys/types.h
index a065b941ee..70d5f0e830 100644
--- a/sys/sys/types.h
+++ b/sys/sys/types.h
@@ -99,8 +99,14 @@ typedef	__uint32_t	gid_t;		/* group id */
 typedef	__int64_t	id_t;		/* general id, can hold gid/pid/uid_t */
 #define	_ID_T_DECLARED
 #endif
+#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
 typedef	__uint64_t	ino_t;		/* inode number */
 typedef	long		key_t;		/* IPC key (for Sys V IPC) */
 #ifndef _MODE_T_DECLARED
@@ -243,31 +249,6 @@ typedef	__timer_t	timer_t;
 #include <sys/_timeval.h>
 
 #define	NBBY 8		/* number of bits in a byte */
-/*
- * These declarations belong elsewhere, but are repeated here and in
- * <stdio.h> to give broken programs a better chance of working with
- * 64-bit off_t's.
- */
-#ifndef _KERNEL
-__BEGIN_DECLS
-#ifndef _FTRUNCATE_DECLARED
-#define	_FTRUNCATE_DECLARED
-int	 ftruncate(int, off_t);
-#endif
-#ifndef _LSEEK_DECLARED
-#define	_LSEEK_DECLARED
-off_t	 lseek(int, off_t, int);
-#endif
-#ifndef _MMAP_DECLARED
-#define	_MMAP_DECLARED
-void *	 mmap(void *, size_t, int, int, int, off_t);
-#endif
-#ifndef _TRUNCATE_DECLARED
-#define	_TRUNCATE_DECLARED
-int	 truncate(const char *, off_t);
-#endif
-__END_DECLS
-#endif /* !_KERNEL */
 
 #endif /* __BSD_VISIBLE */
 
diff --git a/test/sysmsg/syscall.h b/test/sysmsg/syscall.h
index 5e1f28e70a..bac09b9e9c 100644
--- a/test/sysmsg/syscall.h
+++ b/test/sysmsg/syscall.h
@@ -25,16 +25,8 @@
  * 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/test/sysmsg/syscall.h,v 1.1 2004/09/02 11:21:12 eirikn Exp $
  */
 
-/* XXX: eirik */
-#define _MMAP_DECLARED
-#define _LSEEK_DECLARED
-#define _TRUNCATE_DECLARED
-#define _FTRUNCATE_DECLARED
-
 #define __syscall_args nosys_args
 
 #include <sys/types.h>
-- 
2.15.1

