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)
if (! p)
return -1;
- va_start (args, format);
len = vsnprintf (p, size, format, args);
- va_end (args);
if (len > -1 && len < size)
break;
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,
extern struct vty *vty_new (void);
extern struct vty *vty_stdio (void (*atclose)(void));
extern int vty_out (struct vty *, const char *, ...) PRINTF_ATTRIBUTE(2, 3);
+extern int vty_outln (struct vty *, const char *, ...) PRINTF_ATTRIBUTE(2, 3);
extern void vty_read_config (const char *, char *);
extern void vty_time_print (struct vty *, int);
extern void vty_serv_sock (const char *, unsigned short, const char *);