1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-09 17:38:00 +00:00

New utility function: dupwcs.

Just like dupstr, but for wchar_t strings.
This commit is contained in:
Simon Tatham 2023-05-28 11:49:12 +01:00
parent 5f43d11f83
commit 36db93748e
3 changed files with 21 additions and 0 deletions

1
misc.h
View File

@ -26,6 +26,7 @@ char *host_strrchr(const char *s, int c);
char *host_strduptrim(const char *s); char *host_strduptrim(const char *s);
char *dupstr(const char *s); char *dupstr(const char *s);
wchar_t *dupwcs(const wchar_t *s);
char *dupcat_fn(const char *s1, ...); char *dupcat_fn(const char *s1, ...);
#define dupcat(...) dupcat_fn(__VA_ARGS__, (const char *)NULL) #define dupcat(...) dupcat_fn(__VA_ARGS__, (const char *)NULL)
char *dupprintf(const char *fmt, ...) PRINTF_LIKE(1, 2); char *dupprintf(const char *fmt, ...) PRINTF_LIKE(1, 2);

View File

@ -25,6 +25,7 @@ add_sources_from_current_dir(utils
dupcat.c dupcat.c
dupprintf.c dupprintf.c
dupstr.c dupstr.c
dupwcs.c
dup_mb_to_wc.c dup_mb_to_wc.c
dup_wc_to_mb.c dup_wc_to_mb.c
encode_utf8.c encode_utf8.c

19
utils/dupwcs.c Normal file
View File

@ -0,0 +1,19 @@
/*
* Allocate a duplicate of a NUL-terminated wchar_t string.
*/
#include <wchar.h>
#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;
}