annotate src/zlib-1.2.7/examples/gzlog.h @ 169:223a55898ab9 tip default

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