Blob Blame History Raw
From ac53807938f9a2e43401ab5b1b1c7f4dd80ac620 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <petr.pisar@atlas.cz>
Date: Fri, 6 Jul 2018 20:53:54 +0200
Subject: [PATCH] Prefer fgetxattr() from <sys/xattr.h>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

attr-2.4.48 removed <attr/xattr.h> and everybody should use glibc's
<sys/xattr.h> now.

This patch changes configure to check for both of the headers and to
prefer <sys/xattr.h>.

Signed-off-by: Petr Písař <petr.pisar@atlas.cz>
---
 INSTALL      |  5 +++--
 configure.ac | 16 ++++++++++++++--
 src/io.c     |  4 ++++
 3 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/INSTALL b/INSTALL
index 8528e74..80e9214 100644
--- a/INSTALL
+++ b/INSTALL
@@ -29,8 +29,9 @@ Additional configure options:
 
     --disable-xattr
 
-        Switch off extended attributes support. (Shigofumi can stores and load
-        MIME types there.) Support is autodetected by default.
+        Switch off extended attributes support. (Shigofumi can store and load
+        MIME types there.) Support is autodetected by default. You need glibc
+        >= 2.3 or attr library for this feature.
 
     --with-docbook-xsl-stylesheets=DIR
 
diff --git a/configure.ac b/configure.ac
index a875838..aa42aeb 100644
--- a/configure.ac
+++ b/configure.ac
@@ -117,12 +117,24 @@ AM_CONDITIONAL([BUILD_MANPO], [test "$HAVE_PO4A" = "yes"])
 
 # Check for extended attributes
 # XXX: AC_CHECK_HEADER() must be in top level scope
-AC_CHECK_HEADER([attr/xattr.h], [have_xattr=yes], [have_xattr=no])
+AC_CHECK_HEADER([sys/xattr.h],
+    [AC_DEFINE([HAVE_SYS_XATTR], [1], [Define if sys/xattr.h is available])
+        have_sys_xattr=yes],
+    [have_sys_xattr=no],
+    [#include <sys/types.h>
+     #include <sys/xattr.h>]
+)
+AC_CHECK_HEADER([attr/xattr.h],
+    [have_attr_xattr=yes],
+    [have_attr_xattr=no],
+    [#include <sys/types.h>
+     #include <attr/xattr.h>]
+)
 AC_ARG_ENABLE(xattr, [AS_HELP_STRING([--disable-xattr],
                         [Disable extended attribute support])])
 AS_IF([test "$enable_xattr" = "no"],
     AC_MSG_WARN([Extended attribute support disabled]),
-    AS_IF([test "$have_xattr" = "yes"],
+    AS_IF([test "$have_sys_xattr" = "yes" -o "$have_attr_xattr" = "yes"],
         AC_DEFINE([ENABLE_XATTR], [1],
             [Define if you want support extended attributes]),
         AS_IF([test "$enable_xattr" = "yes"],
diff --git a/src/io.c b/src/io.c
index 343f897..d2d7988 100644
--- a/src/io.c
+++ b/src/io.c
@@ -20,8 +20,12 @@
 #include "shigofumi.h"
 
 #if ENABLE_XATTR
+#if HAVE_SYS_XATTR
+#include <sys/xattr.h>
+#else
 #include <attr/xattr.h>
 #endif
+#endif
 
 
 /* Guess MIME type of @file by content.
-- 
2.14.4