Lines Matching full:s
22 #define TRACE_SEQ_CHECK(s) \ argument
24 if (WARN_ONCE((s)->buffer == TRACE_SEQ_POISON, \
26 (s)->state = TRACE_SEQ__BUFFER_POISONED; \
29 #define TRACE_SEQ_CHECK_RET_N(s, n) \ argument
31 TRACE_SEQ_CHECK(s); \
32 if ((s)->state != TRACE_SEQ__GOOD) \
36 #define TRACE_SEQ_CHECK_RET(s) TRACE_SEQ_CHECK_RET_N(s, ) argument
37 #define TRACE_SEQ_CHECK_RET0(s) TRACE_SEQ_CHECK_RET_N(s, 0) argument
41 * @s: a pointer to the trace_seq structure to initialize
43 void trace_seq_init(struct trace_seq *s) in trace_seq_init() argument
45 s->len = 0; in trace_seq_init()
46 s->readpos = 0; in trace_seq_init()
47 s->buffer_size = TRACE_SEQ_BUF_SIZE; in trace_seq_init()
48 s->buffer = malloc(s->buffer_size); in trace_seq_init()
49 if (s->buffer != NULL) in trace_seq_init()
50 s->state = TRACE_SEQ__GOOD; in trace_seq_init()
52 s->state = TRACE_SEQ__MEM_ALLOC_FAILED; in trace_seq_init()
57 * @s: a pointer to the trace_seq structure to reset
59 void trace_seq_reset(struct trace_seq *s) in trace_seq_reset() argument
61 if (!s) in trace_seq_reset()
63 TRACE_SEQ_CHECK(s); in trace_seq_reset()
64 s->len = 0; in trace_seq_reset()
65 s->readpos = 0; in trace_seq_reset()
70 * @s: a pointer to the trace_seq to free the buffer
74 void trace_seq_destroy(struct trace_seq *s) in trace_seq_destroy() argument
76 if (!s) in trace_seq_destroy()
78 TRACE_SEQ_CHECK_RET(s); in trace_seq_destroy()
79 free(s->buffer); in trace_seq_destroy()
80 s->buffer = TRACE_SEQ_POISON; in trace_seq_destroy()
83 static void expand_buffer(struct trace_seq *s) in expand_buffer() argument
87 buf = realloc(s->buffer, s->buffer_size + TRACE_SEQ_BUF_SIZE); in expand_buffer()
89 s->state = TRACE_SEQ__MEM_ALLOC_FAILED; in expand_buffer()
93 s->buffer = buf; in expand_buffer()
94 s->buffer_size += TRACE_SEQ_BUF_SIZE; in expand_buffer()
99 * @s: trace sequence descriptor
102 * It returns 0 if the trace oversizes the buffer's free
109 * buffer (@s). Then the output may be either used by
113 trace_seq_printf(struct trace_seq *s, const char *fmt, ...) in trace_seq_printf() argument
120 TRACE_SEQ_CHECK_RET0(s); in trace_seq_printf()
122 len = (s->buffer_size - 1) - s->len; in trace_seq_printf()
125 ret = vsnprintf(s->buffer + s->len, len, fmt, ap); in trace_seq_printf()
129 expand_buffer(s); in trace_seq_printf()
134 s->len += ret; in trace_seq_printf()
141 * @s: trace sequence descriptor
144 * It returns 0 if the trace oversizes the buffer's free
151 * buffer (@s). Then the output may be either used by
155 trace_seq_vprintf(struct trace_seq *s, const char *fmt, va_list args) in trace_seq_vprintf() argument
161 TRACE_SEQ_CHECK_RET0(s); in trace_seq_vprintf()
163 len = (s->buffer_size - 1) - s->len; in trace_seq_vprintf()
165 ret = vsnprintf(s->buffer + s->len, len, fmt, args); in trace_seq_vprintf()
168 expand_buffer(s); in trace_seq_vprintf()
173 s->len += ret; in trace_seq_vprintf()
180 * @s: trace sequence descriptor
185 * into a special buffer (@s) for later retrieval by a sequencer
188 int trace_seq_puts(struct trace_seq *s, const char *str) in trace_seq_puts() argument
192 TRACE_SEQ_CHECK_RET0(s); in trace_seq_puts()
196 while (len > ((s->buffer_size - 1) - s->len)) in trace_seq_puts()
197 expand_buffer(s); in trace_seq_puts()
199 TRACE_SEQ_CHECK_RET0(s); in trace_seq_puts()
201 memcpy(s->buffer + s->len, str, len); in trace_seq_puts()
202 s->len += len; in trace_seq_puts()
207 int trace_seq_putc(struct trace_seq *s, unsigned char c) in trace_seq_putc() argument
209 TRACE_SEQ_CHECK_RET0(s); in trace_seq_putc()
211 while (s->len >= (s->buffer_size - 1)) in trace_seq_putc()
212 expand_buffer(s); in trace_seq_putc()
214 TRACE_SEQ_CHECK_RET0(s); in trace_seq_putc()
216 s->buffer[s->len++] = c; in trace_seq_putc()
221 void trace_seq_terminate(struct trace_seq *s) in trace_seq_terminate() argument
223 TRACE_SEQ_CHECK_RET(s); in trace_seq_terminate()
225 /* There's always one character left on the buffer */ in trace_seq_terminate()
226 s->buffer[s->len] = 0; in trace_seq_terminate()
229 int trace_seq_do_fprintf(struct trace_seq *s, FILE *fp) in trace_seq_do_fprintf() argument
231 TRACE_SEQ_CHECK(s); in trace_seq_do_fprintf()
233 switch (s->state) { in trace_seq_do_fprintf()
235 return fprintf(fp, "%.*s", s->len, s->buffer); in trace_seq_do_fprintf()
237 fprintf(fp, "%s\n", "Usage of trace_seq after it was destroyed"); in trace_seq_do_fprintf()
240 fprintf(fp, "%s\n", "Can't allocate trace_seq buffer memory"); in trace_seq_do_fprintf()
246 int trace_seq_do_printf(struct trace_seq *s) in trace_seq_do_printf() argument
248 return trace_seq_do_fprintf(s, stdout); in trace_seq_do_printf()