mirror of
https://github.com/curl/curl.git
synced 2026-08-25 01:03:31 +03:00
xattr: add configure check and #ifdefs
setxattr is a glibc call to set extended attributes, so configure now checks for it and the code is adapted to only build when the functionality is present.
This commit is contained in:
parent
fbf51696ef
commit
95719fbea6
5 changed files with 152 additions and 10 deletions
10
src/main.c
10
src/main.c
|
|
@ -5648,12 +5648,10 @@ 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);
|
||||
int err = write_xattr( curl, outs.filename );
|
||||
if (err) {
|
||||
warnf( config, "Error setting extended attributes: %s\n", strerror(errno) );
|
||||
}
|
||||
int err = write_xattr(curl, outs.filename );
|
||||
if(err)
|
||||
warnf( config, "Error setting extended attributes: %s\n",
|
||||
strerror(errno) );
|
||||
}
|
||||
|
||||
#ifdef HAVE_UTIME
|
||||
|
|
|
|||
42
src/xattr.c
42
src/xattr.c
|
|
@ -1,9 +1,35 @@
|
|||
#include <sys/types.h>
|
||||
#include <sys/xattr.h> /* include header from libc, not from libattr */
|
||||
#include <string.h>
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 2010, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
*
|
||||
* This software is licensed as described in the file COPYING, which
|
||||
* you should have received as part of this distribution. The terms
|
||||
* are also available at http://curl.haxx.se/docs/copyright.html.
|
||||
*
|
||||
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
||||
* copies of the Software, and permit persons to whom the Software is
|
||||
* furnished to do so, under the terms of the COPYING file.
|
||||
*
|
||||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||
* KIND, either express or implied.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/* client-local setup.h */
|
||||
#include "setup.h"
|
||||
#include <curl/curl.h>
|
||||
#include "xattr.h"
|
||||
|
||||
#ifdef HAVE_SETXATTR
|
||||
#include <sys/types.h>
|
||||
#include <string.h>
|
||||
#include <sys/xattr.h> /* include header from libc, not from libattr */
|
||||
|
||||
/* mapping table of curl metadata to extended attribute names */
|
||||
static struct xattr_mapping {
|
||||
char *attr; /* name of the xattr */
|
||||
|
|
@ -20,7 +46,7 @@ static struct xattr_mapping {
|
|||
/* store metadata from the curl request alongside the downloaded
|
||||
* file using extended attributes
|
||||
*/
|
||||
int write_xattr( CURL *curl, const char *filename )
|
||||
int write_xattr(CURL *curl, const char *filename)
|
||||
{
|
||||
int i = 0;
|
||||
int err = 0;
|
||||
|
|
@ -35,3 +61,11 @@ int write_xattr( CURL *curl, const char *filename )
|
|||
}
|
||||
return err;
|
||||
}
|
||||
#else
|
||||
int write_xattr(CURL *curl, const char *filename)
|
||||
{
|
||||
(void)curl;
|
||||
(void)filename;
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
25
src/xattr.h
25
src/xattr.h
|
|
@ -1 +1,26 @@
|
|||
#ifndef __XATTR_H
|
||||
#define __XATTR_H
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 2010, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
*
|
||||
* This software is licensed as described in the file COPYING, which
|
||||
* you should have received as part of this distribution. The terms
|
||||
* are also available at http://curl.haxx.se/docs/copyright.html.
|
||||
*
|
||||
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
||||
* copies of the Software, and permit persons to whom the Software is
|
||||
* furnished to do so, under the terms of the COPYING file.
|
||||
*
|
||||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||
* KIND, either express or implied.
|
||||
*
|
||||
***************************************************************************/
|
||||
int write_xattr( CURL *curl, const char *filename );
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue