diff options
author | Andreas Schneider <asn@cryptomilk.org> | 2016-09-21 14:21:33 +0200 |
---|---|---|
committer | Andreas Schneider <asn@cryptomilk.org> | 2016-09-21 14:21:33 +0200 |
commit | 82a8748cd27e403b5a34f5eca571699de6f14403 (patch) | |
tree | aa76393fb81f858eb247ad1445341a2d28b1a8f1 | |
parent | b516b621f78ed89b353240c1ea09ab76c5dbe6be (diff) | |
download | cmocka-82a8748cd27e403b5a34f5eca571699de6f14403.tar.gz cmocka-82a8748cd27e403b5a34f5eca571699de6f14403.tar.bz2 cmocka-82a8748cd27e403b5a34f5eca571699de6f14403.zip |
cmocka: Add file pattern to create xml file for each group
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
-rw-r--r-- | src/cmocka.c | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/src/cmocka.c b/src/cmocka.c index abe1863..7d4679e 100644 --- a/src/cmocka.c +++ b/src/cmocka.c @@ -88,6 +88,10 @@ #define CMOCKA_CLOCK_GETTIME(clock_id, ts) #endif +#ifndef MAX +#define MAX(a,b) ((a) < (b) ? (b) : (a)) +#endif + /** * POSIX has sigsetjmp/siglongjmp, while Windows only has setjmp/longjmp. */ @@ -421,6 +425,41 @@ static void set_source_location( } +static int c_strreplace(char *src, + size_t src_len, + const char *pattern, + const char *repl) +{ + char *p = NULL; + + p = strstr(src, pattern); + if (p == NULL) { + return -1; + } + + do { + size_t of = p - src; + size_t l = strlen(src); + size_t pl = strlen(pattern); + size_t rl = strlen(repl); + + /* overflow check */ + if (src_len <= l + MAX(pl, rl) + 1) { + return -1; + } + + if (rl != pl) { + memmove(src + of + rl, src + of + pl, l - of - pl + 1); + } + + strncpy(src + of, repl, rl); + + p = strstr(src, pattern); + } while (p != NULL); + + return 0; +} + /* Create function results and expected parameter lists. */ void initialize_testing(const char *test_name) { (void)test_name; @@ -2124,8 +2163,15 @@ static void cmprintf_group_finish_xml(const char *group_name, env = getenv("CMOCKA_XML_FILE"); if (env != NULL) { char buf[1024]; + int rc; + snprintf(buf, sizeof(buf), "%s", env); + rc = c_strreplace(buf, sizeof(buf), "%g", group_name); + if (rc < 0) { + snprintf(buf, sizeof(buf), "%s", env); + } + fp = fopen(buf, "r"); if (fp == NULL) { fp = fopen(buf, "w"); |