From 99d509e406a83dd9cdb2960c9e6b453baff420ea Mon Sep 17 00:00:00 2001
From: Kamil Dudka <kdudka@redhat.com>
Date: Fri, 5 Nov 2010 14:21:10 +0100
Subject: [PATCH] xattr: add a configure check for xattr support

It checks for a system header <sys/xattr.h> and the function setxattr().
Even if both are available, the xattr support may be disabled by the
configure option --disable-xattr.
---
 configure.ac |   28 ++++++++++++++++++++++++++++
 src/main.c   |    8 +++++---
 src/xattr.c  |    4 ++++
 3 files changed, 37 insertions(+), 3 deletions(-)

diff --git a/configure.ac b/configure.ac
index 224ca2d..a5a4c78 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2650,6 +2650,33 @@ AC_HELP_STRING([--disable-hidden-symbols],[Leave all symbols with default visibi
 )
 
 dnl ************************************************************
+dnl check whether to build xattr support
+dnl
+
+dnl Verify if configure has been invoked with option --enable-xattr or
+dnl --disable-xattr, and set shell variable want_xattr as appropriate.
+AC_MSG_CHECKING([whether to enable xattr support])
+AC_ARG_ENABLE([xattr],
+  AC_HELP_STRING([--disable-xattr],[Disable xattr support (default: auto)]),
+  [want_xattr=$enableval],
+  [want_xattr=auto])
+AC_MSG_RESULT([$want_xattr])
+
+dnl now check the presence of <sys/xattr.h> and the function setxattr()
+curl_xattr_msg=disabled
+if test xno != "x$want_xattr"; then
+  AC_CHECK_HEADER([sys/xattr.h],
+    AC_CHECK_FUNC([setxattr], [curl_xattr_msg=enabled]))
+  if xyes = "x$want_xattr"; then
+    AC_MSG_WARN([xattr support will not be built])
+  fi
+fi
+if test enabled = $curl_xattr_msg; then
+  AC_DEFINE(USE_XATTR, 1, [if you want to build xattr support])
+fi
+
+
+dnl ************************************************************
 dnl enforce SONAME bump
 dnl
 
@@ -2888,6 +2915,7 @@ AC_MSG_NOTICE([Configured to build curl/libcurl:
   LDAPS support:   ${curl_ldaps_msg}
   RTSP support:    ${curl_rtsp_msg}
   RTMP support:    ${curl_rtmp_msg}
+  xattr support:   ${curl_xattr_msg}
   Protocols:       ${SUPPORT_PROTOCOLS}
 ])
 
diff --git a/src/main.c b/src/main.c
index 5394bac..7dc8b7b 100644
--- a/src/main.c
+++ b/src/main.c
@@ -5648,12 +5648,14 @@ operate(struct Configurable *config, int argc, argv_item_t argv[])
         }
 
         if(config->xattr && outs.filename) {
-          char *url = NULL;
-          curl_easy_getinfo(curl, CURLINFO_EFFECTIVE_URL, &url);
+#ifdef USE_XATTR
           int err = write_xattr( curl, outs.filename );
           if (err) {
-            warnf( config, "Error setting extended attributes: %s\n", strerror(errno) );
+            warnf(config, "Error setting extended attributes: %s\n", strerror(errno));
           }
+#else
+          warnf(config, "xattr support is not compiled in\n");
+#endif
         }
 
 #ifdef HAVE_UTIME
diff --git a/src/xattr.c b/src/xattr.c
index fbc09c2..0865afe 100644
--- a/src/xattr.c
+++ b/src/xattr.c
@@ -1,3 +1,5 @@
+#if USE_XATTR
+
 #include <sys/types.h>
 #include <sys/xattr.h> /* include header from libc, not from libattr */
 #include <string.h>
@@ -35,3 +37,5 @@ int write_xattr( CURL *curl, const char *filename )
   }
   return err;
 }
+
+#endif
-- 
1.7.2.3


