diff options
Diffstat (limited to 'src/nvim/os')
-rw-r--r-- | src/nvim/os/env.c | 25 | ||||
-rw-r--r-- | src/nvim/os/fs.c | 18 | ||||
-rw-r--r-- | src/nvim/os/fs_defs.h | 6 | ||||
-rw-r--r-- | src/nvim/os/os_defs.h | 7 | ||||
-rw-r--r-- | src/nvim/os/pty_process_win.c | 30 |
5 files changed, 32 insertions, 54 deletions
diff --git a/src/nvim/os/env.c b/src/nvim/os/env.c index 33b67a8116..f5dbf0694e 100644 --- a/src/nvim/os/env.c +++ b/src/nvim/os/env.c @@ -178,7 +178,7 @@ char *os_getenvname_at_index(size_t index) for (wchar_t *it = env; *it != L'\0' || *(it + 1) != L'\0'; it++) { if (index == current_index) { char *utf8_str; - int conversion_result = utf16_to_utf8(it, &utf8_str); + int conversion_result = utf16_to_utf8(it, -1, &utf8_str); if (conversion_result != 0) { EMSG2("utf16_to_utf8 failed: %d", conversion_result); break; @@ -258,7 +258,7 @@ void os_get_hostname(char *hostname, size_t size) host_utf16[host_wsize] = '\0'; char *host_utf8; - int conversion_result = utf16_to_utf8(host_utf16, &host_utf8); + int conversion_result = utf16_to_utf8(host_utf16, -1, &host_utf8); if (conversion_result != 0) { EMSG2("utf16_to_utf8 failed: %d", conversion_result); return; @@ -412,6 +412,7 @@ void expand_env_esc(char_u *restrict srcp, bool esc, bool one, char_u *prefix) + FUNC_ATTR_NONNULL_ARG(1, 2) { char_u *tail; char_u *var; @@ -845,10 +846,10 @@ char *vim_getenv(const char *name) // next time, and others can also use it (e.g. Perl). if (vim_path != NULL) { if (vimruntime) { - vim_setenv("VIMRUNTIME", vim_path); + os_setenv("VIMRUNTIME", vim_path, 1); didset_vimruntime = true; } else { - vim_setenv("VIM", vim_path); + os_setenv("VIM", vim_path, 1); didset_vim = true; } } @@ -995,22 +996,6 @@ char_u * home_replace_save(buf_T *buf, char_u *src) FUNC_ATTR_NONNULL_RET return dst; } -/// Vim setenv() wrapper with special handling for $VIMRUNTIME to keep the -/// localization machinery sane. -void vim_setenv(const char *name, const char *val) -{ - os_setenv(name, val, 1); -#ifndef LOCALE_INSTALL_DIR - // When setting $VIMRUNTIME adjust the directory to find message - // translations to $VIMRUNTIME/lang. - if (*val != NUL && STRICMP(name, "VIMRUNTIME") == 0) { - char *buf = (char *)concat_str((char_u *)val, (char_u *)"/lang"); - bindtextdomain(PROJECT_NAME, buf); - xfree(buf); - } -#endif -} - /// Function given to ExpandGeneric() to obtain an environment variable name. char_u *get_env_name(expand_T *xp, int idx) diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c index dcb3ef7c4a..ae922e4040 100644 --- a/src/nvim/os/fs.c +++ b/src/nvim/os/fs.c @@ -293,7 +293,7 @@ static bool is_executable(const char *name, char **abspath) /// Checks if file `name` is executable under any of these conditions: /// - extension is in $PATHEXT and `name` is executable /// - result of any $PATHEXT extension appended to `name` is executable -static bool is_executable_ext(char *name, char **abspath) +static bool is_executable_ext(const char *name, char **abspath) FUNC_ATTR_NONNULL_ARG(1) { const bool is_unix_shell = strstr((char *)path_tail(p_sh), "sh") != NULL; @@ -1180,12 +1180,10 @@ char *os_resolve_shortcut(const char *fname) &IID_IShellLinkW, (void **)&pslw); if (hr == S_OK) { wchar_t *p; - const int conversion_result = utf8_to_utf16(fname, &p); - if (conversion_result != 0) { - EMSG2("utf8_to_utf16 failed: %d", conversion_result); - } - - if (p != NULL) { + const int r = utf8_to_utf16(fname, -1, &p); + if (r != 0) { + EMSG2("utf8_to_utf16 failed: %d", r); + } else if (p != NULL) { // Get a pointer to the IPersistFile interface. hr = pslw->lpVtbl->QueryInterface( pslw, &IID_IPersistFile, (void **)&ppf); @@ -1210,9 +1208,9 @@ char *os_resolve_shortcut(const char *fname) ZeroMemory(wsz, MAX_PATH * sizeof(wchar_t)); hr = pslw->lpVtbl->GetPath(pslw, wsz, MAX_PATH, &ffdw, 0); if (hr == S_OK && wsz[0] != NUL) { - const int conversion_result = utf16_to_utf8(wsz, &rfname); - if (conversion_result != 0) { - EMSG2("utf16_to_utf8 failed: %d", conversion_result); + const int r2 = utf16_to_utf8(wsz, -1, &rfname); + if (r2 != 0) { + EMSG2("utf16_to_utf8 failed: %d", r2); } } diff --git a/src/nvim/os/fs_defs.h b/src/nvim/os/fs_defs.h index 68e5c74ee1..f4929b12b1 100644 --- a/src/nvim/os/fs_defs.h +++ b/src/nvim/os/fs_defs.h @@ -21,12 +21,6 @@ typedef struct { uv_dirent_t ent; ///< @private The entry information. } Directory; -/// Converts libuv error (negative int) to error description string. -#define os_strerror uv_strerror - -/// Converts system error code to libuv error code. -#define os_translate_sys_error uv_translate_sys_error - // Values returned by os_nodetype() #define NODE_NORMAL 0 // file or directory, check with os_isdir() #define NODE_WRITABLE 1 // something we can write to (character diff --git a/src/nvim/os/os_defs.h b/src/nvim/os/os_defs.h index c29af5c160..c8ac4218f6 100644 --- a/src/nvim/os/os_defs.h +++ b/src/nvim/os/os_defs.h @@ -32,11 +32,12 @@ # include <strings.h> #endif -/// Function to convert libuv error to char * error description -/// -/// negative libuv error codes are returned by a number of os functions. +/// Converts libuv error (negative int) to error description string. #define os_strerror uv_strerror +/// Converts system error code to libuv error code. +#define os_translate_sys_error uv_translate_sys_error + #ifdef WIN32 # define os_strtok strtok_s #else diff --git a/src/nvim/os/pty_process_win.c b/src/nvim/os/pty_process_win.c index 290668bca3..183219bd3e 100644 --- a/src/nvim/os/pty_process_win.c +++ b/src/nvim/os/pty_process_win.c @@ -51,26 +51,26 @@ int pty_process_spawn(PtyProcess *ptyproc) cfg = winpty_config_new(WINPTY_FLAG_ALLOW_CURPROC_DESKTOP_CREATION, &err); if (cfg == NULL) { - emsg = "Failed, winpty_config_new."; + emsg = "winpty_config_new failed"; goto cleanup; } winpty_config_set_initial_size(cfg, ptyproc->width, ptyproc->height); winpty_object = winpty_open(cfg, &err); if (winpty_object == NULL) { - emsg = "Failed, winpty_open."; + emsg = "winpty_open failed"; goto cleanup; } - status = utf16_to_utf8(winpty_conin_name(winpty_object), &in_name); + status = utf16_to_utf8(winpty_conin_name(winpty_object), -1, &in_name); if (status != 0) { - emsg = "Failed to convert in_name from utf16 to utf8."; + emsg = "utf16_to_utf8(winpty_conin_name) failed"; goto cleanup; } - status = utf16_to_utf8(winpty_conout_name(winpty_object), &out_name); + status = utf16_to_utf8(winpty_conout_name(winpty_object), -1, &out_name); if (status != 0) { - emsg = "Failed to convert out_name from utf16 to utf8."; + emsg = "utf16_to_utf8(winpty_conout_name) failed"; goto cleanup; } @@ -93,9 +93,9 @@ int pty_process_spawn(PtyProcess *ptyproc) } if (proc->cwd != NULL) { - status = utf8_to_utf16(proc->cwd, &cwd); + status = utf8_to_utf16(proc->cwd, -1, &cwd); if (status != 0) { - emsg = "Failed to convert pwd form utf8 to utf16."; + emsg = "utf8_to_utf16(proc->cwd) failed"; goto cleanup; } } @@ -103,7 +103,7 @@ int pty_process_spawn(PtyProcess *ptyproc) status = build_cmd_line(proc->argv, &cmd_line, os_shell_is_cmdexe(proc->argv[0])); if (status != 0) { - emsg = "Failed to convert cmd line form utf8 to utf16."; + emsg = "build_cmd_line failed"; goto cleanup; } @@ -115,7 +115,7 @@ int pty_process_spawn(PtyProcess *ptyproc) NULL, // Optional environment variables &err); if (spawncfg == NULL) { - emsg = "Failed winpty_spawn_config_new."; + emsg = "winpty_spawn_config_new failed"; goto cleanup; } @@ -128,9 +128,9 @@ int pty_process_spawn(PtyProcess *ptyproc) &err)) { if (win_err) { status = (int)win_err; - emsg = "Failed spawn process."; + emsg = "failed to spawn process"; } else { - emsg = "Failed winpty_spawn."; + emsg = "winpty_spawn failed"; } goto cleanup; } @@ -160,11 +160,11 @@ int pty_process_spawn(PtyProcess *ptyproc) cleanup: if (status) { // In the case of an error of MultiByteToWideChar or CreateProcessW. - ELOG("%s error code: %d", emsg, status); + ELOG("pty_process_spawn: %s: error code: %d", emsg, status); status = os_translate_sys_error(status); } else if (err != NULL) { status = (int)winpty_error_code(err); - ELOG("%s error code: %d", emsg, status); + ELOG("pty_process_spawn: %s: error code: %d", emsg, status); status = translate_winpty_error(status); } winpty_error_free(err); @@ -308,7 +308,7 @@ static int build_cmd_line(char **argv, wchar_t **cmd_line, bool is_cmdexe) } } - int result = utf8_to_utf16(utf8_cmd_line, cmd_line); + int result = utf8_to_utf16(utf8_cmd_line, -1, cmd_line); xfree(utf8_cmd_line); return result; } |