2 * Sherlock Library -- Miscellaneous Functions
4 * (c) 1997--2001 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 *);
48 #define L_DEBUG 'D' /* Debugging messages */
49 #define L_INFO 'I' /* Informational msgs, warnings and errors */
52 #define L_INFO_R 'i' /* Errors caused by external events */
55 #define L_FATAL '!' /* die() */
57 void log(unsigned int cat, byte *msg, ...);
58 void die(byte *, ...) NONRET;
59 void log_init(byte *);
60 void log_file(byte *);
63 #define ASSERT(x) do { if (!(x)) die("Assertion `%s' failed at %s:%d", #x, __FILE__, __LINE__); } while(0)
65 #define ASSERT(x) do { } while(0)
69 #define DBG(x,y...) log(L_DEBUG, x,##y)
71 #define DBG(x,y...) do { } while(0)
74 /* Memory allocation */
78 * The standard dmalloc macros tend to produce lots of namespace
79 * conflicts and we use only xmalloc and xfree, so we can define
80 * the stubs ourselves.
82 #define DMALLOC_DISABLE
84 #define xmalloc(size) _xmalloc_leap(__FILE__, __LINE__, size)
85 #define xrealloc(ptr,size) _xrealloc_leap(__FILE__, __LINE__, ptr, size)
86 #define xfree(ptr) _xfree_leap(__FILE__, __LINE__, ptr)
89 * Unfortunately, several libraries we might want to link to define
90 * their own xmalloc and we don't want to interfere with them, hence
93 #define xmalloc sh_xmalloc
94 void *xmalloc(unsigned);
95 void *xrealloc(void *, unsigned);
96 #define xfree(x) free(x)
99 byte *stralloc(byte *);
101 /* Content-Type pattern matching and filters */
103 int match_ct_patt(byte *, byte *);
111 int wordsplit(byte *, byte **, uns);
113 /* pat(i)match.c: Matching of shell patterns */
115 int match_pattern(byte *, byte *);
116 int match_pattern_nocase(byte *, byte *);
120 void md5_to_hex(byte *, byte *);
121 void hex_to_md5(byte *, byte *);
124 #define MD5_HEX_SIZE 33
133 void init_timer(void);
138 typedef struct regex regex;
140 regex *rx_compile(byte *r);
141 void rx_free(regex *r);
142 int rx_match(regex *r, byte *s);
143 int rx_subst(regex *r, byte *by, byte *src, byte *dest, uns destlen);
151 void *mmap_file(byte *name, unsigned *len);