1 // SPDX-License-Identifier: LGPL-2.1 2 /* 3 * Copyright (C) 2009, 2010 Red Hat Inc, Steven Rostedt <srostedt@redhat.com> 4 * 5 */ 6 7 #ifndef _TRACE_SEQ_H 8 #define _TRACE_SEQ_H 9 10 #include <stdarg.h> 11 #include <stdio.h> 12 13 #ifdef __cplusplus 14 extern "C" { 15 #endif 16 17 /* ----------------------- trace_seq ----------------------- */ 18 19 #ifndef TRACE_SEQ_BUF_SIZE 20 #define TRACE_SEQ_BUF_SIZE 4096 21 #endif 22 23 enum trace_seq_fail { 24 TRACE_SEQ__GOOD, 25 TRACE_SEQ__BUFFER_POISONED, 26 TRACE_SEQ__MEM_ALLOC_FAILED, 27 }; 28 29 /* 30 * Trace sequences are used to allow a function to call several other functions 31 * to create a string of data to use (up to a max of PAGE_SIZE). 32 */ 33 34 struct trace_seq { 35 char *buffer; 36 unsigned int buffer_size; 37 unsigned int len; 38 unsigned int readpos; 39 enum trace_seq_fail state; 40 }; 41 42 void trace_seq_init(struct trace_seq *s); 43 void trace_seq_reset(struct trace_seq *s); 44 void trace_seq_destroy(struct trace_seq *s); 45 46 extern int trace_seq_printf(struct trace_seq *s, const char *fmt, ...) 47 __attribute__ ((format (printf, 2, 3))); 48 extern int trace_seq_vprintf(struct trace_seq *s, const char *fmt, va_list args) 49 __attribute__ ((format (printf, 2, 0))); 50 51 extern int trace_seq_puts(struct trace_seq *s, const char *str); 52 extern int trace_seq_putc(struct trace_seq *s, unsigned char c); 53 54 extern void trace_seq_terminate(struct trace_seq *s); 55 56 extern int trace_seq_do_fprintf(struct trace_seq *s, FILE *fp); 57 extern int trace_seq_do_printf(struct trace_seq *s); 58 59 #ifdef __cplusplus 60 } 61 #endif 62 63 #endif /* _TRACE_SEQ_H */ 64