2 * Sherlock Library -- Miscellaneous Functions
4 * (c) 1997--2000 Martin Mares <mj@ucw.cz>
8 * This file should be included as the very first include in all
9 * source files, especially before all OS includes since it sets
10 * up libc feature macros.
13 #ifndef _SHERLOCK_LIB_H
14 #define _SHERLOCK_LIB_H
16 #include "lib/config.h"
18 /* Tell libc we're going to use all extensions available */
23 #define NULL ((void *)0)
26 /* Ugly structure handling macros */
28 #define OFFSETOF(s, i) ((unsigned int)&((s *)0)->i)
29 #define SKIP_BACK(s, i, p) ((s *)((char *)p - OFFSETOF(s, i)))
30 #define ALIGN(s, a) (((s)+a-1)&~(a-1))
42 void open_temp(struct tempfile *, byte *);
43 void delete_temp(struct tempfile *);
47 #define TF_GENERIC "t"
48 #define TF_QUEUE_CONTROL "c"
49 #define TF_QUEUE_DATA "d"
51 #define TF_TRANSFORM "s"
56 /* FIXME: Define new logging mechanism? */
64 void log(byte *, ...);
65 void die(byte *, ...) NONRET;
67 void open_log_file(byte *);
70 #define ASSERT(x) do { if (!(x)) die("Assertion `%s' failed at %s:%d", #x, __FILE__, __LINE__); } while(0)
72 #define ASSERT(x) do { } while(0)
78 void *xrealloc(void *, uns);
79 byte *stralloc(byte *);
81 /* Content-Type pattern matching and filters */
83 int match_ct_patt(byte *, byte *);
91 int wordsplit(byte *, byte **, uns);
95 int match_pattern(byte *, byte *);
96 int match_pattern_nocase(byte *, byte *);
100 void md5_to_hex(byte *, byte *);
101 void hex_to_md5(byte *, byte *);
104 #define MD5_HEX_SIZE 33
113 void init_timer(void);
118 typedef struct regex regex;
120 regex *rx_compile(byte *r);
121 void rx_free(regex *r);
122 int rx_match(regex *r, byte *s);
123 int rx_subst(regex *r, byte *by, byte *src, byte *dest, uns destlen);
131 void *mmap_file(byte *name, unsigned *len);