Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

89 lines
4.3 KiB

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