1
2
3
4
5
6
7 #ifndef _TRACE_SEQ_H
8 #define _TRACE_SEQ_H
9
10 #include <stdarg.h>
11 #include <stdio.h>
12
13
14
15 #ifndef TRACE_SEQ_BUF_SIZE
16 #define TRACE_SEQ_BUF_SIZE 4096
17 #endif
18
19 enum trace_seq_fail {
20 TRACE_SEQ__GOOD,
21 TRACE_SEQ__BUFFER_POISONED,
22 TRACE_SEQ__MEM_ALLOC_FAILED,
23 };
24
25
26
27
28
29
30 struct trace_seq {
31 char *buffer;
32 unsigned int buffer_size;
33 unsigned int len;
34 unsigned int readpos;
35 enum trace_seq_fail state;
36 };
37
38 void trace_seq_init(struct trace_seq *s);
39 void trace_seq_reset(struct trace_seq *s);
40 void trace_seq_destroy(struct trace_seq *s);
41
42 extern int trace_seq_printf(struct trace_seq *s, const char *fmt, ...)
43 __attribute__ ((format (printf, 2, 3)));
44 extern int trace_seq_vprintf(struct trace_seq *s, const char *fmt, va_list args)
45 __attribute__ ((format (printf, 2, 0)));
46
47 extern int trace_seq_puts(struct trace_seq *s, const char *str);
48 extern int trace_seq_putc(struct trace_seq *s, unsigned char c);
49
50 extern void trace_seq_terminate(struct trace_seq *s);
51
52 extern int trace_seq_do_fprintf(struct trace_seq *s, FILE *fp);
53 extern int trace_seq_do_printf(struct trace_seq *s);
54
55 #endif