summaryrefslogtreecommitdiff
path: root/lib/printf.c
diff options
context:
space:
mode:
authorOndrej Zajicek <santiago@crfreenet.org>2013-11-23 11:50:34 +0100
committerOndrej Zajicek <santiago@crfreenet.org>2013-11-23 11:50:34 +0100
commit736e143fa50607fcd88132291e96089b899af979 (patch)
treec0fcd5fb3174bae8a39b3a32dfe582b2ccb6df17 /lib/printf.c
parent094d2bdb79e1ffa0a02761fd651aa0f0b6b0c585 (diff)
parent2b3d52aa421ae1c31e30107beefd82fddbb42854 (diff)
Merge branch 'master' into add-path
Conflicts: filter/filter.c nest/proto.c nest/rt-table.c proto/bgp/bgp.h proto/bgp/config.Y
Diffstat (limited to 'lib/printf.c')
-rw-r--r--lib/printf.c39
1 files changed, 38 insertions, 1 deletions
diff --git a/lib/printf.c b/lib/printf.c
index 14af1062..41e1cc0d 100644
--- a/lib/printf.c
+++ b/lib/printf.c
@@ -276,7 +276,7 @@ int bvsnprintf(char *buf, int size, const char *fmt, va_list args)
ip_ntox(va_arg(args, ip_addr), ipbuf);
else {
ip_ntop(va_arg(args, ip_addr), ipbuf);
- if (field_width > 0)
+ if (field_width == 1)
field_width = STD_ADDRESS_P_LENGTH;
}
s = ipbuf;
@@ -410,3 +410,40 @@ int bsnprintf(char * buf, int size, const char *fmt, ...)
va_end(args);
return i;
}
+
+int
+buffer_vprint(buffer *buf, const char *fmt, va_list args)
+{
+ int i = bvsnprintf((char *) buf->pos, buf->end - buf->pos, fmt, args);
+ buf->pos = (i >= 0) ? (buf->pos + i) : buf->end;
+ return i;
+}
+
+int
+buffer_print(buffer *buf, const char *fmt, ...)
+{
+ va_list args;
+ int i;
+
+ va_start(args, fmt);
+ i=bvsnprintf((char *) buf->pos, buf->end - buf->pos, fmt, args);
+ va_end(args);
+
+ buf->pos = (i >= 0) ? (buf->pos + i) : buf->end;
+ return i;
+}
+
+void
+buffer_puts(buffer *buf, const char *str)
+{
+ byte *bp = buf->pos;
+ byte *be = buf->end;
+
+ while (bp < be && *str)
+ *bp++ = *str++;
+
+ if (bp < be)
+ *bp = 0;
+
+ buf->pos = bp;
+}