OSDN Git Service

scanpci: Build fix for systems without <err.h>
authorJeremy Huddleston <jeremyhu@apple.com>
Sun, 9 Oct 2011 10:53:05 +0000 (03:53 -0700)
committerJeremy Huddleston <jeremyhu@apple.com>
Sun, 9 Oct 2011 10:53:05 +0000 (03:53 -0700)
https://bugs.freedesktop.org/show_bug.cgi?id=31133

Signed-off-by: Jeremy Huddleston <jeremyhu@apple.com>
configure.ac
scanpci/scanpci.c

index 476a4bf..d622961 100644 (file)
@@ -106,6 +106,8 @@ AM_CONDITIONAL(GNU, [test "x$gnu" = xyes])
 
 AC_SYS_LARGEFILE
 
+AC_CHECK_HEADERS([err.h])
+
 AC_CHECK_HEADER([asm/mtrr.h], [have_mtrr_h="yes"], [have_mtrr_h="no"])
 
 if test "x$have_mtrr_h" = xyes; then
index 36ecf04..219c814 100644 (file)
  * DEALINGS IN THE SOFTWARE.
  */
 
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
 #include <stdlib.h>
 #include <stdio.h>
-#include <err.h>
 #include <unistd.h>
 
+#ifdef HAVE_ERR_H
+#include <err.h>
+#else
+# include <errno.h>
+# include <string.h>
+# define err(exitcode, format, args...) \
+   errx(exitcode, format ": %s", ## args, strerror(errno))
+# define errx(exitcode, format, args...) \
+   { warnx(format, ## args); exit(exitcode); }
+# define warn(format, args...) \
+   warnx(format ": %s", ## args, strerror(errno))
+# define warnx(format, args...) \
+   fprintf(stderr, format "\n", ## args)
+#endif
+
 #include "pciaccess.h"