annotate src/zlib-1.2.8/examples/gzlog.h @ 56:af97cad61ff0

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