/src/CMake/Utilities/cmlibarchive/libarchive/archive_entry_xattr.c
Line | Count | Source |
1 | | /*- |
2 | | * Copyright (c) 2003-2007 Tim Kientzle |
3 | | * All rights reserved. |
4 | | * |
5 | | * Redistribution and use in source and binary forms, with or without |
6 | | * modification, are permitted provided that the following conditions |
7 | | * are met: |
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. |
13 | | * |
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. |
24 | | */ |
25 | | |
26 | | #include "archive_platform.h" |
27 | | |
28 | | #ifdef HAVE_SYS_STAT_H |
29 | | #include <sys/stat.h> |
30 | | #endif |
31 | | #ifdef HAVE_SYS_TYPES_H |
32 | | #include <sys/types.h> |
33 | | #endif |
34 | | #ifdef HAVE_LIMITS_H |
35 | | #include <limits.h> |
36 | | #endif |
37 | | #ifdef HAVE_LINUX_FS_H |
38 | | #include <linux/fs.h> /* for Linux file flags */ |
39 | | #endif |
40 | | /* |
41 | | * Some Linux distributions have both linux/ext2_fs.h and ext2fs/ext2_fs.h. |
42 | | * As the include guards don't agree, the order of include is important. |
43 | | */ |
44 | | #ifdef HAVE_LINUX_EXT2_FS_H |
45 | | #include <linux/ext2_fs.h> /* for Linux file flags */ |
46 | | #endif |
47 | | #if defined(HAVE_EXT2FS_EXT2_FS_H) && !defined(__CYGWIN__) |
48 | | #include <ext2fs/ext2_fs.h> /* for Linux file flags */ |
49 | | #endif |
50 | | #include <stddef.h> |
51 | | #include <stdio.h> |
52 | | #ifdef HAVE_STDLIB_H |
53 | | #include <stdlib.h> |
54 | | #endif |
55 | | #ifdef HAVE_STRING_H |
56 | | #include <string.h> |
57 | | #endif |
58 | | #ifdef HAVE_WCHAR_H |
59 | | #include <wchar.h> |
60 | | #endif |
61 | | |
62 | | #include "archive.h" |
63 | | #include "archive_entry.h" |
64 | | #include "archive_private.h" |
65 | | #include "archive_entry_private.h" |
66 | | |
67 | | /* |
68 | | * extended attribute handling |
69 | | */ |
70 | | |
71 | | void |
72 | | archive_entry_xattr_clear(struct archive_entry *entry) |
73 | 45.4k | { |
74 | 45.4k | struct ae_xattr *xp; |
75 | | |
76 | 45.4k | while (entry->xattr_head != NULL) { |
77 | 0 | xp = entry->xattr_head->next; |
78 | 0 | free(entry->xattr_head->name); |
79 | 0 | free(entry->xattr_head->value); |
80 | 0 | free(entry->xattr_head); |
81 | 0 | entry->xattr_head = xp; |
82 | 0 | } |
83 | | |
84 | 45.4k | entry->xattr_head = NULL; |
85 | 45.4k | } |
86 | | |
87 | | void |
88 | | archive_entry_xattr_add_entry(struct archive_entry *entry, |
89 | | const char *name, const void *value, size_t size) |
90 | 0 | { |
91 | 0 | struct ae_xattr *xp; |
92 | |
|
93 | 0 | if ((xp = malloc(sizeof(struct ae_xattr))) == NULL) |
94 | 0 | __archive_errx(1, "Out of memory"); |
95 | | |
96 | 0 | if ((xp->name = strdup(name)) == NULL) |
97 | 0 | __archive_errx(1, "Out of memory"); |
98 | | |
99 | 0 | if ((xp->value = malloc(size)) != NULL) { |
100 | 0 | memcpy(xp->value, value, size); |
101 | 0 | xp->size = size; |
102 | 0 | } else |
103 | 0 | xp->size = 0; |
104 | |
|
105 | 0 | xp->next = entry->xattr_head; |
106 | 0 | entry->xattr_head = xp; |
107 | 0 | } |
108 | | |
109 | | |
110 | | /* |
111 | | * returns number of the extended attribute entries |
112 | | */ |
113 | | int |
114 | | archive_entry_xattr_count(struct archive_entry *entry) |
115 | 0 | { |
116 | 0 | struct ae_xattr *xp; |
117 | 0 | int count = 0; |
118 | |
|
119 | 0 | for (xp = entry->xattr_head; xp != NULL; xp = xp->next) |
120 | 0 | count++; |
121 | |
|
122 | 0 | return count; |
123 | 0 | } |
124 | | |
125 | | int |
126 | | archive_entry_xattr_reset(struct archive_entry * entry) |
127 | 0 | { |
128 | 0 | entry->xattr_p = entry->xattr_head; |
129 | |
|
130 | 0 | return archive_entry_xattr_count(entry); |
131 | 0 | } |
132 | | |
133 | | int |
134 | | archive_entry_xattr_next(struct archive_entry * entry, |
135 | | const char **name, const void **value, size_t *size) |
136 | 0 | { |
137 | 0 | if (entry->xattr_p) { |
138 | 0 | *name = entry->xattr_p->name; |
139 | 0 | *value = entry->xattr_p->value; |
140 | 0 | *size = entry->xattr_p->size; |
141 | |
|
142 | 0 | entry->xattr_p = entry->xattr_p->next; |
143 | |
|
144 | 0 | return (ARCHIVE_OK); |
145 | 0 | } else { |
146 | 0 | *name = NULL; |
147 | 0 | *value = NULL; |
148 | 0 | *size = (size_t)0; |
149 | 0 | return (ARCHIVE_WARN); |
150 | 0 | } |
151 | 0 | } |
152 | | |
153 | | /* |
154 | | * end of xattr handling |
155 | | */ |