summaryrefslogtreecommitdiffstats
path: root/src/test/test-strxcpyx.c
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2019-07-03 16:27:27 +0200
committerYu Watanabe <watanabe.yu+github@gmail.com>2019-07-04 19:43:56 +0200
commit442ac2692a04a171fa2e99ac2405150b7bc38ca7 (patch)
tree71e5638c95e1a4b098f6338a89adce727c25c0bb /src/test/test-strxcpyx.c
parentfsck: split out fsck return code definitions into a header file of its own (diff)
downloadsystemd-442ac2692a04a171fa2e99ac2405150b7bc38ca7.tar.xz
systemd-442ac2692a04a171fa2e99ac2405150b7bc38ca7.zip
sd-event: replace snprintf() with strpcpyf()
Diffstat (limited to 'src/test/test-strxcpyx.c')
-rw-r--r--src/test/test-strxcpyx.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/test/test-strxcpyx.c b/src/test/test-strxcpyx.c
index 21d56d9be6..d7199124a3 100644
--- a/src/test/test-strxcpyx.c
+++ b/src/test/test-strxcpyx.c
@@ -1,5 +1,6 @@
/* SPDX-License-Identifier: LGPL-2.1+ */
+#include <stdio.h>
#include <string.h>
#include "string-util.h"
@@ -78,6 +79,24 @@ static void test_strscpyl(void) {
assert_se(space_left == 10);
}
+static void test_sd_event_code_migration(void) {
+ char b[100 * DECIMAL_STR_MAX(unsigned) + 1];
+ char c[100 * DECIMAL_STR_MAX(unsigned) + 1], *p;
+ unsigned i;
+ size_t l;
+ int o;
+
+ for (i = o = 0; i < 100; i++)
+ o += snprintf(&b[o], sizeof(b) - o, "%u ", i);
+
+ p = c;
+ l = sizeof(c);
+ for (i = 0; i < 100; i++)
+ l = strpcpyf(&p, l, "%u ", i);
+
+ assert_se(streq(b, c));
+}
+
int main(int argc, char *argv[]) {
test_strpcpy();
test_strpcpyf();
@@ -85,5 +104,7 @@ int main(int argc, char *argv[]) {
test_strscpy();
test_strscpyl();
+ test_sd_event_code_migration();
+
return 0;
}