2
* Copyright (c) 2003-2007 Tim Kientzle
5
* Redistribution and use in source and binary forms, with or without
6
* modification, are permitted provided that the following conditions
8
* 1. Redistributions of source code must retain the above copyright
9
* notice, this list of conditions and the following disclaimer.
10
* 2. Redistributions in binary form must reproduce the above copyright
11
* notice, this list of conditions and the following disclaimer in the
12
* documentation and/or other materials provided with the distribution.
14
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
15
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17
* IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
18
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
#include "archive_platform.h"
27
__FBSDID("$FreeBSD: head/lib/libarchive/archive_entry_xattr.c 201096 2009-12-28 02:41:27Z kientzle $");
29
#ifdef HAVE_SYS_STAT_H
32
#ifdef HAVE_SYS_TYPES_H
33
#include <sys/types.h>
38
#ifdef HAVE_LINUX_FS_H
39
#include <linux/fs.h> /* for Linux file flags */
42
* Some Linux distributions have both linux/ext2_fs.h and ext2fs/ext2_fs.h.
43
* As the include guards don't agree, the order of include is important.
45
#ifdef HAVE_LINUX_EXT2_FS_H
46
#include <linux/ext2_fs.h> /* for Linux file flags */
48
#if defined(HAVE_EXT2FS_EXT2_FS_H) && !defined(__CYGWIN__)
49
#include <ext2fs/ext2_fs.h> /* for Linux file flags */
64
#include "archive_entry.h"
65
#include "archive_private.h"
66
#include "archive_entry_private.h"
69
* extended attribute handling
73
archive_entry_xattr_clear(struct archive_entry *entry)
77
while (entry->xattr_head != NULL) {
78
xp = entry->xattr_head->next;
79
free(entry->xattr_head->name);
80
free(entry->xattr_head->value);
81
free(entry->xattr_head);
82
entry->xattr_head = xp;
85
entry->xattr_head = NULL;
89
archive_entry_xattr_add_entry(struct archive_entry *entry,
90
const char *name, const void *value, size_t size)
94
for (xp = entry->xattr_head; xp != NULL; xp = xp->next)
97
if ((xp = (struct ae_xattr *)malloc(sizeof(struct ae_xattr))) == NULL)
101
xp->name = strdup(name);
102
if ((xp->value = malloc(size)) != NULL) {
103
memcpy(xp->value, value, size);
108
xp->next = entry->xattr_head;
109
entry->xattr_head = xp;
114
* returns number of the extended attribute entries
117
archive_entry_xattr_count(struct archive_entry *entry)
122
for (xp = entry->xattr_head; xp != NULL; xp = xp->next)
129
archive_entry_xattr_reset(struct archive_entry * entry)
131
entry->xattr_p = entry->xattr_head;
133
return archive_entry_xattr_count(entry);
137
archive_entry_xattr_next(struct archive_entry * entry,
138
const char **name, const void **value, size_t *size)
140
if (entry->xattr_p) {
141
*name = entry->xattr_p->name;
142
*value = entry->xattr_p->value;
143
*size = entry->xattr_p->size;
145
entry->xattr_p = entry->xattr_p->next;
152
return (ARCHIVE_WARN);
157
* end of xattr handling