summaryrefslogtreecommitdiff
path: root/lib/vty.c
diff options
context:
space:
mode:
authorQuentin Young <qlyoung@cumulusnetworks.com>2017-06-21 02:47:44 +0000
committerQuentin Young <qlyoung@cumulusnetworks.com>2017-06-29 16:28:21 +0000
commit4d5f445750e01467898eee47796e80d808500d56 (patch)
tree6944f01b1f97388a7a1fb1d69b0b5e548a6aa5a4 /lib/vty.c
parent9e3b206d7c25902cd3917d8969f16d118c8fea91 (diff)
lib: add vty_outln()
Like *.println() in some other unspeakable languages Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
Diffstat (limited to 'lib/vty.c')
-rw-r--r--lib/vty.c45
1 files changed, 32 insertions, 13 deletions
diff --git a/lib/vty.c b/lib/vty.c
index 54a5f727e1..c6a22503b9 100644
--- a/lib/vty.c
+++ b/lib/vty.c
@@ -92,28 +92,23 @@ char integrate_default[] = SYSCONFDIR INTEGRATE_DEFAULT_CONFIG;
static int do_log_commands = 0;
-/* VTY standard output function. */
-int
-vty_out (struct vty *vty, const char *format, ...)
+static int
+vty_out_variadic (struct vty *vty, const char *format, va_list args)
{
- va_list args;
int len = 0;
int size = 1024;
char buf[1024];
char *p = NULL;
+ va_list cp;
if (vty_shell (vty))
- {
- va_start (args, format);
- vprintf (format, args);
- va_end (args);
- }
+ vprintf (format, args);
else
{
/* Try to write to initial buffer. */
- va_start (args, format);
+ va_copy (cp, args);
len = vsnprintf (buf, sizeof(buf), format, args);
- va_end (args);
+ va_end (cp);
/* Initial buffer is not enough. */
if (len < 0 || len >= size)
@@ -129,9 +124,7 @@ vty_out (struct vty *vty, const char *format, ...)
if (! p)
return -1;
- va_start (args, format);
len = vsnprintf (p, size, format, args);
- va_end (args);
if (len > -1 && len < size)
break;
@@ -152,6 +145,32 @@ vty_out (struct vty *vty, const char *format, ...)
return len;
}
+/* VTY standard output function. */
+int
+vty_out (struct vty *vty, const char *format, ...)
+{
+ int len;
+ va_list args;
+
+ va_start (args, format);
+ len = vty_out_variadic (vty, format, args);
+ va_end (args);
+
+ return len;
+}
+
+int
+vty_outln (struct vty *vty, const char *format, ...)
+{
+ int len;
+ va_list args;
+
+ va_start (args, format);
+ len = vty_out_variadic (vty, format, args);
+ va_end (args);
+
+ return len + vty_out (vty, "%s", VTY_NEWLINE);
+}
static int
vty_log_out (struct vty *vty, const char *level, const char *proto_str,