]> git.ipfire.org Git - thirdparty/mtr.git/commitdiff
portability: MacOS does not have error() function
authorSami Kerola <kerolasa@iki.fi>
Tue, 23 Aug 2016 11:49:05 +0000 (12:49 +0100)
committerSami Kerola <kerolasa@iki.fi>
Tue, 23 Aug 2016 20:45:20 +0000 (21:45 +0100)
Add portability fix by using err() function family.  This is a bit cheeky,
but should work relatively well.

Makefile.am
asn.c
configure.ac
dns.c
mtr.c
net.c
portability/.gitignore [new file with mode: 0644]
portability/error.c [new file with mode: 0644]
portability/error.h [new file with mode: 0644]
select.c

index cb4d2f4d313741170cd6e5caebe46627f5d73fe0..f71d641512915622cc15e70f3228c692497657c7 100644 (file)
@@ -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 dbb5926e51c74a617c7afba3802b1285bcdc0782..f456ba88d6fb6c9370435c768c8fa735beca516f 100644 (file)
--- a/asn.c
+++ b/asn.c
 #include <stdio.h>
 #include <stdlib.h>
 #include <sys/types.h>
+#ifdef HAVE_ERROR_H
 #include <error.h>
+#else
+#include "portability/error.h"
+#endif
 #include <errno.h>
 
 #ifdef __APPLE__
index 5369ec471dc61d8297e9ba56daaf133ea314ae11..8ce4da8a823f28a0b4d6e25e839129d68b5e4f5c 100644 (file)
@@ -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 0e69eb4da54dd6cf4d4a1d2b6188008f4e0df447..e6a0a9bd8fd0a133055e15696446facfd7efd5b9 100644 (file)
--- a/dns.c
+++ b/dns.c
 //#endif
 //#include <netdb.h>
 //#include <resolv.h>
+#ifdef HAVE_ERROR_H
 #include <error.h>
+#else
+#include "portability/error.h"
+#endif
 #include <errno.h>
 #include <unistd.h>
 #include <fcntl.h>
diff --git a/mtr.c b/mtr.c
index 47f5d2a863beecf08d4367d15480aa63231c0414..bc6d4bccd708ea308660b70fdb12a78da1c44f0e 100644 (file)
--- a/mtr.c
+++ b/mtr.c
 #include <errno.h>
 #include <string.h>
 #include <strings.h>
+#ifdef HAVE_ERROR_H
 #include <error.h>
+#else
+#include "portability/error.h"
+#endif
 #ifdef HAVE_VALUES_H
 #include <values.h>
 #endif
diff --git a/net.c b/net.c
index 32dcfac531704a11741359ea20432466ffaacc8a..964f50833005376330057289a326ead5b816b68d 100644 (file)
--- a/net.c
+++ b/net.c
 #include <math.h>
 #include <errno.h>
 #include <string.h>
+#ifdef HAVE_ERROR_H
 #include <error.h>
+#else
+#include "portability/error.h"
+#endif
 
 
 #include "mtr.h"
diff --git a/portability/.gitignore b/portability/.gitignore
new file mode 100644 (file)
index 0000000..229368a
--- /dev/null
@@ -0,0 +1,2 @@
+/.deps
+/.dirstamp
diff --git a/portability/error.c b/portability/error.c
new file mode 100644 (file)
index 0000000..99b7c99
--- /dev/null
@@ -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 <stdarg.h>
+#include <err.h>
+
+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 (file)
index 0000000..5efbaed
--- /dev/null
@@ -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, ...);
index 01e4b58f2beccb6bd04b6296764a939b39a110ff..cbf8e25f7932ff7109c9c9220cd26ba61c9848d1 100644 (file)
--- a/select.c
+++ b/select.c
 #include <string.h>
 #include <math.h>
 #include <errno.h>
+#ifdef HAVE_ERROR_H
 #include <error.h>
+#else
+#include "portability/error.h"
+#endif
 
 #include "mtr.h"
 #include "dns.h"