diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 02:54:50 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 02:54:50 +0000 |
commit | 451520af975c978c8ffaa1d9a0959b50c1b8e294 (patch) | |
tree | c2abdd80665f8494280a65417a9c21156ff41125 /src/pty.c | |
parent | Adding upstream version 1.7.4. (diff) | |
download | ttyd-451520af975c978c8ffaa1d9a0959b50c1b8e294.tar.xz ttyd-451520af975c978c8ffaa1d9a0959b50c1b8e294.zip |
Adding upstream version 1.7.7.upstream/1.7.7upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | src/pty.c | 44 |
1 files changed, 16 insertions, 28 deletions
@@ -187,45 +187,33 @@ bool conpty_init() { return true; } +static WCHAR *to_utf16(char *str) { + int len = MultiByteToWideChar(CP_UTF8, 0, str, -1, NULL, 0); + if (len <= 0) return NULL; + WCHAR *wstr = xmalloc((len + 1) * sizeof(WCHAR)); + if (len != MultiByteToWideChar(CP_UTF8, 0, str, -1, wstr, len)) { + free(wstr); + return NULL; + } + wstr[len] = L'\0'; + return wstr; +} + // convert argv to cmdline for CreateProcessW static WCHAR *join_args(char **argv) { - char *args = NULL; + char args[256] = {0}; char **ptr = argv; for (; *ptr; ptr++) { char *quoted = (char *) quote_arg(*ptr); - size_t arg_len = args == NULL ? 1 : strlen(args) + 1; + size_t arg_len = strlen(args) + 1; size_t quoted_len = strlen(quoted); - args = xrealloc(args, arg_len + quoted_len); if (arg_len == 1) memset(args, 0, 2); if (arg_len != 1) strcat(args, " "); strncat(args, quoted, quoted_len); if (quoted != *ptr) free(quoted); } - - int len = MultiByteToWideChar(CP_UTF8, 0, args, -1, NULL, 0); - if (len <= 0) goto failed; - WCHAR *ws = (WCHAR *) xmalloc(len * sizeof(WCHAR)); - if (len != MultiByteToWideChar(CP_UTF8, 0, args, -1, ws, len)) { - free(ws); - goto failed; - } - return ws; - -failed: - if (args != NULL) free(args); - return NULL; -} - -static WCHAR *to_utf16(char *str) { - int len = MultiByteToWideChar(CP_UTF8, 0, str, -1, NULL, 0); - if (len <= 0) return NULL; - WCHAR *wstr = xmalloc((len + 1) * sizeof(WCHAR)); - if (len != MultiByteToWideChar(CP_UTF8, 0, str, -1, wstr, len)) { - free(wstr); - return NULL; - } - wstr[len] = L'\0'; - return wstr; + if (args[255] != '\0') args[255] = '\0'; // truncate + return to_utf16(args); } static bool conpty_setup(HPCON *hnd, COORD size, STARTUPINFOEXW *si_ex, char **in_name, char **out_name) { |