diff options
author | FdaSilvaYY <fdasilvayy@gmail.com> | 2017-11-07 11:50:30 +0100 |
---|---|---|
committer | Rich Salz <rsalz@openssl.org> | 2017-11-13 07:52:35 -0500 |
commit | 4483fbae10a9277812cc8a587ef58a5a512fe7c9 (patch) | |
tree | c3879b67351cc43c7e61a671386ca7eeddd90799 /test/testutil | |
parent | 1a78a33aed6d182bf26a3e839341b9ea38dbcaa3 (diff) | |
download | openssl-4483fbae10a9277812cc8a587ef58a5a512fe7c9.tar.gz |
Factorise duplicated code.
Extract and factorise duplicated string glue code.
Cache strlen result to avoid duplicate calls.
[extended tests]
Reviewed-by: Andy Polyakov <appro@openssl.org>
Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/4719)
Diffstat (limited to 'test/testutil')
-rw-r--r-- | test/testutil/driver.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/test/testutil/driver.c b/test/testutil/driver.c index 48593f9201..9cdce7a4e0 100644 --- a/test/testutil/driver.c +++ b/test/testutil/driver.c @@ -272,3 +272,28 @@ int run_tests(const char *test_prog_name) return EXIT_SUCCESS; } +/* + * Glue an array of strings together and return it as an allocated string. + * Optionally return the whole length of this string in |out_len| + */ +char *glue_strings(const char *list[], size_t *out_len) +{ + size_t len = 0; + char *p, *ret; + int i; + + for (i = 0; list[i] != NULL; i++) + len += strlen(list[i]); + + if (out_len != NULL) + *out_len = len; + + if (!TEST_ptr(ret = p = OPENSSL_malloc(len + 1))) + return NULL; + + for (i = 0; list[i] != NULL; i++) + p += strlen(strcpy(p, list[i])); + + return ret; +} + |