annotate zlib/examples/gzlog.h @ 158:494b0b89df80 default tip

...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 25 May 2020 18:13:55 +0900
parents 04ced10e8804
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
51
ae3a4bfb450b add some files of version 4.4.3 that have been forgotten.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 /* gzlog.h
111
kono
parents: 51
diff changeset
2 Copyright (C) 2004, 2008, 2012 Mark Adler, all rights reserved
kono
parents: 51
diff changeset
3 version 2.2, 14 Aug 2012
51
ae3a4bfb450b add some files of version 4.4.3 that have been forgotten.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
4
ae3a4bfb450b add some files of version 4.4.3 that have been forgotten.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 This software is provided 'as-is', without any express or implied
ae3a4bfb450b add some files of version 4.4.3 that have been forgotten.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 warranty. In no event will the author be held liable for any damages
ae3a4bfb450b add some files of version 4.4.3 that have been forgotten.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 arising from the use of this software.
ae3a4bfb450b add some files of version 4.4.3 that have been forgotten.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
8
ae3a4bfb450b add some files of version 4.4.3 that have been forgotten.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 Permission is granted to anyone to use this software for any purpose,
ae3a4bfb450b add some files of version 4.4.3 that have been forgotten.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 including commercial applications, and to alter it and redistribute it
ae3a4bfb450b add some files of version 4.4.3 that have been forgotten.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 freely, subject to the following restrictions:
ae3a4bfb450b add some files of version 4.4.3 that have been forgotten.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
12
ae3a4bfb450b add some files of version 4.4.3 that have been forgotten.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 1. The origin of this software must not be misrepresented; you must not
ae3a4bfb450b add some files of version 4.4.3 that have been forgotten.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 claim that you wrote the original software. If you use this software
ae3a4bfb450b add some files of version 4.4.3 that have been forgotten.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 in a product, an acknowledgment in the product documentation would be
ae3a4bfb450b add some files of version 4.4.3 that have been forgotten.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 appreciated but is not required.
ae3a4bfb450b add some files of version 4.4.3 that have been forgotten.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 2. Altered source versions must be plainly marked as such, and must not be
ae3a4bfb450b add some files of version 4.4.3 that have been forgotten.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 misrepresented as being the original software.
ae3a4bfb450b add some files of version 4.4.3 that have been forgotten.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 3. This notice may not be removed or altered from any source distribution.
ae3a4bfb450b add some files of version 4.4.3 that have been forgotten.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
20
ae3a4bfb450b add some files of version 4.4.3 that have been forgotten.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 Mark Adler madler@alumni.caltech.edu
ae3a4bfb450b add some files of version 4.4.3 that have been forgotten.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 */
ae3a4bfb450b add some files of version 4.4.3 that have been forgotten.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
23
111
kono
parents: 51
diff changeset
24 /* Version History:
kono
parents: 51
diff changeset
25 1.0 26 Nov 2004 First version
kono
parents: 51
diff changeset
26 2.0 25 Apr 2008 Complete redesign for recovery of interrupted operations
kono
parents: 51
diff changeset
27 Interface changed slightly in that now path is a prefix
kono
parents: 51
diff changeset
28 Compression now occurs as needed during gzlog_write()
kono
parents: 51
diff changeset
29 gzlog_write() now always leaves the log file as valid gzip
kono
parents: 51
diff changeset
30 2.1 8 Jul 2012 Fix argument checks in gzlog_compress() and gzlog_write()
kono
parents: 51
diff changeset
31 2.2 14 Aug 2012 Clean up signed comparisons
kono
parents: 51
diff changeset
32 */
kono
parents: 51
diff changeset
33
51
ae3a4bfb450b add some files of version 4.4.3 that have been forgotten.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
34 /*
ae3a4bfb450b add some files of version 4.4.3 that have been forgotten.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
35 The gzlog object allows writing short messages to a gzipped log file,
ae3a4bfb450b add some files of version 4.4.3 that have been forgotten.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
36 opening the log file locked for small bursts, and then closing it. The log
111
kono
parents: 51
diff changeset
37 object works by appending stored (uncompressed) data to the gzip file until
kono
parents: 51
diff changeset
38 1 MB has been accumulated. At that time, the stored data is compressed, and
kono
parents: 51
diff changeset
39 replaces the uncompressed data in the file. The log file is truncated to
kono
parents: 51
diff changeset
40 its new size at that time. After each write operation, the log file is a
kono
parents: 51
diff changeset
41 valid gzip file that can decompressed to recover what was written.
51
ae3a4bfb450b add some files of version 4.4.3 that have been forgotten.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
42
111
kono
parents: 51
diff changeset
43 The gzlog operations can be interupted at any point due to an application or
kono
parents: 51
diff changeset
44 system crash, and the log file will be recovered the next time the log is
kono
parents: 51
diff changeset
45 opened with gzlog_open().
51
ae3a4bfb450b add some files of version 4.4.3 that have been forgotten.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
46 */
ae3a4bfb450b add some files of version 4.4.3 that have been forgotten.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
47
111
kono
parents: 51
diff changeset
48 #ifndef GZLOG_H
kono
parents: 51
diff changeset
49 #define GZLOG_H
kono
parents: 51
diff changeset
50
kono
parents: 51
diff changeset
51 /* gzlog object type */
kono
parents: 51
diff changeset
52 typedef void gzlog;
kono
parents: 51
diff changeset
53
51
ae3a4bfb450b add some files of version 4.4.3 that have been forgotten.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
54 /* Open a gzlog object, creating the log file if it does not exist. Return
111
kono
parents: 51
diff changeset
55 NULL on error. Note that gzlog_open() could take a while to complete if it
kono
parents: 51
diff changeset
56 has to wait to verify that a lock is stale (possibly for five minutes), or
kono
parents: 51
diff changeset
57 if there is significant contention with other instantiations of this object
kono
parents: 51
diff changeset
58 when locking the resource. path is the prefix of the file names created by
kono
parents: 51
diff changeset
59 this object. If path is "foo", then the log file will be "foo.gz", and
kono
parents: 51
diff changeset
60 other auxiliary files will be created and destroyed during the process:
kono
parents: 51
diff changeset
61 "foo.dict" for a compression dictionary, "foo.temp" for a temporary (next)
kono
parents: 51
diff changeset
62 dictionary, "foo.add" for data being added or compressed, "foo.lock" for the
kono
parents: 51
diff changeset
63 lock file, and "foo.repairs" to log recovery operations performed due to
kono
parents: 51
diff changeset
64 interrupted gzlog operations. A gzlog_open() followed by a gzlog_close()
kono
parents: 51
diff changeset
65 will recover a previously interrupted operation, if any. */
kono
parents: 51
diff changeset
66 gzlog *gzlog_open(char *path);
51
ae3a4bfb450b add some files of version 4.4.3 that have been forgotten.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
67
111
kono
parents: 51
diff changeset
68 /* Write to a gzlog object. Return zero on success, -1 if there is a file i/o
kono
parents: 51
diff changeset
69 error on any of the gzlog files (this should not happen if gzlog_open()
kono
parents: 51
diff changeset
70 succeeded, unless the device has run out of space or leftover auxiliary
kono
parents: 51
diff changeset
71 files have permissions or ownership that prevent their use), -2 if there is
kono
parents: 51
diff changeset
72 a memory allocation failure, or -3 if the log argument is invalid (e.g. if
kono
parents: 51
diff changeset
73 it was not created by gzlog_open()). This function will write data to the
kono
parents: 51
diff changeset
74 file uncompressed, until 1 MB has been accumulated, at which time that data
kono
parents: 51
diff changeset
75 will be compressed. The log file will be a valid gzip file upon successful
kono
parents: 51
diff changeset
76 return. */
kono
parents: 51
diff changeset
77 int gzlog_write(gzlog *log, void *data, size_t len);
51
ae3a4bfb450b add some files of version 4.4.3 that have been forgotten.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
78
111
kono
parents: 51
diff changeset
79 /* Force compression of any uncompressed data in the log. This should be used
kono
parents: 51
diff changeset
80 sparingly, if at all. The main application would be when a log file will
kono
parents: 51
diff changeset
81 not be appended to again. If this is used to compress frequently while
kono
parents: 51
diff changeset
82 appending, it will both significantly increase the execution time and
kono
parents: 51
diff changeset
83 reduce the compression ratio. The return codes are the same as for
kono
parents: 51
diff changeset
84 gzlog_write(). */
kono
parents: 51
diff changeset
85 int gzlog_compress(gzlog *log);
kono
parents: 51
diff changeset
86
kono
parents: 51
diff changeset
87 /* Close a gzlog object. Return zero on success, -3 if the log argument is
kono
parents: 51
diff changeset
88 invalid. The log object is freed, and so cannot be referenced again. */
kono
parents: 51
diff changeset
89 int gzlog_close(gzlog *log);
kono
parents: 51
diff changeset
90
kono
parents: 51
diff changeset
91 #endif