From c83dced0d218b8cdce470e40968f5ab898478b1f Mon Sep 17 00:00:00 2001 From: Timo Strunk Date: Fri, 12 Sep 2014 17:46:40 +0200 Subject: [PATCH] Made safe version of string concat with delimiter --- file_path.c | 12 ++++++++++++ file_path.h | 4 ++++ 2 files changed, 16 insertions(+) diff --git a/file_path.c b/file_path.c index a88cdb5ca8..5336618d57 100644 --- a/file_path.c +++ b/file_path.c @@ -926,6 +926,18 @@ void fill_pathname_join(char *out_path, rarch_assert(strlcat(out_path, path, size) < size); } +void fill_pathname_join_delim(char *out_path, const char *dir, + const char *path, const char delim, size_t size) +{ + size_t copied = strlcpy(out_path, dir, size); + rarch_assert(copied < size+1); + + out_path[copied]=delim; + out_path[copied+1] = '\0'; + + rarch_assert(strlcat(out_path, path, size) < size); +} + void fill_pathname_expand_special(char *out_path, const char *in_path, size_t size) { diff --git a/file_path.h b/file_path.h index 3efd78c5e8..bd86f6f54f 100644 --- a/file_path.h +++ b/file_path.h @@ -193,6 +193,10 @@ void fill_pathname_resolve_relative(char *out_path, const char *in_refpath, void fill_pathname_join(char *out_path, const char *dir, const char *path, size_t size); +/* Joins a directory and path together using the given char. */ +void fill_pathname_join_delim(char *out_path, const char *dir, + const char *path, const char delim, size_t size); + /* Generates a short representation of path. It should only * be used for displaying the result; the output representation is not * binding in any meaningful way (for a normal path, this is the same as basename)