trace-seq.h 1.4 KB

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