summaryrefslogtreecommitdiffstats
path: root/ctdb/lib/replace/test/snprintf.c
diff options
context:
space:
mode:
authorMichael Adam <obnox@samba.org>2011-11-25 16:36:40 +0100
committerMichael Adam <obnox@samba.org>2011-11-26 00:34:54 +0100
commit2c0abf2dcf040e6e32612e65f04ff488745612ae (patch)
treed2c86b044dd2727e469f65e66bca49fe958d6b66 /ctdb/lib/replace/test/snprintf.c
parent5d94dff27e96e09e1f81d4811ce1e2492edff13f (diff)
downloadsamba-2c0abf2dcf040e6e32612e65f04ff488745612ae.tar.gz
samba-2c0abf2dcf040e6e32612e65f04ff488745612ae.tar.xz
samba-2c0abf2dcf040e6e32612e65f04ff488745612ae.zip
update lib/replace to current upstream version (samba master)
(This used to be ctdb commit 17bcffab19fdbb435b4745ff90c327342bbbf0f8)
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"); }