From: Sami Kerola Date: Tue, 23 Aug 2016 11:49:05 +0000 (+0100) Subject: portability: MacOS does not have error() function X-Git-Tag: v0.88~27^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=73f360b44ffe70aaa886e0cbc2267691da87ef93;p=thirdparty%2Fmtr.git portability: MacOS does not have error() function Add portability fix by using err() function family. This is a bit cheeky, but should work relatively well. --- diff --git a/Makefile.am b/Makefile.am index cb4d2f4..f71d641 100644 --- a/Makefile.am +++ b/Makefile.am @@ -18,6 +18,12 @@ mtr_SOURCES = mtr.c mtr.h \ img/mtr_icon.xpm \ mtr-gtk.h +if WITH_ERROR +mtr_SOURCES += \ + portability/error.h \ + portability/error.c +endif + if WITH_GETOPT mtr_SOURCES += \ portability/getopt.h \ diff --git a/asn.c b/asn.c index dbb5926..f456ba8 100644 --- a/asn.c +++ b/asn.c @@ -22,7 +22,11 @@ #include #include #include +#ifdef HAVE_ERROR_H #include +#else +#include "portability/error.h" +#endif #include #ifdef __APPLE__ diff --git a/configure.ac b/configure.ac index 5369ec4..8ce4da8 100644 --- a/configure.ac +++ b/configure.ac @@ -8,6 +8,7 @@ AC_CONFIG_AUX_DIR([build-aux]) AM_INIT_AUTOMAKE([ 1.7.9 foreign + subdir-objects ]) # --enable-silent-rules @@ -38,6 +39,7 @@ AC_CHECK_HEADERS([ \ arpa/nameser_compat.h \ curses.h \ cursesX.h \ + error.h \ fcntl.h \ ncurses.h \ ncurses/curses.h \ @@ -53,6 +55,13 @@ AC_CHECK_FUNCS([ \ fcntl \ ]) +AC_CHECK_FUNC([error], [with_error=no], + [AC_CHECK_FUNCS([verr verrx vwarn vwarnx], [with_error=yes], + [AC_MSG_ERROR([cannot find working error printing function]) + ]) +]) +AM_CONDITIONAL([WITH_ERROR], [test "x$with_error" = "xyes"]) + AC_CHECK_FUNC([getopt_long], [with_getopt=no], [with_getopt=yes]) AS_IF([test "x$with_getopt" = "xno"], [ AC_DEFINE([HAVE_GETOPT], [1], [Define if libc has getopt_long]) diff --git a/dns.c b/dns.c index 0e69eb4..e6a0a9b 100644 --- a/dns.c +++ b/dns.c @@ -46,7 +46,11 @@ //#endif //#include //#include +#ifdef HAVE_ERROR_H #include +#else +#include "portability/error.h" +#endif #include #include #include diff --git a/mtr.c b/mtr.c index 47f5d2a..bc6d4bc 100644 --- a/mtr.c +++ b/mtr.c @@ -26,7 +26,11 @@ #include #include #include +#ifdef HAVE_ERROR_H #include +#else +#include "portability/error.h" +#endif #ifdef HAVE_VALUES_H #include #endif diff --git a/net.c b/net.c index 32dcfac..964f508 100644 --- a/net.c +++ b/net.c @@ -38,7 +38,11 @@ #include #include #include +#ifdef HAVE_ERROR_H #include +#else +#include "portability/error.h" +#endif #include "mtr.h" diff --git a/portability/.gitignore b/portability/.gitignore new file mode 100644 index 0000000..229368a --- /dev/null +++ b/portability/.gitignore @@ -0,0 +1,2 @@ +/.deps +/.dirstamp diff --git a/portability/error.c b/portability/error.c new file mode 100644 index 0000000..99b7c99 --- /dev/null +++ b/portability/error.c @@ -0,0 +1,39 @@ + /* + Linux error(3) function go around for systems that has err(3) and + warn(3), but no error(3). MacOS is good example of such. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation version 2. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. +*/ + +#include +#include + +void error(int status, int errnum, const char *format, ...) { + va_list arg; + + va_start(arg, format); + if (errnum == 0) { + if (status == 0) + vwarnx(format, arg); + else + verrx(status, format, arg); + } else { + if (status == 0) + vwarn(format, arg); + else + verr(status, format, arg); + } + va_end(arg); +} diff --git a/portability/error.h b/portability/error.h new file mode 100644 index 0000000..5efbaed --- /dev/null +++ b/portability/error.h @@ -0,0 +1,20 @@ + /* + Linux error(3) function go around for systems that has err(3) and + warn(3), but no error(3). MacOS is good example of such. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation version 2. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. +*/ + +void error(int status, int errnum, const char *format, ...); diff --git a/select.c b/select.c index 01e4b58..cbf8e25 100644 --- a/select.c +++ b/select.c @@ -28,7 +28,11 @@ #include #include #include +#ifdef HAVE_ERROR_H #include +#else +#include "portability/error.h" +#endif #include "mtr.h" #include "dns.h"