Do not read past the end of fmt_desc[]
[fio.git] / lib / pattern.h
CommitLineData
634bd210
RP
1#ifndef FIO_PARSE_PATTERN_H
2#define FIO_PARSE_PATTERN_H
3
634bd210
RP
4/**
5 * Pattern format description. The input for 'parse_pattern'.
6 * Describes format with its name and callback, which should
7 * be called to paste something inside the buffer.
8 */
9struct pattern_fmt_desc {
10 const char *fmt;
11 unsigned int len;
12 int (*paste)(char *buf, unsigned int len, void *priv);
13};
14
15/**
16 * Pattern format. The output of 'parse_pattern'.
17 * Describes the exact position inside the xbuffer.
18 */
19struct pattern_fmt {
20 unsigned int off;
21 const struct pattern_fmt_desc *desc;
22};
23
24int parse_and_fill_pattern(const char *in, unsigned int in_len,
25 char *out, unsigned int out_len,
26 const struct pattern_fmt_desc *fmt_desc,
634bd210
RP
27 struct pattern_fmt *fmt,
28 unsigned int *fmt_sz_out);
29
30int paste_format_inplace(char *pattern, unsigned int pattern_len,
31 struct pattern_fmt *fmt, unsigned int fmt_sz,
32 void *priv);
33
34int paste_format(const char *pattern, unsigned int pattern_len,
35 struct pattern_fmt *fmt, unsigned int fmt_sz,
36 char *out, unsigned int out_len, void *priv);
37
38int cpy_pattern(const char *pattern, unsigned int pattern_len,
39 char *out, unsigned int out_len);
40
41int cmp_pattern(const char *pattern, unsigned int pattern_size,
42 unsigned int off, const char *buf, unsigned int len);
43
44#endif