Re: [PATCH 1/4] stringbuf: A string buffer implementation

!MAILaRCHIVE_VOTE_RePLACE
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: Rusty Russell <rusty@...>
Cc: Matthew Wilcox <matthew@...>, Linus Torvalds <torvalds@...>, Andrew Morton <akpm@...>, <linux-kernel@...>, Matthew Wilcox <willy@...>
Date: Friday, October 26, 2007 - 1:05 am

Perhaps have an sb_alloc function and a failure mode that
uses printk when sb_alloc fails or sb_append is passed null?

Perhaps something like:

stringbuf *sb_alloc(char* level, gfp_t priority)
{
	stringbuf *sb = kmalloc(sizeof(*sb), priority);
	if (sb)
		sb>len = sprintf(sb->buf, "%s", level);
	else
		printk(level);
	return sb;
}
EXPORT_SYMBOL(sb_alloc);

/**
 * sb_append - append to a stringbuf
 * @sb: a pointer to the stringbuf
 * @fmt: printf-style format
 */
void sb_append(struct stringbuf *sb, const char *fmt, ...)
{
	va_list args;

	va_start(args, fmt);
	if (sb)
		sb->len += vscnprintf(&sb->buf[len], sizeof(sb->buf) - sb->len, fmt, args);
	else
		vprintk(fmt, args);
	va_end(args);
}
EXPORT_SYMBOL(sb_append);

void sb_printk(struct stringbuf *sb)
{
	if (sb && sb->len > 0) {
		printk(sb->buf);
		sb->len = 0;
	}
}
EXPORT_SYMBOL(sb_printk);

void sb_free(stringbuf *sb)
{
	kfree(sb);
}
EXPORT_SYMBOL(sb_free);


-
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
Stringbuf, v2, Matthew Wilcox, (Wed Oct 24, 3:58 pm)
Re: Stringbuf, v2, Joe Perches, (Wed Oct 24, 4:51 pm)
Re: Stringbuf, v2, Matthew Wilcox, (Wed Oct 24, 4:57 pm)
Re: Stringbuf, v2, Joe Perches, (Wed Oct 24, 5:06 pm)
Re: Stringbuf, v2, Matthew Wilcox, (Wed Oct 24, 5:34 pm)
[PATCH 1/4] stringbuf: A string buffer implementation, Matthew Wilcox, (Wed Oct 24, 3:59 pm)
Re: [PATCH 1/4] stringbuf: A string buffer implementation, Rusty Russell, (Thu Oct 25, 10:11 pm)
Re: [PATCH 1/4] stringbuf: A string buffer implementation, Rusty Russell, (Sat Oct 27, 8:50 am)
Re: [PATCH 1/4] stringbuf: A string buffer implementation, Pekka Enberg, (Sat Oct 27, 12:34 pm)
Re: [PATCH 1/4] stringbuf: A string buffer implementation, Matthew Wilcox, (Sat Oct 27, 12:48 pm)
Re: [PATCH 1/4] stringbuf: A string buffer implementation, Matthew Wilcox, (Fri Oct 26, 7:57 am)
Re: [PATCH 1/4] stringbuf: A string buffer implementation, Rusty Russell, (Sat Oct 27, 6:09 am)
Re: [PATCH 1/4] stringbuf: A string buffer implementation, Matt Mackall, (Sun Oct 28, 11:03 pm)
Re: [PATCH 1/4] stringbuf: A string buffer implementation, Rusty Russell, (Mon Oct 29, 1:38 am)
Re: [PATCH 1/4] stringbuf: A string buffer implementation, Joe Perches, (Fri Oct 26, 1:05 am)
Re: [PATCH 1/4] stringbuf: A string buffer implementation, Matthew Wilcox, (Wed Oct 24, 5:21 pm)
Re: [PATCH 1/4] stringbuf: A string buffer implementation, Matthew Wilcox, (Wed Oct 24, 11:23 pm)
[PATCH 2/4] isdn: Use stringbuf, Matthew Wilcox, (Wed Oct 24, 3:59 pm)
[PATCH 3/4] sound: Use stringbuf, Matthew Wilcox, (Wed Oct 24, 3:59 pm)
[PATCH 4/4] partitions: Fix non-atomic printk, Matthew Wilcox, (Wed Oct 24, 3:59 pm)