Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: LGPL-2.1
0002 /*
0003  * Copyright (C) 2009, 2010 Red Hat Inc, Steven Rostedt <srostedt@redhat.com>
0004  *
0005  */
0006 
0007 #ifndef _TRACE_SEQ_H
0008 #define _TRACE_SEQ_H
0009 
0010 #include <stdarg.h>
0011 #include <stdio.h>
0012 
0013 /* ----------------------- trace_seq ----------------------- */
0014 
0015 #ifndef TRACE_SEQ_BUF_SIZE
0016 #define TRACE_SEQ_BUF_SIZE 4096
0017 #endif
0018 
0019 enum trace_seq_fail {
0020     TRACE_SEQ__GOOD,
0021     TRACE_SEQ__BUFFER_POISONED,
0022     TRACE_SEQ__MEM_ALLOC_FAILED,
0023 };
0024 
0025 /*
0026  * Trace sequences are used to allow a function to call several other functions
0027  * to create a string of data to use (up to a max of PAGE_SIZE).
0028  */
0029 
0030 struct trace_seq {
0031     char            *buffer;
0032     unsigned int        buffer_size;
0033     unsigned int        len;
0034     unsigned int        readpos;
0035     enum trace_seq_fail state;
0036 };
0037 
0038 void trace_seq_init(struct trace_seq *s);
0039 void trace_seq_reset(struct trace_seq *s);
0040 void trace_seq_destroy(struct trace_seq *s);
0041 
0042 extern int trace_seq_printf(struct trace_seq *s, const char *fmt, ...)
0043     __attribute__ ((format (printf, 2, 3)));
0044 extern int trace_seq_vprintf(struct trace_seq *s, const char *fmt, va_list args)
0045     __attribute__ ((format (printf, 2, 0)));
0046 
0047 extern int trace_seq_puts(struct trace_seq *s, const char *str);
0048 extern int trace_seq_putc(struct trace_seq *s, unsigned char c);
0049 
0050 extern void trace_seq_terminate(struct trace_seq *s);
0051 
0052 extern int trace_seq_do_fprintf(struct trace_seq *s, FILE *fp);
0053 extern int trace_seq_do_printf(struct trace_seq *s);
0054 
0055 #endif /* _TRACE_SEQ_H */