/* * Trace sequences are used to allow a function to call several other functions * to create a string of data to use.
*/
/** * struct seq_buf - seq buffer structure * @buffer: pointer to the buffer * @size: size of the buffer * @len: the amount of data inside the buffer
*/ struct seq_buf { char *buffer;
size_t size;
size_t len;
};
/* * seq_buf have a buffer that might overflow. When this happens * len is set to be greater than size.
*/ staticinlinebool
seq_buf_has_overflowed(struct seq_buf *s)
{ return s->len > s->size;
}
/* * How much buffer is left on the seq_buf?
*/ staticinlineunsignedint
seq_buf_buffer_left(struct seq_buf *s)
{ if (seq_buf_has_overflowed(s)) return 0;
return s->size - s->len;
}
/* How much buffer was written? */ staticinlineunsignedint seq_buf_used(struct seq_buf *s)
{ return min(s->len, s->size);
}
/** * seq_buf_str - get NUL-terminated C string from seq_buf * @s: the seq_buf handle * * This makes sure that the buffer in @s is NUL-terminated and * safe to read as a string. * * Note, if this is called when the buffer has overflowed, then * the last byte of the buffer is zeroed, and the len will still * point passed it. * * After this function is called, s->buffer is safe to use * in string operations. * * Returns: @s->buf after making sure it is terminated.
*/ staticinlineconstchar *seq_buf_str(struct seq_buf *s)
{ if (WARN_ON(s->size == 0)) return"";
/** * seq_buf_get_buf - get buffer to write arbitrary data to * @s: the seq_buf handle * @bufp: the beginning of the buffer is stored here * * Returns: the number of bytes available in the buffer, or zero if * there's no space.
*/ staticinline size_t seq_buf_get_buf(struct seq_buf *s, char **bufp)
{
WARN_ON(s->len > s->size + 1);
/** * seq_buf_commit - commit data to the buffer * @s: the seq_buf handle * @num: the number of bytes to commit * * Commit @num bytes of data written to a buffer previously acquired * by seq_buf_get_buf(). To signal an error condition, or that the data * didn't fit in the available space, pass a negative @num value.
*/ staticinlinevoid seq_buf_commit(struct seq_buf *s, int num)
{ if (num < 0) {
seq_buf_set_overflow(s);
} else { /* num must be negative on overflow */
BUG_ON(s->len + num > s->size);
s->len += num;
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.