cmake/Utilities/cmlibarchive/libarchive/archive_entry_xattr.c

157 lines
3.9 KiB
C
Raw Normal View History

2010-06-23 01:18:35 +03:00
/*-
* Copyright (c) 2003-2007 Tim Kientzle
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "archive_platform.h"
2012-04-19 19:04:21 +03:00
__FBSDID("$FreeBSD: head/lib/libarchive/archive_entry_xattr.c 201096 2009-12-28 02:41:27Z kientzle $");
2010-06-23 01:18:35 +03:00
#ifdef HAVE_SYS_STAT_H
#include <sys/stat.h>
#endif
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#ifdef HAVE_LIMITS_H
#include <limits.h>
#endif
#ifdef HAVE_LINUX_FS_H
2012-04-19 19:04:21 +03:00
#include <linux/fs.h> /* for Linux file flags */
2010-06-23 01:18:35 +03:00
#endif
/*
* Some Linux distributions have both linux/ext2_fs.h and ext2fs/ext2_fs.h.
* As the include guards don't agree, the order of include is important.
*/
#ifdef HAVE_LINUX_EXT2_FS_H
2012-04-19 19:04:21 +03:00
#include <linux/ext2_fs.h> /* for Linux file flags */
2010-06-23 01:18:35 +03:00
#endif
#if defined(HAVE_EXT2FS_EXT2_FS_H) && !defined(__CYGWIN__)
2012-04-19 19:04:21 +03:00
#include <ext2fs/ext2_fs.h> /* for Linux file flags */
2010-06-23 01:18:35 +03:00
#endif
#include <stddef.h>
#include <stdio.h>
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#ifdef HAVE_STRING_H
#include <string.h>
#endif
#ifdef HAVE_WCHAR_H
#include <wchar.h>
#endif
#include "archive.h"
#include "archive_entry.h"
#include "archive_private.h"
#include "archive_entry_private.h"
/*
* extended attribute handling
*/
void
archive_entry_xattr_clear(struct archive_entry *entry)
{
2012-04-19 19:04:21 +03:00
struct ae_xattr *xp;
2010-06-23 01:18:35 +03:00
2012-04-19 19:04:21 +03:00
while (entry->xattr_head != NULL) {
xp = entry->xattr_head->next;
free(entry->xattr_head->name);
free(entry->xattr_head->value);
free(entry->xattr_head);
entry->xattr_head = xp;
}
2010-06-23 01:18:35 +03:00
2012-04-19 19:04:21 +03:00
entry->xattr_head = NULL;
2010-06-23 01:18:35 +03:00
}
void
archive_entry_xattr_add_entry(struct archive_entry *entry,
2012-04-19 19:04:21 +03:00
const char *name, const void *value, size_t size)
2010-06-23 01:18:35 +03:00
{
2012-04-19 19:04:21 +03:00
struct ae_xattr *xp;
2010-06-23 01:18:35 +03:00
2012-04-19 19:04:21 +03:00
if ((xp = (struct ae_xattr *)malloc(sizeof(struct ae_xattr))) == NULL)
2016-07-09 11:21:54 +02:00
__archive_errx(1, "Out of memory");
2010-06-23 01:18:35 +03:00
2016-03-13 13:35:51 +01:00
if ((xp->name = strdup(name)) == NULL)
2016-07-09 11:21:54 +02:00
__archive_errx(1, "Out of memory");
2016-03-13 13:35:51 +01:00
2012-04-19 19:04:21 +03:00
if ((xp->value = malloc(size)) != NULL) {
memcpy(xp->value, value, size);
xp->size = size;
} else
xp->size = 0;
2010-06-23 01:18:35 +03:00
2012-04-19 19:04:21 +03:00
xp->next = entry->xattr_head;
entry->xattr_head = xp;
2010-06-23 01:18:35 +03:00
}
/*
* returns number of the extended attribute entries
*/
int
archive_entry_xattr_count(struct archive_entry *entry)
{
2012-04-19 19:04:21 +03:00
struct ae_xattr *xp;
int count = 0;
2010-06-23 01:18:35 +03:00
2012-04-19 19:04:21 +03:00
for (xp = entry->xattr_head; xp != NULL; xp = xp->next)
count++;
2010-06-23 01:18:35 +03:00
2012-04-19 19:04:21 +03:00
return count;
2010-06-23 01:18:35 +03:00
}
int
archive_entry_xattr_reset(struct archive_entry * entry)
{
2012-04-19 19:04:21 +03:00
entry->xattr_p = entry->xattr_head;
2010-06-23 01:18:35 +03:00
2012-04-19 19:04:21 +03:00
return archive_entry_xattr_count(entry);
2010-06-23 01:18:35 +03:00
}
int
archive_entry_xattr_next(struct archive_entry * entry,
2012-04-19 19:04:21 +03:00
const char **name, const void **value, size_t *size)
2010-06-23 01:18:35 +03:00
{
2012-04-19 19:04:21 +03:00
if (entry->xattr_p) {
*name = entry->xattr_p->name;
*value = entry->xattr_p->value;
*size = entry->xattr_p->size;
entry->xattr_p = entry->xattr_p->next;
return (ARCHIVE_OK);
} else {
*name = NULL;
*value = NULL;
*size = (size_t)0;
return (ARCHIVE_WARN);
}
2010-06-23 01:18:35 +03:00
}
/*
* end of xattr handling
*/