summaryrefslogtreecommitdiffstats
path: root/ctdb/lib/replace/test/snprintf.c
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2013-11-13 14:17:32 +0100
committerMichael Adam <obnox@samba.org>2013-11-13 14:18:52 +0100
commitf087a8e2b81fae82fa571ef09d2d1cb682cc8ff8 (patch)
treed4a6b14a1594958150b733180d995b5c32025017 /ctdb/lib/replace/test/snprintf.c
parente80a5aba3db8e81173fa443991e08ef4a300ea5c (diff)
parent25f3c8b5269863aadbe72e304da7012782ef5b25 (diff)
downloadsamba-f087a8e2b81fae82fa571ef09d2d1cb682cc8ff8.tar.gz
samba-f087a8e2b81fae82fa571ef09d2d1cb682cc8ff8.tar.xz
samba-f087a8e2b81fae82fa571ef09d2d1cb682cc8ff8.zip
Merge branch 'master' of ctdb into 'master' of samba
Signed-off-by: Stefan Metzmacher <metze@samba.org> Signed-off-by: Michael Adam <obnox@samba.org>
Diffstat (limited to 'ctdb/lib/replace/test/snprintf.c')
-rw-r--r--ctdb/lib/replace/test/snprintf.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/ctdb/lib/replace/test/snprintf.c b/ctdb/lib/replace/test/snprintf.c
new file mode 100644
index 0000000000..d06630bcc9
--- /dev/null
+++ b/ctdb/lib/replace/test/snprintf.c
@@ -0,0 +1,29 @@
+void foo(const char *format, ...)
+{
+ va_list ap;
+ int len;
+ char buf[20];
+ long long l = 1234567890;
+ l *= 100;
+
+ va_start(ap, format);
+ len = vsnprintf(buf, 0, format, ap);
+ va_end(ap);
+ if (len != 5) exit(1);
+
+ va_start(ap, format);
+ len = vsnprintf(0, 0, format, ap);
+ va_end(ap);
+ if (len != 5) exit(2);
+
+ if (snprintf(buf, 3, "hello") != 5 || strcmp(buf, "he") != 0) exit(3);
+
+ if (snprintf(buf, 20, "%lld", l) != 12 || strcmp(buf, "123456789000") != 0) exit(4);
+ if (snprintf(buf, 20, "%zu", 123456789) != 9 || strcmp(buf, "123456789") != 0) exit(5);
+ if (snprintf(buf, 20, "%2\$d %1\$d", 3, 4) != 3 || strcmp(buf, "4 3") != 0) exit(6);
+ if (snprintf(buf, 20, "%s", 0) < 3) exit(7);
+
+ printf("1");
+ exit(0);
+}
+main() { foo("hello"); }