diff --git a/misc.h b/misc.h index c4f0e14c..be9ff9c0 100644 --- a/misc.h +++ b/misc.h @@ -26,6 +26,7 @@ char *host_strrchr(const char *s, int c); char *host_strduptrim(const char *s); char *dupstr(const char *s); +wchar_t *dupwcs(const wchar_t *s); char *dupcat_fn(const char *s1, ...); #define dupcat(...) dupcat_fn(__VA_ARGS__, (const char *)NULL) char *dupprintf(const char *fmt, ...) PRINTF_LIKE(1, 2); diff --git a/utils/CMakeLists.txt b/utils/CMakeLists.txt index 3e43d4d7..38882059 100644 --- a/utils/CMakeLists.txt +++ b/utils/CMakeLists.txt @@ -25,6 +25,7 @@ add_sources_from_current_dir(utils dupcat.c dupprintf.c dupstr.c + dupwcs.c dup_mb_to_wc.c dup_wc_to_mb.c encode_utf8.c diff --git a/utils/dupwcs.c b/utils/dupwcs.c new file mode 100644 index 00000000..11fba330 --- /dev/null +++ b/utils/dupwcs.c @@ -0,0 +1,19 @@ +/* + * Allocate a duplicate of a NUL-terminated wchar_t string. + */ + +#include + +#include "defs.h" +#include "misc.h" + +wchar_t *dupwcs(const wchar_t *s) +{ + wchar_t *p = NULL; + if (s) { + int len = wcslen(s); + p = snewn(len + 1, wchar_t); + wcscpy(p, s); + } + return p; +}