Ruby: ext/zlib/zlib-1.2.13/examples/gzlog.c File Reference

Ruby 3.0.5p211 (2022-11-24 revision ba5cf0f7c52d4d35cc6a173c89eda98ceffa2dcf)

Data Structures | Macros | Typedefs | Functions | Variables
gzlog.c File Reference
`#include <sys/types.h>`
`#include <stdio.h>`
`#include <stdlib.h>`
`#include <string.h>`
`#include <fcntl.h>`
`#include <unistd.h>`
`#include <errno.h>`
`#include <time.h>`
`#include <sys/stat.h>`
`#include <sys/time.h>`
`#include "zlib.h"`
`#include "gzlog.h"`

Go to the source code of this file.

## Data Structures
struct | log

## Macros
#define | local static
#define | BAIL(n)
#define | PATIENCE 300
#define | MAX_STORE 16
#define | TRIGGER 1024
#define | DICT 32768U
#define | NO_OP 0
#define | APPEND_OP 1
#define | COMPRESS_OP 2
#define | REPLACE_OP 3
#define | PULL2(p) ((p)[0]+((uint)((p)[1])<<8))
#define | PULL4(p) (PULL2(p)+((ulong)PULL2(p+2)<<16))
#define | PULL8(p) (PULL4(p)+((off_t)PULL4(p+4)<<32))
#define | PUT2(p, a) do {(p)[0]=a;(p)[1]=(a)>>8;} while(0)
#define | PUT4(p, a) do {PUT2(p,a);PUT2(p+2,a>>16);} while(0)
#define | PUT8(p, a) do {PUT4(p,a);PUT4(p+4,a>>32);} while(0)
#define | LOGID "\106\035\172" /* should be three non-zero characters */
#define | HEAD sizeof(log_gzhead) /* should be 16 */
#define | EXTRA sizeof(log_gzext) /* should be 35 */
#define | BODY sizeof(log_gzbody)

## Typedefs
typedef unsigned int | uint
typedef unsigned long | ulong

## Functions
int | log_lock (struct log *log)
void | log_touch (struct log *log)
int | log_check (struct log *log)
void | log_unlock (struct log *log)
int | log_head (struct log *log)
int | log_mark (struct log *log, int op)
int | log_last (struct log *log, int last)
int | log_append (struct log *log, unsigned char *data, size_t len)
int | log_replace (struct log *log)
int | log_compress (struct log *log, unsigned char *data, size_t len)
void | log_log (struct log *log, int op, char *record)
int | log_recover (struct log *log, int op)
void | log_close (struct log *log)
int | log_open (struct log *log)
gzlog * | gzlog_open (char *path)
int | gzlog_compress (gzlog *logd)
int | gzlog_write (gzlog *logd, void *data, size_t len)
int | gzlog_close (gzlog *logd)

## Variables
unsigned char | log_gzhead []
unsigned char | log_gzext []
unsigned char | log_gzbody []

## Macro Definition Documentation

## ◆ APPEND_OP

#define APPEND_OP 1

Definition at line 273 of file gzlog.c.

## ◆ BAIL

#define BAIL | ( |  | n | ) |

Definition at line 254 of file gzlog.c.

## ◆ BODY

#define BODY sizeof(log_gzbody)

Definition at line 337 of file gzlog.c.

## ◆ COMPRESS_OP

#define COMPRESS_OP 2

Definition at line 274 of file gzlog.c.

## ◆ DICT

#define DICT 32768U

Definition at line 269 of file gzlog.c.

## ◆ EXTRA

#define EXTRA sizeof(log_gzext) /* should be 35 */

Definition at line 328 of file gzlog.c.

## ◆ HEAD

#define HEAD sizeof(log_gzhead) /* should be 16 */

Definition at line 316 of file gzlog.c.

## ◆ local

#define local static

Definition at line 241 of file gzlog.c.

## ◆ LOGID

#define LOGID "\106\035\172" /* should be three non-zero characters */

Definition at line 288 of file gzlog.c.

## ◆ MAX_STORE

#define MAX_STORE 16

Definition at line 261 of file gzlog.c.

## ◆ NO_OP

#define NO_OP 0

Definition at line 272 of file gzlog.c.

## ◆ PATIENCE

#define PATIENCE 300

Definition at line 258 of file gzlog.c.

## ◆ PULL2

#define PULL2 | ( |  | p | ) | ((p)[0]+((uint)((p)[1])<<8))

Definition at line 278 of file gzlog.c.

## ◆ PULL4

#define PULL4 | ( |  | p | ) | (PULL2(p)+((ulong)PULL2(p+2)<<16))

Definition at line 279 of file gzlog.c.

## ◆ PULL8

#define PULL8 | ( |  | p | ) | (PULL4(p)+((off_t)PULL4(p+4)<<32))

Definition at line 280 of file gzlog.c.

## ◆ PUT2

#define PUT2 | ( |  | p,
|  |  | a
| ) |  | do {(p)[0]=a;(p)[1]=(a)>>8;} while(0)

Definition at line 283 of file gzlog.c.

## ◆ PUT4

#define PUT4 | ( |  | p,
|  |  | a
| ) |  | do {PUT2(p,a);PUT2(p+2,a>>16);} while(0)

Definition at line 284 of file gzlog.c.

## ◆ PUT8

#define PUT8 | ( |  | p,
|  |  | a
| ) |  | do {PUT4(p,a);PUT4(p+4,a>>32);} while(0)

Definition at line 285 of file gzlog.c.

## ◆ REPLACE_OP

#define REPLACE_OP 3

Definition at line 275 of file gzlog.c.

## ◆ TRIGGER

#define TRIGGER 1024

Definition at line 266 of file gzlog.c.

## Typedef Documentation

## ◆ uint

typedef unsigned int uint

Definition at line 242 of file gzlog.c.

## ◆ ulong

typedef unsigned long ulong

Definition at line 243 of file gzlog.c.

## Function Documentation

## ◆ gzlog_close()

int gzlog_close | ( | gzlog * | logd | ) |

Definition at line 1044 of file gzlog.c.

References free, log::id, log_close(), LOGID, NULL, and log::path.

## ◆ gzlog_compress()

int gzlog_compress | ( | gzlog * | logd | ) |

Definition at line 910 of file gzlog.c.

References BAIL, COMPRESS_OP, DICT, log::end, log::fd, log::first, free, log::id, log::last, len, log_check(), log_compress(), log_mark(), log_open(), log_touch(), LOGID, malloc, NULL, log::path, PULL2, read(), SEEK_CUR, SEEK_SET, log::stored, and write().

Referenced by gzlog_write().

## ◆ gzlog_open()

gzlog * gzlog_open | ( | char * | path | ) |

Definition at line 867 of file gzlog.c.

References log::end, log::fd, free, log::id, log_open(), LOGID, malloc, NULL, log::path, and strlen().

## ◆ gzlog_write()

int gzlog_write | ( | gzlog * | logd,
|  | void * | data,
|  | size_t | len
| ) |  |

Definition at line 997 of file gzlog.c.

References APPEND_OP, BAIL, log::end, log::fd, log::first, gzlog_compress(), log::id, log::last, len, log_append(), log_check(), log_mark(), log_open(), log_touch(), LOGID, NULL, log::path, log::stored, TRIGGER, and write().

## ◆ log_append()

int log_append | ( | struct log * | log,
|  | unsigned char * | data,
|  | size_t | len
| ) |  |

Definition at line 501 of file gzlog.c.

References BAIL, crc32(), log::end, log::fd, ftruncate, if(), log::last, len, log_last(), log_mark(), MAX_STORE, NO_OP, off_t, log::path, PUT4, SEEK_CUR, log::stored, log::tcrc, log::tlen, and write().

Referenced by gzlog_write(), and log_recover().

## ◆ log_check()

int log_check | ( | struct log * | log | ) |

Definition at line 384 of file gzlog.c.

References log::end, log::lock, log_touch(), log::path, and stat.

Referenced by gzlog_compress(), gzlog_write(), and log_unlock().

## ◆ log_close()

void log_close | ( | struct log * | log | ) |

Definition at line 798 of file gzlog.c.

References log::fd, and log_unlock().

Referenced by gzlog_close(), and log_open().

## ◆ log_compress()

int log_compress | ( | struct log * | log,
|  | unsigned char * | data,
|  | size_t | len
| ) |  |

Definition at line 608 of file gzlog.c.

References z_stream_s::avail_in, z_stream_s::avail_out, log::back, BAIL, log::ccrc, log::clen, deflate(), deflateEnd(), deflateInit2, deflatePrime(), deflateSetDictionary(), DICT, log::end, log::fd, log::first, ftruncate, log::last, len, log_last(), log_mark(), log_replace(), log_touch(), max, z_stream_s::next_in, z_stream_s::next_out, off_t, z_stream_s::opaque, log::path, PUT4, read(), REPLACE_OP, SEEK_CUR, SEEK_SET, log::stored, log::tcrc, log::tlen, write(), Z_DEFAULT_COMPRESSION, Z_DEFAULT_STRATEGY, Z_DEFLATED, Z_NO_FLUSH, Z_NULL, Z_OK, Z_PARTIAL_FLUSH, z_stream_s::zalloc, and z_stream_s::zfree.

Referenced by gzlog_compress(), and log_recover().

## ◆ log_head()

int log_head | ( | struct log * | log | ) |

Definition at line 410 of file gzlog.c.

References log::back, log::ccrc, log::clen, EXTRA, log::fd, log::first, HEAD, log::last, log_gzhead, memcmp(), PULL2, PULL4, PULL8, read(), SEEK_SET, log::stored, log::tcrc, and log::tlen.

Referenced by log_open().

## ◆ log_last()

int log_last | ( | struct log * | log,
|  | int | last
| ) |  |

Definition at line 462 of file gzlog.c.

References log::back, log::fd, log::first, last, log::last, len, mask, PUT2, read(), SEEK_CUR, SEEK_SET, log::stored, and write().

Referenced by log_append(), and log_compress().

## ◆ log_lock()

int log_lock | ( | struct log * | log | ) |

Definition at line 348 of file gzlog.c.

References log::end, log::lock, NULL, log::path, PATIENCE, and stat.

Referenced by log_open().

## ◆ log_log()

void log_log | ( | struct log * | log,
|  | int | op,
|  | char * | record
| ) |  |

Definition at line 718 of file gzlog.c.

References APPEND_OP, COMPRESS_OP, log::end, NULL, and log::path.

Referenced by log_recover().

## ◆ log_mark()

int log_mark | ( | struct log * | log,
|  | int | op
| ) |  |

Definition at line 437 of file gzlog.c.

References log::back, log::ccrc, log::clen, EXTRA, log::fd, log::first, fsync, HEAD, log::last, PUT2, PUT4, PUT8, SEEK_SET, log::stored, log::tcrc, log::tlen, and write().

Referenced by gzlog_compress(), gzlog_write(), log_append(), log_compress(), and log_replace().

## ◆ log_open()

int log_open | ( | struct log * | log | ) |

Definition at line 815 of file gzlog.c.

References BODY, log::end, EXTRA, log::fd, HEAD, log_close(), log_gzbody, log_gzext, log_gzhead, log_head(), log_lock(), log_recover(), log_touch(), NO_OP, log::path, SEEK_END, and write().

Referenced by gzlog_compress(), gzlog_open(), and gzlog_write().

## ◆ log_recover()

int log_recover | ( | struct log * | log,
|  | int | op
| ) |  |

Definition at line 738 of file gzlog.c.

References APPEND_OP, COMPRESS_OP, log::end, free, len, log_append(), log_compress(), log_log(), log_replace(), malloc, NULL, off_t, log::path, read(), REPLACE_OP, and stat.

Referenced by log_open().

## ◆ log_replace()

int log_replace | ( | struct log * | log | ) |

Definition at line 571 of file gzlog.c.

References BAIL, log::end, free, log_mark(), malloc, NO_OP, NULL, log::path, and strlen().

Referenced by log_compress(), and log_recover().

## ◆ log_touch()

void log_touch | ( | struct log * | log | ) |

Definition at line 372 of file gzlog.c.

References log::end, log::lock, NULL, log::path, and stat.

Referenced by gzlog_compress(), gzlog_write(), log_check(), log_compress(), and log_open().

## ◆ log_unlock()

void log_unlock | ( | struct log * | log | ) |

Definition at line 396 of file gzlog.c.

References log::end, log::lock, log_check(), and log::path.

Referenced by log_close().

## Variable Documentation

## ◆ log_gzbody

unsigned char log_gzbody[]

Initial value:
= {
1, 0, 0, 0xff, 0xff,
0, 0, 0, 0,
0, 0, 0, 0
}

Definition at line 331 of file gzlog.c.

Referenced by log_open().

## ◆ log_gzext

unsigned char log_gzext[]

Initial value:
= {
52, 0, 0, 0, 0, 0, 0, 0,
52, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0,
5
}

Definition at line 319 of file gzlog.c.

Referenced by log_open().

## ◆ log_gzhead

unsigned char log_gzhead[]

Initial value:
= {
0x1f, 0x8b,
8,
4,
0, 0, 0, 0,
0, 0xff,
39, 0, 'a', 'p', 35, 0
}

Definition at line 306 of file gzlog.c.

Referenced by log_head(), and log_open().