Example #1
0
/*
 * Clear an sbuf and reset its position.
 */
void
sbuf_clear(struct sbuf *s)
{
	assert_sbuf_integrity(s);
	/* don't care if it's finished or not */

	SBUF_CLEARFLAG(s, SBUF_FINISHED);
	SBUF_CLEARFLAG(s, SBUF_OVERFLOWED);
	s->s_len = 0;
}
Example #2
0
/*
 * End the section padding to the specified length with the specified
 * character.
 */
ssize_t
sbuf_end_section(struct sbuf *s, ssize_t old_len, size_t pad, int c)
{
	ssize_t len;

	assert_sbuf_integrity(s);
	assert_sbuf_state(s, 0);
	KASSERT(SBUF_ISSECTION(s),
	    ("attempt to end a section when not in a section"));

	if (pad > 1) {
		len = roundup(s->s_sect_len, pad) - s->s_sect_len;
		for (; s->s_error == 0 && len > 0; len--)
			sbuf_put_byte(s, c);
	}
	len = s->s_sect_len;
	if (old_len == -1) {
		s->s_sect_len = 0;
		SBUF_CLEARFLAG(s, SBUF_INSECTION);
	} else {
		s->s_sect_len += old_len;
	}
	if (s->s_error != 0)
		return (-1);
	return (len);
}
Example #3
0
/*
 * Finish off an sbuf.
 */
void
sbuf_finish(struct sbuf *s)
{
	assert_sbuf_integrity(s);
	assert_sbuf_state(s, 0);
	
	s->s_buf[s->s_len] = '\0';
	SBUF_CLEARFLAG(s, SBUF_OVERFLOWED);
	SBUF_SETFLAG(s, SBUF_FINISHED);
}
Example #4
0
/*
 * Clear an sbuf and reset its position.
 */
void
sbuf_clear(struct sbuf *s)
{

	assert_sbuf_integrity(s);
	/* don't care if it's finished or not */

	SBUF_CLEARFLAG(s, SBUF_FINISHED);
	s->s_error = 0;
	s->s_len = 0;
	s->s_rec_off = 0;
	s->s_sect_len = 0;
}