From 2b48b63e745e93b484286d4eb1c9e0fba0f726f7 Mon Sep 17 00:00:00 2001 From: Olaf Seibert Date: Thu, 21 Jan 2016 00:02:22 +0100 Subject: [PATCH] Eliminate CENV_SYS_STRERROR, use configure checks instead --- configure.ac | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++-- src/cenv.h | 4 ---- src/dpsup.c | 16 ++++++++----- src/enaddr.c | 18 +++++++------- src/osdsup.c | 16 ++++++++----- src/tapedd.c | 22 +++++++++++------- src/vdkfmt.c | 20 +++++++++------- 7 files changed, 118 insertions(+), 44 deletions(-) diff --git a/configure.ac b/configure.ac index 5102e86..19b68aa 100644 --- a/configure.ac +++ b/configure.ac @@ -47,7 +47,11 @@ NETLIBS="$LIBS" LIBS="$SAVE_LIBS" # Checks for header files. -AC_CHECK_HEADERS([arpa/inet.h fcntl.h limits.h netinet/in.h sgtty.h stddef.h stdlib.h string.h sys/file.h sys/ioctl.h sys/socket.h sys/time.h termios.h unistd.h net/if_tun.h linux/if_tun.h linux/if_packet.h net/if_tap.h sys/mtio.h net/nit.h sys/dlpi.h net/if_dl.h net/if_types.h]) +AC_CHECK_HEADERS([arpa/inet.h errno.h fcntl.h limits.h netinet/in.h sgtty.h \ + stddef.h stdlib.h string.h sys/file.h sys/ioctl.h \ + sys/socket.h sys/time.h termios.h unistd.h net/if_tun.h \ + linux/if_tun.h linux/if_packet.h net/if_tap.h sys/mtio.h \ + net/nit.h sys/dlpi.h net/if_dl.h net/if_types.h]) # Checks for typedefs, structures, and compiler characteristics. AC_C_INLINE @@ -63,7 +67,9 @@ AC_FUNC_FORK AC_FUNC_FSEEKO AC_FUNC_MALLOC AC_FUNC_REALLOC -AC_CHECK_FUNCS([alarm dup2 gettimeofday localtime_r memset socket strcasecmp strchr strcspn strerror strncasecmp strpbrk strrchr strtol getifaddrs if_nameindex termios sigsetops sigaction nanosleep]) +AC_CHECK_FUNCS([alarm dup2 gettimeofday localtime_r memset socket strcasecmp \ + strchr strcspn strerror strncasecmp strpbrk strrchr strtol \ + getifaddrs if_nameindex termios sigsetops sigaction nanosleep]) # Check for CPU. # This requires install-sh, config.sub, config.guess from automake. @@ -109,6 +115,53 @@ typedef char vaddr_t; CENVFLAGS="$CENVFLAGS -include vaddr-sucks.h" ]) +# ------------------------------------------------------------------------- +# Check how to replace strerror() +# ------------------------------------------------------------------------- + +AC_MSG_CHECKING([whether sys_errlist exists]) +AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ +#if HAVE_ERRNO_H +# include +#endif +#include +#include +]], [[ + return sys_errlist[sys_nerr-1]; +]])], +[ + # Compiles ok + AC_MSG_RESULT([yes]) + AC_DEFINE([HAVE_SYS_ERRLIST], [1], [Define if char *sys_errlist[] exists]) +], +[ + # Compile error; try another variation + AC_MSG_RESULT([no]) + + AC_MSG_CHECKING([whether sys_errlist exists but needs a declaration]) + AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ + #if HAVE_ERRNO_H + # include + #endif + #include + #include + extern int sys_nerr; + extern char *sys_errlist[]; + ]], [[ + return sys_errlist[sys_nerr-1]; + ]])], + [ + # Compiles ok + AC_MSG_RESULT([yes]) + AC_DEFINE([HAVE_SYS_ERRLIST], [1], [Define if char *sys_errlist[] exists]) + AC_DEFINE([DECL_SYS_ERRLIST], [1], [Define if char *sys_errlist[] must be declared]) + ], + [ + # Compile error + AC_MSG_RESULT([no?]) + ]) +]) + # ------------------------------------------------------------------------- # Check whether we want bridge support # ------------------------------------------------------------------------- @@ -147,6 +200,15 @@ fi # Output section. State which @VARIABLES@ are going to be substituted # ------------------------------------------------------------------------- +AH_TOP([ +#ifndef CONFIG_H_INCLUDED +#define CONFIG_H_INCLUDED +]) + +AH_BOTTOM([ +#endif /* CONFIG_H_INCLUDED */ +]) + AC_SUBST([CC]) AC_SUBST([CFLAGS]) AC_SUBST([DESTDIR]) diff --git a/src/cenv.h b/src/cenv.h index c458dc7..1be3b30 100644 --- a/src/cenv.h +++ b/src/cenv.h @@ -229,10 +229,6 @@ # define CENV_SYSF_SIGSET (CENV_SYS_DECOSF|CENV_SYS_SUN|CENV_SYS_SOLARIS \ |CENV_SYS_XBSD|CENV_SYS_LINUX) #endif -#ifndef CENV_SYSF_STRERROR /* Has strerror(3) */ -# define CENV_SYSF_STRERROR (CENV_SYS_DECOSF|CENV_SYS_SOLARIS|CENV_SYS_XBSD \ - |CENV_SYS_LINUX) -#endif #ifndef CENV_SYSF_NANOSLEEP /* Has nanosleep(2) */ # define CENV_SYSF_NANOSLEEP (CENV_SYS_DECOSF|CENV_SYS_SOLARIS|CENV_SYS_XBSD \ |CENV_SYS_LINUX) diff --git a/src/dpsup.c b/src/dpsup.c index 2ce6f1f..cdd3bac 100644 --- a/src/dpsup.c +++ b/src/dpsup.c @@ -43,6 +43,10 @@ static int decosfcclossage; #include #include /* For strerror() if present */ +#if HAVE_ERRNO_H +# include +#endif + #include "dpsup.h" #if CENV_SYS_DECOSF || CENV_SYS_SUN || CENV_SYS_SOLARIS || CENV_SYS_XBSD || CENV_SYS_LINUX @@ -663,19 +667,19 @@ dp_strerror(int err) { if (err == -1 && errno != err) return dp_strerror(errno); -#if CENV_SYSF_STRERROR +#if HAVE_STRERROR return strerror(err); #else -# if CENV_SYS_UNIX +# if HAVE_SYS_ERRLIST { -# if !CENV_SYS_XBSD /* Already in signal.h */ +# if DECL_SYS_ERRLIST extern int sys_nerr; extern char *sys_errlist[]; # endif if (0 < err && err <= sys_nerr) - return (char *)sys_errlist[err]; + return sys_errlist[err]; } -# endif +# endif /* HAVE_SYS_ERRLIST */ if (err == 0) return "No error"; else { @@ -683,7 +687,7 @@ dp_strerror(int err) sprintf(ebuf, "Unknown-error-%d", err); return ebuf; } -#endif /* !CENV_SYSF_STRERROR */ +#endif /* !HAVE_STRERROR */ } diff --git a/src/enaddr.c b/src/enaddr.c index a100567..b166dea 100644 --- a/src/enaddr.c +++ b/src/enaddr.c @@ -60,6 +60,10 @@ #include "rcsid.h" #include "osdnet.h" +#if HAVE_ERRNO_H +# include +#endif + #ifdef RCSID RCSID(enaddr_c,"$Id: enaddr.c,v 2.6 2002/03/18 04:19:17 klh Exp $") #endif @@ -122,10 +126,6 @@ Usage: enaddr [-v] [ [default | ] [+] [-]]\n\ #if 1 /* Error and diagnostic stuff */ -#if CENV_SYSF_STRERROR -# include /* For strerror() */ -#endif - /* Error and diagnostic output */ static const char *log_progname = LOG_PROGNAME; @@ -134,19 +134,19 @@ char *log_strerror(int err) { if (err == -1 && errno != err) return log_strerror(errno); -#if CENV_SYSF_STRERROR +#if HAVE_STRERROR return strerror(err); #else -# if CENV_SYS_UNIX +# if HAVE_SYS_ERRLIST { -# if !CENV_SYS_XBSD /* Already in signal.h */ +# if DECL_SYS_ERRLIST extern int sys_nerr; extern char *sys_errlist[]; # endif if (0 < err && err <= sys_nerr) return sys_errlist[err]; } -# endif +# endif /* HAVE_SYS_ERRLIST */ if (err == 0) return "No error"; else { @@ -154,7 +154,7 @@ char *log_strerror(int err) sprintf(ebuf, "Unknown-error-%d", err); return ebuf; } -#endif /* !CENV_SYSF_STRERROR */ +#endif /* !HAVE_STRERROR */ } diff --git a/src/osdsup.c b/src/osdsup.c index aa49344..b8d1ba8 100644 --- a/src/osdsup.c +++ b/src/osdsup.c @@ -52,6 +52,10 @@ #include "osdsup.h" #include "kn10ops.h" +#if HAVE_ERRNO_H +# include +#endif + #if CENV_SYS_UNIX # include # include @@ -119,7 +123,7 @@ #endif /* CENV_USE_COMM_TOOLBOX */ #endif /* CENV_SYS_MAC */ -#if CENV_SYSF_STRERROR +#if HAVE_STRERROR extern char *strerror(int); /* Not always declared in string.h */ #endif @@ -180,19 +184,19 @@ os_strerror(int err) { if (err == -1 && errno != err) return os_strerror(errno); -#if CENV_SYSF_STRERROR +#if HAVE_STRERROR return strerror(err); #else -# if CENV_SYS_UNIX +# if HAVE_SYS_ERRLIST { -# if !CENV_SYS_XBSD /* Already in signal.h */ +# if DECL_SYS_ERRLIST extern int sys_nerr; extern char *sys_errlist[]; # endif if (0 < err && err <= sys_nerr) return sys_errlist[err]; } -# endif +# endif /* HAVE_SYS_ERRLIST */ if (err == 0) return "No error"; else { @@ -200,7 +204,7 @@ os_strerror(int err) sprintf(ebuf, "Unknown-error-%d", err); return ebuf; } -#endif /* !CENV_SYSF_STRERROR */ +#endif /* !HAVE_STRERROR */ } /* Controlling terminal stuff diff --git a/src/tapedd.c b/src/tapedd.c index 453748e..beca2ee 100644 --- a/src/tapedd.c +++ b/src/tapedd.c @@ -63,7 +63,7 @@ # include # include /* FLD macros */ # define char8 _KCCtype_char8 -# define CENV_SYSF_STRERROR 1 +# define HAVE_STRERROR 1 # define NULLDEV "NUL:" # define FD_STDIN 0 # define FD_STDOUT 1 @@ -83,6 +83,10 @@ # define strCMP strcmp /* Temporary compat hack */ #endif +#if HAVE_ERRNO_H +# include +#endif + #define MAXRECSIZE (1L<<16) /* was ((15*518*5)+512) */ #define FNAMSIZ 200 @@ -340,19 +344,19 @@ os_strerror(int err) { if (err == -1 && errno != err) return os_strerror(errno); -#if CENV_SYSF_STRERROR +#if HAVE_STRERROR return strerror(err); #else -# if CENV_SYS_UNIX +# if HAVE_SYS_ERRLIST { -#if !CENV_SYS_XBSD +# if DECL_SYS_ERRLIST extern int sys_nerr; extern char *sys_errlist[]; -#endif - if (0 < err && err <= sys_nerr) - return (char *)sys_errlist[err]; - } # endif + if (0 < err && err <= sys_nerr) + return sys_errlist[err]; + } +# endif /* HAVE_SYS_ERRLIST */ if (err == 0) return "No error"; else { @@ -360,7 +364,7 @@ os_strerror(int err) sprintf(ebuf, "Unknown-error-%d", err); return ebuf; } -#endif /* !CENV_SYSF_STRERROR */ +#endif /* !HAVE_STRERROR */ } void errhan(void *arg, struct vmtape *t, char *s) diff --git a/src/vdkfmt.c b/src/vdkfmt.c index ff92e80..018527a 100644 --- a/src/vdkfmt.c +++ b/src/vdkfmt.c @@ -57,6 +57,10 @@ # define FD_STDOUT 1 #endif +#if HAVE_ERRNO_H +# include +#endif + #define FNAMSIZ 200 #define TRUE 1 @@ -218,19 +222,19 @@ os_strerror(int err) { if (err == -1 && errno != err) return os_strerror(errno); -#if CENV_SYSF_STRERROR +#if HAVE_STRERROR return strerror(err); #else -# if CENV_SYS_UNIX +# if HAVE_SYS_ERRLIST { -#if !CENV_SYS_XBSD +# if DECL_SYS_ERRLIST extern int sys_nerr; extern char *sys_errlist[]; -#endif - if (0 < err && err <= sys_nerr) - return (char *)sys_errlist[err]; - } # endif + if (0 < err && err <= sys_nerr) + return sys_errlist[err]; + } +# endif /* HAVE_SYS_ERRLIST */ if (err == 0) return "No error"; else { @@ -238,7 +242,7 @@ os_strerror(int err) sprintf(ebuf, "Unknown-error-%d", err); return ebuf; } -#endif /* !CENV_SYSF_STRERROR */ +#endif /* !HAVE_STRERROR */ } void errhan(struct vdk_unit *t, char *s)