Subject: eliminating redundant declarations in system include files.
To: None <tech-userlevel@netbsd.org>
From: Christos Zoulas <christos@zoulas.com>
List: tech-userlevel
Date: 12/16/2000 15:55:48
The following patch eliminates redundant declaration warnings. I cannot
think of a better way of doing it. Comments?

christos

Index: errno.h
===================================================================
RCS file: /cvsroot/basesrc/include/errno.h,v
retrieving revision 1.3
diff -u -u -r1.3 errno.h
--- errno.h	2000/06/13 01:21:53	1.3
+++ errno.h	2000/12/16 20:51:55
@@ -48,8 +48,10 @@
 #include <sys/featuretest.h>
 
 __BEGIN_DECLS
+#ifndef errno
 int *__errno __P((void));
 #define errno (*__errno())
+#endif
 
 #if !defined(_ANSI_SOURCE) && !defined(_POSIX_C_SOURCE) && \
     !defined(_XOPEN_SOURCE)
Index: signal.h
===================================================================
RCS file: /cvsroot/basesrc/include/signal.h,v
retrieving revision 1.20
diff -u -u -r1.20 signal.h
--- signal.h	1998/12/09 12:50:47	1.20
+++ signal.h	2000/12/16 20:51:55
@@ -50,7 +50,11 @@
 #if !defined(_ANSI_SOURCE) && !defined(_POSIX_C_SOURCE) && \
     !defined(_XOPEN_SOURCE)
 extern __const char *__const *sys_signame __RENAME(__sys_signame14);
+#ifndef __SYS_SIGLIST_DECLARED
+#define __SYS_SIGLIST_DECLARED
+/* also in unistd.h */
 extern __const char *__const *sys_siglist __RENAME(__sys_siglist14);
+#endif /* __SYS_SIGLIST_DECLARED */
 extern __const int sys_nsig __RENAME(__sys_nsig14);
 #endif
 
@@ -90,21 +94,15 @@
 int	sigsuspend __P((const sigset_t *)) __RENAME(__sigsuspend14);
 
 #if defined(__GNUC__) && defined(__STDC__)
+#ifndef errno
+int *__errno __P((void));
+#define errno (*__errno())
+#endif
 extern __inline int
 sigaddset(sigset_t *set, int signo)
 {
-#ifdef _REENTRANT
-	extern int *__errno __P((void));
-#else
-	extern int errno;
-#endif
-
 	if (signo <= 0 || signo >= _NSIG) {
-#ifdef _REENTRANT
-		*__errno() = 22;		/* EINVAL */
-#else
 		errno = 22;			/* EINVAL */
-#endif
 		return (-1);
 	}
 	__sigaddset(set, signo);
@@ -114,18 +112,8 @@
 extern __inline int
 sigdelset(sigset_t *set, int signo)
 {
-#ifdef _REENTRANT
-	extern int *__errno __P((void));
-#else
-	extern int errno;
-#endif
-
 	if (signo <= 0 || signo >= _NSIG) {
-#ifdef _REENTRANT
-		*__errno() = 22;		/* EINVAL */
-#else
 		errno = 22;			/* EINVAL */
-#endif
 		return (-1);
 	}
 	__sigdelset(set, signo);
@@ -135,18 +123,8 @@
 extern __inline int
 sigismember(const sigset_t *set, int signo)
 {
-#ifdef _REENTRANT
-	extern int *__errno __P((void));
-#else
-	extern int errno;
-#endif
-
 	if (signo <= 0 || signo >= _NSIG) {
-#ifdef _REENTRANT
-		*__errno() = 22;		/* EINVAL */
-#else
 		errno = 22;			/* EINVAL */
-#endif
 		return (-1);
 	}
 	return (__sigismember(set, signo));
@@ -174,7 +152,11 @@
 #endif /* (!_POSIX_C_SOURCE && !_XOPEN_SOURCE) || ... */
 
 #if !defined(_POSIX_C_SOURCE) && !defined(_XOPEN_SOURCE)
+#ifndef __PSIGNAL_DECLARED
+#define __PSIGNAL_DECLARED
+/* also in unistd.h */
 void	psignal __P((unsigned int, const char *));
+#endif /* __PSIGNAL_DECLARED */
 int	sigblock __P((int));
 #ifdef __LIBC12_SOURCE__
 int	sigreturn __P((struct sigcontext13 *));
Index: stdio.h
===================================================================
RCS file: /cvsroot/basesrc/include/stdio.h,v
retrieving revision 1.39
diff -u -u -r1.39 stdio.h
--- stdio.h	2000/11/15 15:44:05	1.39
+++ stdio.h	2000/12/16 20:51:55
@@ -272,7 +272,11 @@
 
 __BEGIN_DECLS
 char	*ctermid __P((char *));
+#ifndef __CUSERID_DECLARED
+#define __CUSERID_DECLARED
+/* also declared in unistd.h */
 char	*cuserid __P((char *));
+#endif /* __CUSERID_DECLARED */
 FILE	*fdopen __P((int, const char *));
 int	 fileno __P((FILE *));
 __END_DECLS
Index: unistd.h
===================================================================
RCS file: /cvsroot/basesrc/include/unistd.h,v
retrieving revision 1.85
diff -u -u -r1.85 unistd.h
--- unistd.h	2000/06/27 05:51:54	1.85
+++ unistd.h	2000/12/16 20:51:56
@@ -103,7 +103,11 @@
 #endif /* defined(_POSIX_C_SOURCE) || defined(_XOPEN_SOURCE) */
 int	 close __P((int));
 size_t	 confstr __P((int, char *, size_t));
+#ifndef __CUSERID_DECLARED
+#define __CUSERID_DECLARED
+/* also declared in stdio.h */
 char	*cuserid __P((char *));	/* obsolete */
+#endif /* __CUSERID_DECLARED */
 int	 dup __P((int));
 int	 dup2 __P((int, int));
 int	 execl __P((const char *, const char *, ...));
@@ -126,7 +130,6 @@
 uid_t	 getuid __P((void));
 int	 isatty __P((int));
 int	 link __P((const char *, const char *));
-off_t	 lseek __P((int, off_t, int));
 long	 pathconf __P((const char *, int));
 int	 pause __P((void));
 int	 pipe __P((int *));
@@ -160,6 +163,14 @@
 
 
 /*
+ * The following three syscalls are also defined in <sys/types.h>
+ * We protect them against double declarations.
+ */
+#ifndef __OFF_T_SYSCALLS_DECLARED
+#define __OFF_T_SYSCALLS_DECLARED
+off_t	 lseek __P((int, off_t, int));
+int	 truncate __P((const char *, off_t));
+/*
  * IEEE Std 1003.1b-93,
  * also found in X/Open Portability Guide >= Issue 4 Verion 2
  */
@@ -169,6 +180,7 @@
     (_XOPEN_SOURCE - 0) >= 500
 int	 ftruncate __P((int, off_t));
 #endif
+#endif /* __OFF_T_SYSCALLS_DECLARED */
 
 
 /*
@@ -254,7 +266,6 @@
 void	 swab __P((const void *, void *, size_t));
 int	 symlink __P((const char *, const char *));
 void	 sync __P((void));
-int	 truncate __P((const char *, off_t));
 useconds_t ualarm __P((useconds_t, useconds_t));
 int	 usleep __P((useconds_t));
 #ifdef __LIBC12_SOURCE__
@@ -306,7 +317,11 @@
 int      issetugid __P((void));
 int	 nfssvc __P((int, void *));
 int	 profil __P((char *, size_t, u_long, u_int));
-void	 psignal __P((unsigned int, const char *));
+#ifndef __PSIGNAL_DECLARED
+#define __PSIGNAL_DECLARED
+/* also in signal.h */
+void	psignal __P((unsigned int, const char *));
+#endif /* __PSIGNAL_DECLARED */
 int	 rcmd __P((char **, int, const char *,
 	    const char *, const char *, int *));
 int	 reboot __P((int, char *));
@@ -339,7 +354,11 @@
 int	 iruserok_sa __P((const void *, int, int, const char *, const char *));
 #endif
 
+#ifndef __SYS_SIGLIST_DECLARED
+#define __SYS_SIGLIST_DECLARED
+/* also in signal.h */
 extern __const char *__const *sys_siglist __RENAME(__sys_siglist14);
+#endif /* __SYS_SIGLIST_DECLARED */
 extern	 int optreset;		/* getopt(3) external variable */
 extern	 char *suboptarg;	/* getsubopt(3) external variable */
 #endif
Index: types.h
===================================================================
RCS file: /cvsroot/syssrc/sys/sys/types.h,v
retrieving revision 1.47
diff -u -u -r1.47 types.h
--- types.h	2000/09/19 08:35:36	1.47
+++ types.h	2000/12/16 20:52:46
@@ -125,6 +125,8 @@
  * include that header or explicitly cast them to off_t.
  */
 #if !defined(_POSIX_SOURCE) && !defined(_XOPEN_SOURCE)
+#ifndef __OFF_T_SYSCALLS_DECLARED
+#define __OFF_T_SYSCALLS_DECLARED
 #ifndef _KERNEL
 #include <sys/cdefs.h>
 __BEGIN_DECLS
@@ -133,6 +135,7 @@
 int	 truncate __P((const char *, off_t));
 __END_DECLS
 #endif /* !_KERNEL */
+#endif /* __OFF_T_SYSCALLS_DECLARED */
 #endif /* !defined(_POSIX_SOURCE) ... */
 
 #if !defined(_POSIX_SOURCE) && !defined(_XOPEN_SOURCE)