forked from kubo/snzip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsnzip.h
158 lines (137 loc) · 4.94 KB
/
snzip.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/* -*- indent-tabs-mode: nil -*-
*
* Copyright 2011-2016 Kubo Takehiro <[email protected]>
*
* 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 AUTHORS ''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 <COPYRIGHT HOLDER> OR
* CONTRIBUTORS 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.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of the authors.
*
*/
#ifndef SNZIP_H
#define SNZIP_H 1
#include <stdio.h>
#include <stdint.h>
#ifndef __GNUC__
#define __attribute__(attr)
#endif
#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif
/* unlocked stdio functions */
#if defined _IO_getc_unlocked
#define getc_unlocked _IO_getc_unlocked
#elif !defined HAVE_GETC_UNLOCKED
#define getc_unlocked getc
#endif
#if defined _IO_putc_unlocked
#define putc_unlocked _IO_putc_unlocked
#elif !defined HAVE_PUTC_UNLOCKED
#define putc_unlocked putc
#endif
#if !defined HAVE_FREAD_UNLOCKED
#define fread_unlocked fread
#endif
#if !defined HAVE_FWRITE_UNLOCKED
#define fwrite_unlocked fwrite
#endif
#if defined _IO_ferror_unlocked
#define ferror_unlocked _IO_ferror_unlocked
#elif !defined HAVE_FERROR_UNLOCKED
#define ferror_unlocked ferror
#endif
#if defined _IO_feof_unlocked
#define feof_unlocked _IO_feof_unlocked
#elif !defined HAVE_FEOF_UNLOCKED
#define feof_unlocked feof
#endif
#ifdef HAVE_BYTESWAP_H
#include <byteswap.h>
#endif
#if defined bswap_32
#define SNZ_BSWAP32(x) bswap_32(x) /* in byteswap.h (linux) */
#elif defined _MSC_VER
#include <intrin.h>
#define SNZ_BSWAP32(x) _byteswap_ulong(x) /* in intrin.h (msvc) */
#else
#define SNZ_BSWAP32(x) \
((((x) >> 24) & 0x000000ffu) | \
(((x) >> 8) & 0x0000ff00u) | \
(((x) << 8) & 0x00ff0000u) | \
(((x) << 24) & 0xff000000u))
#endif
#ifdef WORDS_BIGENDIAN
#define SNZ_TO_LE32(x) SNZ_BSWAP32(x)
#define SNZ_FROM_LE32(x) SNZ_BSWAP32(x)
#define SNZ_TO_BE32(x) (x)
#define SNZ_FROM_BE32(x) (x)
#else
#define SNZ_TO_LE32(x) (x)
#define SNZ_FROM_LE32(x) (x)
#define SNZ_TO_BE32(x) SNZ_BSWAP32(x)
#define SNZ_FROM_BE32(x) SNZ_BSWAP32(x)
#endif
/* logging functions */
extern int trc_lineno;
extern const char *trc_filename;
void print_error_(const char *fmt, ...) __attribute__((format(printf, 1, 2)));
void trace_(const char *fmt, ...) __attribute__((format(printf, 1, 2)));
#define print_error (trc_filename = __FILE__, trc_lineno = __LINE__, print_error_)
#define trace (trc_filename = __FILE__, trc_lineno = __LINE__, trace_)
/* utility functions */
typedef struct {
size_t clen; /* maximum length of compressed data */
size_t uclen; /* maximum length of uncompressed data */
char *c; /* buffer for compressed data */
char *uc; /* buffer for uncompressed data */
} work_buffer_t;
int work_buffer_init(work_buffer_t *wb, size_t block_size);
void work_buffer_free(work_buffer_t *wb);
void work_buffer_resize(work_buffer_t *wb, size_t clen, size_t uclen);
int write_full(int fd, const void *buf, size_t count);
/* */
typedef struct {
const char *name;
const char *url;
const char *suffix;
int (*compress)(FILE *infp, FILE *outfp, size_t block_size);
int (*uncompress)(FILE *infp, FILE *outfp, int skip_magic);
} stream_format_t;
extern int64_t uncompressed_source_len;
extern int32_t snzip_format_block_size;
extern uint32_t hadoop_snappy_source_length;
extern uint32_t hadoop_snappy_compressed_length;
extern stream_format_t snzip_format;
extern stream_format_t framing_format;
extern stream_format_t framing2_format;
extern stream_format_t snappy_java_format;
extern stream_format_t snappy_in_java_format;
extern stream_format_t comment_43_format;
extern stream_format_t raw_format;
extern stream_format_t hadoop_snappy_format;
extern stream_format_t iwa_format;
/* hadoop-snapp-format.c */
size_t hadoop_snappy_max_input_size(size_t block_size);
#endif /* SNZIP_H */