# else
# define WIMLIBAPI __attribute__((visibility("default")))
# endif
-# define ALWAYS_INLINE inline __attribute__((always_inline))
-# define PACKED __attribute__((packed))
-# define FORMAT(type, format_str, args_start) \
+# define _always_inline_attribute inline __attribute__((always_inline))
+# define _packed_attribute __attribute__((packed))
+# define _format_attribute(type, format_str, args_start) \
/*__attribute__((format(type, format_str, args_start))) */
# if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4)
-# define COLD __attribute__((cold))
+# define _cold_attribute __attribute__((cold))
# else
-# define COLD
+# define _cold_attribute
# endif
+# define _malloc_attribute __attribute__((malloc))
+# define _warn_unused_result_attribute __attribute__((warn_unused_result))
#else
# define WIMLIBAPI
-# define ALWAYS_INLINE inline
-# define FORMAT(type, format_str, args_start)
-# define COLD
-# define PACKED
+# define _always_inline_attribute inline
+# define _format_attribute(type, format_str, args_start)
+# define _cold_attribute
+# define _packed_attribute
+# define _malloc_attribute
+# define _warn_unused_result_attribute
#endif /* __GNUC__ */
#endif /* _WIMLIB_COMPILER_H */
int num_bytes_remaining;
};
-static inline int bitstream_put_byte(struct output_bitstream *ostream,
- u8 n)
+static inline int
+bitstream_put_byte(struct output_bitstream *ostream, u8 n)
{
if (ostream->num_bytes_remaining < 1)
return 1;
return 0;
}
-static inline int bitstream_put_two_bytes(struct output_bitstream *ostream,
- u16 n)
+static inline int
+bitstream_put_two_bytes(struct output_bitstream *ostream, u16 n)
{
if (ostream->num_bytes_remaining < 2)
return 1;
typedef unsigned (*lz_record_match_t)(unsigned, unsigned, void *, void *);
typedef unsigned (*lz_record_literal_t)(u8, void *);
-extern unsigned lz_analyze_block(const u8 uncompressed_data[],
- unsigned uncompressed_len,
- u32 match_tab[],
- lz_record_match_t record_match,
- lz_record_literal_t record_literal,
- void *record_match_arg1,
- void *record_match_arg2,
- void *record_literal_arg,
- const struct lz_params *params);
+extern unsigned
+lz_analyze_block(const u8 uncompressed_data[],
+ unsigned uncompressed_len,
+ u32 match_tab[],
+ lz_record_match_t record_match,
+ lz_record_literal_t record_literal,
+ void *record_match_arg1,
+ void *record_match_arg2,
+ void *record_literal_arg,
+ const struct lz_params *params);
extern int bitstream_put_bits(struct output_bitstream *ostream,
output_bitbuf_t bits, unsigned num_bits);
-extern void init_output_bitstream(struct output_bitstream *ostream,
- void *data, unsigned num_bytes);
+extern void
+init_output_bitstream(struct output_bitstream *ostream,
+ void *data, unsigned num_bytes);
-extern int flush_output_bitstream(struct output_bitstream *ostream);
+extern int
+flush_output_bitstream(struct output_bitstream *ostream);
-extern void make_canonical_huffman_code(unsigned num_syms,
- unsigned max_codeword_len,
- const freq_t freq_tab[],
- u8 lens[],
- u16 codewords[]);
+extern void
+make_canonical_huffman_code(unsigned num_syms,
+ unsigned max_codeword_len,
+ const freq_t freq_tab[],
+ u8 lens[],
+ u16 codewords[]);
#endif /* _WIMLIB_COMPRESS_H */
* directory in the decode_table, as the
* decode_table contains 2**table_bits entries.
*/
-static inline int
+static _always_inline_attribute int
read_huffsym(struct input_bitstream *istream,
const u16 decode_table[],
const u8 lens[],
return ret;
}
-extern int make_huffman_decode_table(u16 decode_table[], unsigned num_syms,
- unsigned num_bits, const u8 lengths[],
- unsigned max_codeword_len);
+extern int
+make_huffman_decode_table(u16 decode_table[], unsigned num_syms,
+ unsigned num_bits, const u8 lengths[],
+ unsigned max_codeword_len);
#endif /* _WIMLIB_DECOMPRESS_H */
# define wimlib_printf wprintf
#else /* __WIN32__ */
extern int
-wimlib_fprintf(FILE *fp, const tchar *format, ...) FORMAT(printf, 2, 3);
+wimlib_fprintf(FILE *fp, const tchar *format, ...) _format_attribute(printf, 2, 3);
extern int
-wimlib_printf(const tchar *format, ...) FORMAT(printf, 1, 2);
+wimlib_printf(const tchar *format, ...) _format_attribute(printf, 1, 2);
#endif /* !__WIN32__ */
-static inline int dummy_tprintf(const tchar *format, ...)
+static inline int
+dummy_tprintf(const tchar *format, ...) _format_attribute(printf, 1, 2)
{
return 0;
}
#ifdef ENABLE_ERROR_MESSAGES
extern void
-wimlib_error(const tchar *format, ...) FORMAT(printf, 1, 2) COLD;
+wimlib_error(const tchar *format, ...)
+ _format_attribute(printf, 1, 2) _cold_attribute;
extern void
-wimlib_error_with_errno(const tchar *format, ...) FORMAT(printf, 1, 2) COLD;
+wimlib_error_with_errno(const tchar *format, ...)
+ _format_attribute(printf, 1, 2) _cold_attribute;
extern void
-wimlib_warning(const tchar *format, ...) FORMAT(printf, 1, 2) COLD;
+wimlib_warning(const tchar *format, ...)
+ _format_attribute(printf, 1, 2) _cold_attribute;
extern void
-wimlib_warning_with_errno(const tchar *format, ...) FORMAT(printf, 1, 2) COLD;
+wimlib_warning_with_errno(const tchar *format, ...)
+ _format_attribute(printf, 1, 2) _cold_attribute;
# define ERROR(format, ...) wimlib_error(T(format), ## __VA_ARGS__)
# define ERROR_WITH_ERRNO(format, ...) wimlib_error_with_errno(T(format), ## __VA_ARGS__)
# define WARNING(format, ...) wimlib_warning(T(format), ## __VA_ARGS__)
}
extern struct wim_lookup_table *
-new_lookup_table(size_t capacity);
+new_lookup_table(size_t capacity) _malloc_attribute;
extern int
read_lookup_table(WIMStruct *w);
}
extern struct wim_lookup_table_entry *
-new_lookup_table_entry(void);
+new_lookup_table_entry(void) _malloc_attribute;
extern struct wim_lookup_table_entry *
-clone_lookup_table_entry(const struct wim_lookup_table_entry *lte);
+clone_lookup_table_entry(const struct wim_lookup_table_entry *lte)
+ _malloc_attribute;
extern void
print_lookup_table_entry(const struct wim_lookup_table_entry *entry,
#ifndef _WIMLIB_PATHS_H
#define _WIMLIB_PATHS_H
+#include "wimlib/compiler.h"
#include "wimlib/types.h"
const tchar *
zap_backslashes(tchar *s);
extern tchar *
-canonicalize_wim_path(const tchar *wim_path);
+canonicalize_wim_path(const tchar *wim_path) _malloc_attribute;
extern tchar *
-canonicalize_fs_path(const tchar *fs_path);
+canonicalize_fs_path(const tchar *fs_path) _malloc_attribute;
#endif /* _WIMLIB_PATHS_H */
print_security_data(const struct wim_security_data *sd);
extern u8 *
-write_security_data(const struct wim_security_data *sd, u8 *p);
+write_security_data(const struct wim_security_data * restrict sd,
+ u8 * restrict p);
extern void
free_security_data(struct wim_security_data *sd);
typedef int16_t s16;
typedef int32_t s32;
typedef int64_t s64;
+
+/* Unsigned little endian types of exact size */
+typedef uint8_t le8;
+typedef uint16_t le16;
+typedef uint32_t le32;
+typedef uint64_t le64;
+
+/* Signed little endian types of exact size (declare as unsigned to avoid sign
+ * extension on big-endian architectures) */
+typedef uint8_t sle8;
+typedef uint16_t sle16;
+typedef uint32_t sle32;
+typedef uint64_t sle64;
#endif
/* A pointer to 'utf16lechar' indicates a UTF-16LE encoded string */
#define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))
#ifdef ENABLE_CUSTOM_MEMORY_ALLOCATOR
-extern void *(*wimlib_malloc_func)(size_t);
-extern void (*wimlib_free_func)(void *);
-extern void *(*wimlib_realloc_func)(void *, size_t);
-extern void *wimlib_calloc(size_t nmemb, size_t size);
+extern void *
+wimlib_malloc(size_t) _malloc_attribute;
+
+extern void
+wimlib_free_memory(void *p);
+
+extern void *
+wimlib_realloc(void *, size_t) _warn_unused_result_attribute;
+
+extern void *
+wimlib_calloc(size_t nmemb, size_t size) _malloc_attribute;
+
#ifdef __WIN32__
-extern wchar_t *wimlib_wcsdup(const wchar_t *str);
+extern wchar_t *
+wimlib_wcsdup(const wchar_t *str) _malloc_attribute;
+
#endif
-extern char *wimlib_strdup(const char *str);
-# define MALLOC wimlib_malloc_func
-# define FREE wimlib_free_func
-# define REALLOC wimlib_realloc_func
+extern char *
+wimlib_strdup(const char *str) _malloc_attribute;
+
+# define MALLOC wimlib_malloc
+# define FREE wimlib_free_memory
+# define REALLOC wimlib_realloc
# define CALLOC wimlib_calloc
# define STRDUP wimlib_strdup
# define WSTRDUP wimlib_wcsdup
/* Initializes an output bit buffer to write its output to the memory location
* pointer to by @data. */
void
-init_output_bitstream(struct output_bitstream *ostream, void *data,
- unsigned num_bytes)
+init_output_bitstream(struct output_bitstream *ostream,
+ void *data, unsigned num_bytes)
{
wimlib_assert(num_bytes >= 4);
ostream->bitbuf = 0;
ostream->free_bits = 16;
- ostream->bit_output = (u8*)data;
- ostream->next_bit_output = (u8*)data + 2;
- ostream->output = (u8*)data + 4;
+ ostream->bit_output = data;
+ ostream->next_bit_output = data + 2;
+ ostream->output = data + 4;
ostream->num_bytes_remaining = num_bytes - 4;
}
-/* Intermediate (non-leaf) node in a Huffman tree. */
-typedef struct HuffmanNode {
+typedef struct {
u32 freq;
u16 sym;
union {
u16 path_len;
u16 height;
};
- struct HuffmanNode *left_child;
- struct HuffmanNode *right_child;
} HuffmanNode;
-/* Leaf node in a Huffman tree. The fields are in the same order as the
- * HuffmanNode, so it can be cast to a HuffmanNode. There are no pointers to
- * the children in the leaf node. */
-typedef struct {
- u32 freq;
- u16 sym;
- union {
- u16 path_len;
- u16 height;
- };
-} HuffmanLeafNode;
+typedef struct HuffmanIntermediateNode {
+ HuffmanNode node_base;
+ HuffmanNode *left_child;
+ HuffmanNode *right_child;
+} HuffmanIntermediateNode;
-/* Comparator function for HuffmanLeafNodes. Sorts primarily by symbol
+
+/* Comparator function for HuffmanNodes. Sorts primarily by symbol
* frequency and secondarily by symbol value. */
static int
-cmp_leaves_by_freq(const void *__leaf1, const void *__leaf2)
+cmp_nodes_by_freq(const void *_leaf1, const void *_leaf2)
{
- const HuffmanLeafNode *leaf1 = __leaf1;
- const HuffmanLeafNode *leaf2 = __leaf2;
+ const HuffmanNode *leaf1 = _leaf1;
+ const HuffmanNode *leaf2 = _leaf2;
int freq_diff = (int)leaf1->freq - (int)leaf2->freq;
return freq_diff;
}
-/* Comparator function for HuffmanLeafNodes. Sorts primarily by code length and
+/* Comparator function for HuffmanNodes. Sorts primarily by code length and
* secondarily by symbol value. */
static int
-cmp_leaves_by_code_len(const void *__leaf1, const void *__leaf2)
+cmp_nodes_by_code_len(const void *_leaf1, const void *_leaf2)
{
- const HuffmanLeafNode *leaf1 = __leaf1;
- const HuffmanLeafNode *leaf2 = __leaf2;
+ const HuffmanNode *leaf1 = _leaf1;
+ const HuffmanNode *leaf2 = _leaf2;
int code_len_diff = (int)leaf1->path_len - (int)leaf2->path_len;
return code_len_diff;
}
+#define INVALID_SYMBOL 0xffff
+
/* Recursive function to calculate the depth of the leaves in a Huffman tree.
* */
static void
-huffman_tree_compute_path_lengths(HuffmanNode *node, u16 cur_len)
+huffman_tree_compute_path_lengths(HuffmanNode *base_node, u16 cur_len)
{
- if (node->sym == (u16)(-1)) {
+ if (base_node->sym == INVALID_SYMBOL) {
/* Intermediate node. */
+ HuffmanIntermediateNode *node = (HuffmanIntermediateNode*)base_node;
huffman_tree_compute_path_lengths(node->left_child, cur_len + 1);
huffman_tree_compute_path_lengths(node->right_child, cur_len + 1);
} else {
/* Leaf node. */
- node->path_len = cur_len;
+ base_node->path_len = cur_len;
}
}
* for symbol i.
*/
void
-make_canonical_huffman_code(unsigned num_syms, unsigned max_codeword_len,
- const freq_t freq_tab[], u8 lens[],
- u16 codewords[])
+make_canonical_huffman_code(unsigned num_syms,
+ unsigned max_codeword_len,
+ const freq_t * restrict freq_tab,
+ u8 * restrict lens,
+ u16 * restrict codewords)
{
/* We require at least 2 possible symbols in the alphabet to produce a
* valid Huffman decoding table. It is allowed that fewer than 2 symbols
/* Initialize the array of leaf nodes with the symbols and their
* frequencies. */
- HuffmanLeafNode leaves[num_used_symbols];
+ HuffmanNode leaves[num_used_symbols];
unsigned leaf_idx = 0;
for (unsigned i = 0; i < num_syms; i++) {
if (freq_tab[i] != 0) {
* format constrains codes to 16 bits or less each. However, it is
* still possible for there to be more than 16 intermediate nodes, as
* long as no leaf has a depth of more than 16. */
- HuffmanNode inodes[num_used_symbols - 1];
+ HuffmanIntermediateNode inodes[num_used_symbols - 1];
/* Pointer to the leaf node of lowest frequency that hasn't already been
* added as the child of some intermediate note. */
- HuffmanLeafNode *cur_leaf;
+ HuffmanNode *cur_leaf;
/* Pointer past the end of the array of leaves. */
- HuffmanLeafNode *end_leaf = &leaves[num_used_symbols];
+ HuffmanNode *end_leaf = &leaves[num_used_symbols];
/* Pointer to the intermediate node of lowest frequency. */
- HuffmanNode *cur_inode;
+ HuffmanIntermediateNode *cur_inode;
/* Pointer to the next unallocated intermediate node. */
- HuffmanNode *next_inode;
+ HuffmanIntermediateNode *next_inode;
/* Only jump back to here if the maximum length of the codewords allowed
* by the LZX format (16 bits) is exceeded. */
/* Sort the leaves from those that correspond to the least frequent
* symbol, to those that correspond to the most frequent symbol. If two
* leaves have the same frequency, they are sorted by symbol. */
- qsort(leaves, num_used_symbols, sizeof(leaves[0]), cmp_leaves_by_freq);
+ qsort(leaves, num_used_symbols, sizeof(leaves[0]), cmp_nodes_by_freq);
cur_leaf = &leaves[0];
cur_inode = &inodes[0];
* remaining leaves or from the intermediate nodes. */
if (cur_leaf != end_leaf && (cur_inode == next_inode ||
- cur_leaf->freq <= cur_inode->freq)) {
- f1 = (HuffmanNode*)cur_leaf++;
+ cur_leaf->freq <= cur_inode->node_base.freq)) {
+ f1 = cur_leaf++;
} else if (cur_inode != next_inode) {
- f1 = cur_inode++;
+ f1 = (HuffmanNode*)cur_inode++;
}
if (cur_leaf != end_leaf && (cur_inode == next_inode ||
- cur_leaf->freq <= cur_inode->freq)) {
- f2 = (HuffmanNode*)cur_leaf++;
+ cur_leaf->freq <= cur_inode->node_base.freq)) {
+ f2 = cur_leaf++;
} else if (cur_inode != next_inode) {
- f2 = cur_inode++;
+ f2 = (HuffmanNode*)cur_inode++;
} else {
/* All nodes used up! */
break;
/* next_inode becomes the parent of f1 and f2. */
- next_inode->freq = f1->freq + f2->freq;
- next_inode->sym = (u16)(-1); /* Invalid symbol. */
- next_inode->left_child = f1;
- next_inode->right_child = f2;
+ next_inode->node_base.freq = f1->freq + f2->freq;
+ next_inode->node_base.sym = INVALID_SYMBOL;
+ next_inode->left_child = f1;
+ next_inode->right_child = f2;
/* We need to keep track of the height so that we can detect if
* the length of a codeword has execeed max_codeword_len. The
* parent node has a height one higher than the maximum height
* of its children. */
- next_inode->height = max(f1->height, f2->height) + 1;
+ next_inode->node_base.height = max(f1->height, f2->height) + 1;
/* Check to see if the code length of the leaf farthest away
* from next_inode has exceeded the maximum code length. */
- if (next_inode->height > max_codeword_len) {
+ if (next_inode->node_base.height > max_codeword_len) {
/* The code lengths can be made more uniform by making
* the frequencies more uniform. Divide all the
* frequencies by 2, leaving 1 as the minimum frequency.
/* The Huffman tree is now complete, and its height is no more than
* max_codeword_len. */
- HuffmanNode *root = next_inode - 1;
- wimlib_assert(root->height <= max_codeword_len);
+ HuffmanIntermediateNode *root = next_inode - 1;
+ wimlib_assert(root->node_base.height <= max_codeword_len);
/* Compute the path lengths for the leaf nodes. */
- huffman_tree_compute_path_lengths(root, 0);
+ huffman_tree_compute_path_lengths(&root->node_base, 0);
/* Sort the leaf nodes primarily by code length and secondarily by
* symbol. */
- qsort(leaves, num_used_symbols, sizeof(leaves[0]), cmp_leaves_by_code_len);
+ qsort(leaves, num_used_symbols, sizeof(leaves[0]), cmp_nodes_by_code_len);
u16 cur_codeword = 0;
unsigned cur_codeword_len = 0;
* pointers by the fact that values less than @num_syms must be symbol values.
*/
int
-make_huffman_decode_table(u16 decode_table[], unsigned num_syms,
- unsigned table_bits, const u8 lens[],
+make_huffman_decode_table(u16 * restrict decode_table, unsigned num_syms,
+ unsigned table_bits, const u8 * restrict lens,
unsigned max_codeword_len)
{
unsigned len_counts[max_codeword_len + 1];
break;
unsigned num_entries = 1 << (table_bits - codeword_len);
- const unsigned entries_per_long = sizeof(unsigned long) /
- sizeof(decode_table[0]);
- if (num_entries >= entries_per_long) {
- /* Fill in the Huffman decode table entries one unsigned
- * long at a time. On 32-bit systems this is 2 entries
- * per store, while on 64-bit systems this is 4 entries
- * per store. */
- wimlib_assert2(decode_table_pos % entries_per_long == 0);
- BUILD_BUG_ON(sizeof(unsigned long) != 4 &&
- sizeof(unsigned long) != 8);
-
- unsigned long *p = (unsigned long *)&decode_table[decode_table_pos];
- unsigned n = num_entries / entries_per_long;
- unsigned long v = sym;
- if (sizeof(unsigned long) >= 4)
- v |= v << 16;
- if (sizeof(unsigned long) >= 8) {
- /* This may produce a compiler warning if an
- * unsigned long is 32 bits, but this won't be
- * executed unless an unsigned long is at least
- * 64 bits anyway. */
- v |= v << 32;
- }
- do {
- *p++ = v;
- } while (--n);
- decode_table_pos += num_entries;
- } else {
- /* Fill in the Huffman decode table entries one 16-bit
- * integer at a time. */
- do {
- decode_table[decode_table_pos++] = sym;
- } while (--num_entries);
- }
+ /* Fill in the Huffman decode table entries one 16-bit
+ * integer at a time. */
+ do {
+ decode_table[decode_table_pos++] = sym;
+ } while (--num_entries);
+
wimlib_assert2(decode_table_pos <= table_num_entries);
if (++i == num_used_syms) {
wimlib_assert2(decode_table_pos == table_num_entries);
* a file name and short name that take the specified numbers of bytes. This
* excludes any alternate data stream entries that may follow the dentry. */
static u64
-__dentry_correct_length_unaligned(u16 file_name_nbytes, u16 short_name_nbytes)
+_dentry_correct_length_unaligned(u16 file_name_nbytes, u16 short_name_nbytes)
{
u64 length = WIM_DENTRY_DISK_SIZE;
if (file_name_nbytes)
static u64
dentry_correct_length_unaligned(const struct wim_dentry *dentry)
{
- return __dentry_correct_length_unaligned(dentry->file_name_nbytes,
+ return _dentry_correct_length_unaligned(dentry->file_name_nbytes,
dentry->short_name_nbytes);
}
static u64
-__dentry_total_length(const struct wim_dentry *dentry, u64 length)
+_dentry_total_length(const struct wim_dentry *dentry, u64 length)
{
const struct wim_inode *inode = dentry->d_inode;
for (u16 i = 0; i < inode->i_num_ads; i++)
u64
dentry_correct_total_length(const struct wim_dentry *dentry)
{
- return __dentry_total_length(dentry,
+ return _dentry_total_length(dentry,
dentry_correct_length_unaligned(dentry));
}
static u64
dentry_total_length(const struct wim_dentry *dentry)
{
- return __dentry_total_length(dentry, dentry->length);
+ return _dentry_total_length(dentry, dentry->length);
}
int
static int
-__new_dentry_with_inode(const tchar *name, struct wim_dentry **dentry_ret,
+_new_dentry_with_inode(const tchar *name, struct wim_dentry **dentry_ret,
bool timeless)
{
struct wim_dentry *dentry;
int
new_dentry_with_timeless_inode(const tchar *name, struct wim_dentry **dentry_ret)
{
- return __new_dentry_with_inode(name, dentry_ret, true);
+ return _new_dentry_with_inode(name, dentry_ret, true);
}
int
new_dentry_with_inode(const tchar *name, struct wim_dentry **dentry_ret)
{
- return __new_dentry_with_inode(name, dentry_ret, false);
+ return _new_dentry_with_inode(name, dentry_ret, false);
}
int
/* This function is passed as an argument to for_dentry_in_tree_depth() in order
* to free a directory tree. */
static int
-do_free_dentry(struct wim_dentry *dentry, void *__lookup_table)
+do_free_dentry(struct wim_dentry *dentry, void *_lookup_table)
{
- struct wim_lookup_table *lookup_table = __lookup_table;
+ struct wim_lookup_table *lookup_table = _lookup_table;
unsigned i;
if (lookup_table) {
* The calculated length here is unaligned to allow for the possibility
* that the dentry->length names an unaligned length, although this
* would be unexpected. */
- calculated_size = __dentry_correct_length_unaligned(file_name_nbytes,
+ calculated_size = _dentry_correct_length_unaligned(file_name_nbytes,
short_name_nbytes);
if (dentry->length < calculated_size) {
}
p = put_zeroes(p, (8 - (p - orig_p) % 8) % 8);
}
- wimlib_assert(p - orig_p == __dentry_total_length(dentry, length));
+ wimlib_assert(p - orig_p == _dentry_total_length(dentry, length));
return p;
}
# include <unistd.h> /* for unlink() */
#endif
-/* Size of each lookup table entry in the WIM file. */
-#define WIM_LOOKUP_TABLE_ENTRY_DISK_SIZE 50
-
struct wim_lookup_table *
new_lookup_table(size_t capacity)
{
return ret;
}
+
+/* Size of each lookup table entry in the WIM file. */
+#define WIM_LOOKUP_TABLE_ENTRY_DISK_SIZE 50
+
/*
* Reads the lookup table from a WIM file.
*
}
static u32
-lzx_record_literal(u8 literal, void *__main_freq_tab)
+lzx_record_literal(u8 literal, void *_main_freq_tab)
{
- freq_t *main_freq_tab = __main_freq_tab;
+ freq_t *main_freq_tab = _main_freq_tab;
main_freq_tab[literal]++;
return literal;
}
* intermediate representation documented below. */
static u32
lzx_record_match(unsigned match_offset, unsigned match_len,
- void *__freq_tabs, void *__queue)
+ void *_freq_tabs, void *_queue)
{
- struct lzx_freq_tables *freq_tabs = __freq_tabs;
- struct lru_queue *queue = __queue;
+ struct lzx_freq_tables *freq_tabs = _freq_tabs;
+ struct lru_queue *queue = _queue;
unsigned position_slot;
unsigned position_footer = 0;
u32 match;
/* Documented in wimlib.h */
WIMLIBAPI unsigned
-wimlib_lzx_compress(const void *__uncompressed_data, unsigned uncompressed_len,
+wimlib_lzx_compress(const void *_uncompressed_data, unsigned uncompressed_len,
void *compressed_data)
{
struct output_bitstream ostream;
/* The input data must be preprocessed. To avoid changing the original
* input, copy it to a temporary buffer. */
- memcpy(uncompressed_data, __uncompressed_data, uncompressed_len);
+ memcpy(uncompressed_data, _uncompressed_data, uncompressed_len);
memset(uncompressed_data + uncompressed_len, 0, 8);
/* Before doing any actual compression, do the call instruction (0xe8
}
for (i = 0; i < uncompressed_len; i++) {
- if (buf[i] != *((u8*)__uncompressed_data + i)) {
+ if (buf[i] != *((u8*)_uncompressed_data + i)) {
ERROR("lzx_compress(): Data we compressed didn't "
"decompress to the original data (difference at "
"byte %u of %u)", i + 1, uncompressed_len);
u32 cur_version;
u32 msg_type;
u32 msg_size;
-} PACKED;
+} _packed_attribute;
struct msg_unmount_request {
struct unmount_msg_hdr hdr;
u32 unmount_flags;
u8 want_progress_messages;
-} PACKED;
+} _packed_attribute;
struct msg_daemon_info {
struct unmount_msg_hdr hdr;
pid_t daemon_pid;
u32 mount_flags;
-} PACKED;
+} _packed_attribute;
struct msg_unmount_finished {
struct unmount_msg_hdr hdr;
s32 status;
-} PACKED;
+} _packed_attribute;
struct msg_write_streams_progress {
struct unmount_msg_hdr hdr;
union wimlib_progress_info info;
-} PACKED;
+} _packed_attribute;
enum {
MSG_TYPE_UNMOUNT_REQUEST,
#include "wimlib/util.h"
/* At the start of each type of access control entry. */
-typedef struct {
+typedef struct _ACE_HEADER {
/* enum ace_type, specifies what type of ACE this is. */
u8 type;
u8 flags;
/* Size of the access control entry. */
- u8 size;
-} ACEHeader;
+ u16 size;
+} _packed_attribute ACE_HEADER;
/* Grants rights to a user or group */
-typedef struct {
- ACEHeader hdr;
+typedef struct _ACCESS_ALLOWED_ACE {
+ ACE_HEADER hdr;
u32 mask;
u32 sid_start;
-} AccessAllowedACE;
+} _packed_attribute ACCESS_ALLOWED_ACE;
/* Denies rights to a user or group */
-typedef struct {
- ACEHeader hdr;
+typedef struct _ACCESS_DENIED_ACE {
+ ACE_HEADER hdr;
u32 mask;
u32 sid_start;
-} AccessDeniedACE;
+} _packed_attribute ACCESS_DENIED_ACE;
-typedef struct {
- ACEHeader hdr;
+typedef struct _SYSTEM_AUDIT_ACE {
+ ACE_HEADER hdr;
u32 mask;
u32 sid_start;
-} SystemAuditACE;
+} _packed_attribute SYSTEM_AUDIT_ACE;
/* Header of an access control list. */
-typedef struct {
+typedef struct _ACL {
/* ACL_REVISION or ACL_REVISION_DS */
u8 revision;
/* padding */
u16 sbz2;
-} ACL;
+} _packed_attribute ACL;
/* A structure used to identify users or groups. */
-typedef struct {
+typedef struct _SID {
/* example: 0x1 */
u8 revision;
u8 identifier_authority[6];
u32 sub_authority[0];
-} SID;
+} _packed_attribute SID;
-typedef struct {
+typedef struct _SECURITY_DESCRIPTOR_RELATIVE {
/* Example: 0x1 */
u8 revision;
/* Example: 0x0 */
/* Discretionary ACL. */
/* Example: 0x34 */
u32 dacl_offset;
-} SecurityDescriptor;
+} _packed_attribute SECURITY_DESCRIPTOR_RELATIVE;
/*
* This is a hack to work around a problem in libntfs-3g. libntfs-3g validates
/* No-op if no NTFS-3g support, or if NTFS-3g is version 2013 or later
* */
#if defined(WITH_NTFS_3G) && !defined(HAVE_NTFS_MNT_RDONLY)
- if (*size_p >= sizeof(SecurityDescriptor)) {
- SecurityDescriptor *sd = (SecurityDescriptor*)descr;
+ if (*size_p >= sizeof(SECURITY_DESCRIPTOR_RELATIVE)) {
+ SECURITY_DESCRIPTOR_RELATIVE *sd = (SECURITY_DESCRIPTOR_RELATIVE*)descr;
u32 sacl_offset = le32_to_cpu(sd->sacl_offset);
if (sacl_offset == *size_p - sizeof(ACL)) {
sd->sacl_offset = cpu_to_le32(0);
* Writes security data to an in-memory buffer.
*/
u8 *
-write_security_data(const struct wim_security_data *sd, u8 *p)
+write_security_data(const struct wim_security_data * restrict sd,
+ u8 * restrict p)
{
DEBUG("Writing security data (total_length = %"PRIu32", num_entries "
"= %"PRIu32")", sd->total_length, sd->num_entries);
p += sizeof(ACL);
for (u16 i = 0; i < ace_count; i++) {
- const ACEHeader *hdr = p;
+ const ACE_HEADER *hdr = p;
tprintf(T(" [ACE]\n"));
tprintf(T(" ACE type = %d\n"), hdr->type);
tprintf(T(" ACE flags = 0x%x\n"), hdr->flags);
tprintf(T(" ACE size = %u\n"), hdr->size);
- const AccessAllowedACE *aaa = (const AccessAllowedACE*)hdr;
+ const ACCESS_ALLOWED_ACE *aaa = (const ACCESS_ALLOWED_ACE*)p;
tprintf(T(" ACE mask = %x\n"), le32_to_cpu(aaa->mask));
tprintf(T(" SID start = %u\n"), le32_to_cpu(aaa->sid_start));
p += hdr->size;
static void
print_security_descriptor(const void *p, u64 size)
{
- const SecurityDescriptor *sd = p;
+ const SECURITY_DESCRIPTOR_RELATIVE *sd = p;
u8 revision = sd->revision;
u16 control = le16_to_cpu(sd->security_descriptor_control);
void
print_security_data(const struct wim_security_data *sd)
{
- wimlib_assert(sd != NULL);
-
tputs(T("[SECURITY DATA]"));
tprintf(T("Length = %"PRIu32" bytes\n"), sd->total_length);
tprintf(T("Number of Entries = %"PRIu32"\n"), sd->num_entries);
for (u32 i = 0; i < sd->num_entries; i++) {
- tprintf(T("[SecurityDescriptor %"PRIu32", length = %"PRIu64"]\n"),
+ tprintf(T("[SECURITY_DESCRIPTOR_RELATIVE %"PRIu32", length = %"PRIu64"]\n"),
i, sd->sizes[i]);
print_security_descriptor(sd->descriptors[i], sd->sizes[i]);
tputchar(T('\n'));
* return -1.
*/
int
-sd_set_add_sd(struct wim_sd_set *sd_set, const char descriptor[], size_t size)
+sd_set_add_sd(struct wim_sd_set *sd_set, const char *descriptor, size_t size)
{
u8 hash[SHA1_HASH_SIZE];
int security_id;
struct sd_node *new;
u8 **descriptors;
u64 *sizes;
- u8 *descr_copy;
+ char *descr_copy;
struct wim_security_data *sd;
bool bret;
- sha1_buffer((const u8*)descriptor, size, hash);
+ sha1_buffer(descriptor, size, hash);
security_id = lookup_sd(sd_set, hash);
if (security_id >= 0) /* Identical descriptor already exists */
}
static int
-copy_resource_to_swm(struct wim_lookup_table_entry *lte, void *__args)
+copy_resource_to_swm(struct wim_lookup_table_entry *lte, void *_args)
{
- struct split_args *args = (struct split_args*)__args;
+ struct split_args *args = (struct split_args*)_args;
WIMStruct *w = args->w;
int ret;
#ifdef ENABLE_CUSTOM_MEMORY_ALLOCATOR
-void *(*wimlib_malloc_func) (size_t) = malloc;
-void (*wimlib_free_func) (void *) = free;
-void *(*wimlib_realloc_func)(void *, size_t) = realloc;
+static void *(*wimlib_malloc_func) (size_t) = malloc;
+static void (*wimlib_free_func) (void *) = free;
+static void *(*wimlib_realloc_func)(void *, size_t) = realloc;
+
+void *
+wimlib_malloc(size_t size)
+{
+ return (*wimlib_malloc_func)(size);
+}
+
+void
+wimlib_free_memory(void *ptr)
+{
+ (*wimlib_free_func)(ptr);
+}
+
+void *
+wimlib_realloc(void *ptr, size_t size)
+{
+ return (*wimlib_realloc_func)(ptr, size);
+}
void *
wimlib_calloc(size_t nmemb, size_t size)
{
size_t total_size = nmemb * size;
- void *p = MALLOC(total_size);
+ void *p = (*wimlib_malloc_func)(total_size);
if (p)
- memset(p, 0, total_size);
+ p = memset(p, 0, total_size);
return p;
}
char *p;
size = strlen(str);
- p = MALLOC(size + 1);
+ p = (*wimlib_malloc_func)(size + 1);
if (p)
memcpy(p, str, size + 1);
return p;
wchar_t *p;
size = wcslen(str);
- p = MALLOC((size + 1) * sizeof(wchar_t));
+ p = (*wimlib_malloc_func)((size + 1) * sizeof(wchar_t));
if (p)
- memcpy(p, str, (size + 1) * sizeof(wchar_t));
+ p = wmemcpy(p, str, size + 1);
return p;
}
#endif
u64 table_disk_size;
u64 cur_offset;
u64 *cur_offset_p;
- u64 offsets[0];
+ union {
+ u64 offsets[0];
+ u32 u32_offsets[0];
+ };
};
/*
array_cpu_to_le64(chunk_tab->offsets, chunk_tab->num_chunks);
} else {
for (u64 i = 0; i < chunk_tab->num_chunks; i++)
- ((u32*)chunk_tab->offsets)[i] =
- cpu_to_le32(chunk_tab->offsets[i]);
+ chunk_tab->u32_offsets[i] = cpu_to_le32(chunk_tab->offsets[i]);
}
bytes_written = full_pwrite(out_fd,
(u8*)chunk_tab->offsets + chunk_tab->bytes_per_chunk_entry,
* @codewords and @lens provide the Huffman code that is being used.
*/
static int
-xpress_write_match(struct output_bitstream *ostream, u32 match,
- const u16 codewords[], const u8 lens[])
+xpress_write_match(struct output_bitstream *restrict ostream,
+ u32 match,
+ const u16 codewords[restrict],
+ const u8 lens[restrict])
{
u32 adjusted_match_len = match & 0xffff;
u32 match_offset = match >> 16;
int ret;
ret = bitstream_put_bits(ostream, codewords[sym], lens[sym]);
- if (ret != 0)
+ if (ret)
return ret;
if (adjusted_match_len >= 0xf) {
u8 byte1 = min(adjusted_match_len - 0xf, 0xff);
ret = bitstream_put_byte(ostream, byte1);
- if (ret != 0)
+ if (ret)
return ret;
if (byte1 == 0xff) {
ret = bitstream_put_two_bytes(ostream, adjusted_match_len);
- if (ret != 0)
+ if (ret)
return ret;
}
}
static int
xpress_write_compressed_literals(struct output_bitstream *ostream,
- const u32 match_tab[],
+ const u32 match_tab[restrict],
unsigned num_matches,
- const u16 codewords[],
- const u8 lens[])
+ const u16 codewords[restrict],
+ const u8 lens[restrict])
{
for (unsigned i = 0; i < num_matches; i++) {
int ret;
else /* literal byte */
ret = bitstream_put_bits(ostream, codewords[match],
lens[match]);
- if (ret != 0)
+ if (ret)
return ret;
}
return bitstream_put_bits(ostream, codewords[XPRESS_END_OF_DATA],
}
static u32
-xpress_record_literal(u8 literal, void *__freq_tab)
+xpress_record_literal(u8 literal, void *_freq_tab)
{
- freq_t *freq_tab = __freq_tab;
+ freq_t *freq_tab = _freq_tab;
freq_tab[literal]++;
return literal;
}
static u32
xpress_record_match(unsigned match_offset, unsigned match_len,
- void *freq_tab, void *ignore)
+ void *freq_tab, void *_ignore)
{
wimlib_assert(match_len >= XPRESS_MIN_MATCH &&
match_len <= XPRESS_MAX_MATCH);
/* Documented in wimlib.h */
WIMLIBAPI unsigned
-wimlib_xpress_compress(const void *__uncompressed_data,
- unsigned uncompressed_len, void *__compressed_data)
+wimlib_xpress_compress(const void * restrict _uncompressed_data,
+ unsigned uncompressed_len,
+ void * restrict _compressed_data)
{
- u8 *compressed_data = __compressed_data;
+ u8 *compressed_data = _compressed_data;
struct output_bitstream ostream;
u32 match_tab[uncompressed_len];
freq_t freq_tab[XPRESS_NUM_SYMBOLS];
int ret;
u8 uncompressed_data[uncompressed_len + 8];
- memcpy(uncompressed_data, __uncompressed_data, uncompressed_len);
+ memcpy(uncompressed_data, _uncompressed_data, uncompressed_len);
memset(uncompressed_data + uncompressed_len, 0, 8);
wimlib_assert(uncompressed_len <= 32768);
* the compressed data, in which case they are actually unnecessary, or
* they may precede a number of bytes embedded into the bitstream.) */
if (ostream.bit_output >
- (const u8*)__compressed_data + uncompressed_len - 3)
+ (const u8*)_compressed_data + uncompressed_len - 3)
return 0;
*(u16*)ostream.bit_output = cpu_to_le16(0);
- compressed_len = ostream.next_bit_output - (const u8*)__compressed_data;
+ compressed_len = ostream.next_bit_output - (const u8*)_compressed_data;
wimlib_assert(compressed_len <= uncompressed_len - 1);
/* Verify that we really get the same thing back when decompressing. */
{
u8 buf[uncompressed_len];
- ret = wimlib_xpress_decompress(__compressed_data, compressed_len,
+ ret = wimlib_xpress_decompress(_compressed_data, compressed_len,
buf, uncompressed_len);
if (ret) {
ERROR("xpress_compress(): Failed to decompress data we "
*/
static int
xpress_decode_match(unsigned huffsym, unsigned window_pos,
- unsigned window_len, u8 window[],
- struct input_bitstream *istream)
+ unsigned window_len, u8 window[restrict],
+ struct input_bitstream * restrict istream)
{
unsigned match_len;
unsigned match_offset;
unsigned i;
ret = bitstream_read_bits(istream, offset_bsr, &match_offset);
- if (ret != 0)
+ if (ret)
return ret;
match_offset |= (1 << offset_bsr);
/* Decodes the Huffman-encoded matches and literal bytes in a block of
* XPRESS-encoded data. */
static int
-xpress_decompress_block(struct input_bitstream *istream,
- u8 uncompressed_data[],
+xpress_decompress_block(struct input_bitstream * restrict istream,
+ u8 uncompressed_data[restrict],
unsigned uncompressed_len,
- const u8 lens[],
- const u16 decode_table[])
+ const u8 lens[restrict],
+ const u16 decode_table[restrict])
{
unsigned curpos;
unsigned huffsym;
/* Documented in wimlib.h */
WIMLIBAPI int
-wimlib_xpress_decompress(const void *__compressed_data, unsigned compressed_len,
- void *uncompressed_data, unsigned uncompressed_len)
+wimlib_xpress_decompress(const void * restrict _compressed_data, unsigned compressed_len,
+ void * restrict uncompressed_data, unsigned uncompressed_len)
{
u8 lens[XPRESS_NUM_SYMBOLS];
u16 decode_table[(1 << XPRESS_TABLEBITS) + 2 * XPRESS_NUM_SYMBOLS];
unsigned i;
int ret;
- compressed_data = __compressed_data;
+ compressed_data = _compressed_data;
lens_p = lens;
DEBUG2("compressed_len = %d, uncompressed_len = %d",