xref: /openbsd-src/sbin/savecore/compress.h (revision 96dc1bb701f13423f421b3b08325731b53c5e373)
1*96dc1bb7Stedu /*	$OpenBSD: compress.h,v 1.1 2016/09/03 13:05:08 tedu Exp $	*/
2*96dc1bb7Stedu 
3*96dc1bb7Stedu /*
4*96dc1bb7Stedu  * Copyright (c) 1997 Michael Shalayeff
5*96dc1bb7Stedu  * All rights reserved.
6*96dc1bb7Stedu  *
7*96dc1bb7Stedu  * Redistribution and use in source and binary forms, with or without
8*96dc1bb7Stedu  * modification, are permitted provided that the following conditions
9*96dc1bb7Stedu  * are met:
10*96dc1bb7Stedu  * 1. Redistributions of source code must retain the above copyright
11*96dc1bb7Stedu  *    notice, this list of conditions and the following disclaimer.
12*96dc1bb7Stedu  * 2. Redistributions in binary form must reproduce the above copyright
13*96dc1bb7Stedu  *    notice, this list of conditions and the following disclaimer in the
14*96dc1bb7Stedu  *    documentation and/or other materials provided with the distribution.
15*96dc1bb7Stedu  *
16*96dc1bb7Stedu  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17*96dc1bb7Stedu  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18*96dc1bb7Stedu  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19*96dc1bb7Stedu  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20*96dc1bb7Stedu  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21*96dc1bb7Stedu  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22*96dc1bb7Stedu  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23*96dc1bb7Stedu  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24*96dc1bb7Stedu  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25*96dc1bb7Stedu  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26*96dc1bb7Stedu  * SUCH DAMAGE.
27*96dc1bb7Stedu  *
28*96dc1bb7Stedu  */
29*96dc1bb7Stedu 
30*96dc1bb7Stedu #include <sys/stat.h>
31*96dc1bb7Stedu 
32*96dc1bb7Stedu struct z_info {
33*96dc1bb7Stedu 	u_int32_t mtime;	/* timestamp */
34*96dc1bb7Stedu 	u_int32_t crc;		/* crc */
35*96dc1bb7Stedu 	u_int32_t hlen;		/* header length */
36*96dc1bb7Stedu 	u_int64_t total_in;	/* # bytes in */
37*96dc1bb7Stedu 	u_int64_t total_out;	/* # bytes out */
38*96dc1bb7Stedu };
39*96dc1bb7Stedu 
40*96dc1bb7Stedu /*
41*96dc1bb7Stedu  * making it any bigger does not affect perfomance very much.
42*96dc1bb7Stedu  * actually this value is just a little bit better than 8192.
43*96dc1bb7Stedu  */
44*96dc1bb7Stedu #define Z_BUFSIZE 16384
45*96dc1bb7Stedu 
46*96dc1bb7Stedu enum program_mode {
47*96dc1bb7Stedu 	MODE_COMP,
48*96dc1bb7Stedu 	MODE_DECOMP,
49*96dc1bb7Stedu 	MODE_CAT
50*96dc1bb7Stedu } pmode;
51*96dc1bb7Stedu 
52*96dc1bb7Stedu /*
53*96dc1bb7Stedu  * exit codes for compress
54*96dc1bb7Stedu  */
55*96dc1bb7Stedu #define	SUCCESS	0
56*96dc1bb7Stedu #define	FAILURE	1
57*96dc1bb7Stedu #define	WARNING	2
58*96dc1bb7Stedu 
59*96dc1bb7Stedu extern char null_magic[];
60*96dc1bb7Stedu 
61*96dc1bb7Stedu extern void *z_open(int, const char *, char *, int, u_int32_t, int);
62*96dc1bb7Stedu extern FILE *zopen(const char *, const char *,int);
63*96dc1bb7Stedu extern int zread(void *, char *, int);
64*96dc1bb7Stedu extern int zwrite(void *, const char *, int);
65*96dc1bb7Stedu extern int z_close(void *, struct z_info *, const char *, struct stat *);
66*96dc1bb7Stedu 
67*96dc1bb7Stedu 
68*96dc1bb7Stedu extern void *gz_open(int, const char *, char *, int, u_int32_t, int);
69*96dc1bb7Stedu extern int gz_read(void *, char *, int);
70*96dc1bb7Stedu extern int gz_write(void *, const char *, int);
71*96dc1bb7Stedu extern int gz_close(void *, struct z_info *, const char *, struct stat *);
72*96dc1bb7Stedu extern int gz_flush(void *, int);
73*96dc1bb7Stedu 
74*96dc1bb7Stedu extern void *lzh_open(int, const char *, char *, int, u_int32_t, int);
75*96dc1bb7Stedu extern int lzh_read(void *, char *, int);
76*96dc1bb7Stedu extern int lzh_write(void *, const char *, int);
77*96dc1bb7Stedu extern int lzh_close(void *, struct z_info *);
78*96dc1bb7Stedu extern int lzh_flush(void *, int);
79*96dc1bb7Stedu 
80*96dc1bb7Stedu extern void *null_open(int, const char *, char *, int, u_int32_t, int);
81*96dc1bb7Stedu extern int null_read(void *, char *, int);
82*96dc1bb7Stedu extern int null_write(void *, const char *, int);
83*96dc1bb7Stedu extern int null_close(void *, struct z_info *, const char *, struct stat *);
84*96dc1bb7Stedu extern int null_flush(void *, int);
85*96dc1bb7Stedu 
86*96dc1bb7Stedu extern void setfile(const char *, int, struct stat *);
87