seq_buf: Add seq_buf_do_printk() helper
[linux-2.6-microblaze.git] / lib / seq_buf.c
index 0a68f7a..45c450f 100644 (file)
@@ -93,6 +93,38 @@ int seq_buf_printf(struct seq_buf *s, const char *fmt, ...)
 }
 EXPORT_SYMBOL_GPL(seq_buf_printf);
 
+/**
+ * seq_buf_do_printk - printk seq_buf line by line
+ * @s: seq_buf descriptor
+ * @lvl: printk level
+ *
+ * printk()-s a multi-line sequential buffer line by line. The function
+ * makes sure that the buffer in @s is nul terminated and safe to read
+ * as a string.
+ */
+void seq_buf_do_printk(struct seq_buf *s, const char *lvl)
+{
+       const char *start, *lf;
+
+       if (s->size == 0 || s->len == 0)
+               return;
+
+       seq_buf_terminate(s);
+
+       start = s->buffer;
+       while ((lf = strchr(start, '\n'))) {
+               int len = lf - start + 1;
+
+               printk("%s%.*s", lvl, len, start);
+               start = ++lf;
+       }
+
+       /* No trailing LF */
+       if (start < s->buffer + s->len)
+               printk("%s%s\n", lvl, start);
+}
+EXPORT_SYMBOL_GPL(seq_buf_do_printk);
+
 #ifdef CONFIG_BINARY_PRINTF
 /**
  * seq_buf_bprintf - Write the printf string from binary arguments