From fb1edb2f5728d74ae811c6ab32395598cea5609b Mon Sep 17 00:00:00 2001 From: Dundar Göc Date: Fri, 26 Aug 2022 23:11:25 +0200 Subject: refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/os/fs.c | 4 ++-- src/nvim/os/shell.c | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c index c0d5616666..158c22efaf 100644 --- a/src/nvim/os/fs.c +++ b/src/nvim/os/fs.c @@ -821,10 +821,10 @@ int os_fchown(int fd, uv_uid_t owner, uv_gid_t group) /// Check if a path exists. /// /// @return `true` if `path` exists -bool os_path_exists(const char_u *path) +bool os_path_exists(const char *path) { uv_stat_t statbuf; - return os_stat((char *)path, &statbuf) == kLibuvSuccess; + return os_stat(path, &statbuf) == kLibuvSuccess; } /// Sets file access and modification times. diff --git a/src/nvim/os/shell.c b/src/nvim/os/shell.c index 461a79c37b..35390e3dc1 100644 --- a/src/nvim/os/shell.c +++ b/src/nvim/os/shell.c @@ -503,7 +503,7 @@ int os_expand_wildcards(int num_pat, char **pat, int *num_file, char ***file, in // Move the file names to allocated memory. for (j = 0, i = 0; i < *num_file; i++) { // Require the files to exist. Helps when using /bin/sh - if (!(flags & EW_NOTFOUND) && !os_path_exists((char_u *)(*file)[i])) { + if (!(flags & EW_NOTFOUND) && !os_path_exists((*file)[i])) { continue; } @@ -1112,7 +1112,7 @@ static void out_data_append_to_screen(char *output, size_t *count, bool eof) goto end; } - (void)msg_outtrans_len_attr((char_u *)p, i, 0); + (void)msg_outtrans_len_attr(p, i, 0); p += i; } } @@ -1208,7 +1208,7 @@ static void read_input(DynamicBuffer *buf) { size_t written = 0, l = 0, len = 0; linenr_T lnum = curbuf->b_op_start.lnum; - char_u *lp = ml_get(lnum); + char_u *lp = (char_u *)ml_get(lnum); for (;;) { l = strlen((char *)lp + written); @@ -1240,7 +1240,7 @@ static void read_input(DynamicBuffer *buf) if (lnum > curbuf->b_op_end.lnum) { break; } - lp = ml_get(lnum); + lp = (char_u *)ml_get(lnum); written = 0; } else if (len > 0) { written += len; -- cgit From 49e893f296bca9eef5ff45a3d746c261d055bf10 Mon Sep 17 00:00:00 2001 From: Dundar Göc Date: Fri, 26 Aug 2022 23:11:25 +0200 Subject: refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/os/shell.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/shell.c b/src/nvim/os/shell.c index 35390e3dc1..f3b3c1dfbf 100644 --- a/src/nvim/os/shell.c +++ b/src/nvim/os/shell.c @@ -64,7 +64,7 @@ static void save_patterns(int num_pat, char **pat, int *num_file, char ***file) static bool have_wildcard(int num, char **file) { for (int i = 0; i < num; i++) { - if (path_has_wildcard((char_u *)file[i])) { + if (path_has_wildcard(file[i])) { return true; } } @@ -1106,7 +1106,7 @@ static void out_data_append_to_screen(char *output, size_t *count, bool eof) // incomplete UTF-8 sequence that could be composing with the last // complete sequence. // This will be corrected when we switch to vterm based implementation - int i = *p ? utfc_ptr2len_len((char_u *)p, (int)(end - p)) : 1; + int i = *p ? utfc_ptr2len_len(p, (int)(end - p)) : 1; if (!eof && i == 1 && utf8len_tab_zero[*(uint8_t *)p] > (end - p)) { *count = (size_t)(p - output); goto end; -- cgit From 04bd700ac3bc2bdea0e0d8747de95dab2034aa11 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 24 Jul 2022 11:26:54 +0800 Subject: feat(tui): support 'mousemoveevent' --- src/nvim/os/input.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/input.c b/src/nvim/os/input.c index bfe6d59dc6..ea9f31d776 100644 --- a/src/nvim/os/input.c +++ b/src/nvim/os/input.c @@ -293,7 +293,8 @@ static uint8_t check_multiclick(int code, int grid, int row, int col) || code == KE_MOUSEDOWN || code == KE_MOUSEUP || code == KE_MOUSELEFT - || code == KE_MOUSERIGHT) { + || code == KE_MOUSERIGHT + || code == KE_MOUSEMOVE) { return 0; } uint64_t mouse_time = os_hrtime(); // time of current mouse click (ns) @@ -347,7 +348,8 @@ static unsigned int handle_mouse_event(char **ptr, uint8_t *buf, unsigned int bu if (type != KS_EXTRA || !((mouse_code >= KE_LEFTMOUSE && mouse_code <= KE_RIGHTRELEASE) - || (mouse_code >= KE_MOUSEDOWN && mouse_code <= KE_MOUSERIGHT))) { + || (mouse_code >= KE_MOUSEDOWN && mouse_code <= KE_MOUSERIGHT) + || mouse_code == KE_MOUSEMOVE)) { return bufsize; } -- cgit From 73207cae611a1efb8cd17139e8228772daeb9866 Mon Sep 17 00:00:00 2001 From: Dundar Göc Date: Fri, 26 Aug 2022 23:11:25 +0200 Subject: refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/os/env.c | 6 +++--- src/nvim/os/shell.c | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/env.c b/src/nvim/os/env.c index c940c86675..2f2a8c7fdc 100644 --- a/src/nvim/os/env.c +++ b/src/nvim/os/env.c @@ -669,8 +669,8 @@ void expand_env_esc(char_u *restrict srcp, char_u *restrict dst, int dstlen, boo ExpandInit(&xpc); xpc.xp_context = EXPAND_FILES; - var = ExpandOne(&xpc, dst, NULL, - WILD_ADD_SLASH|WILD_SILENT, WILD_EXPAND_FREE); + var = (char_u *)ExpandOne(&xpc, (char *)dst, NULL, + WILD_ADD_SLASH|WILD_SILENT, WILD_EXPAND_FREE); mustfree = true; } #else @@ -684,7 +684,7 @@ void expand_env_esc(char_u *restrict srcp, char_u *restrict dst, int dstlen, boo // If 'shellslash' is set change backslashes to forward slashes. // Can't use slash_adjust(), p_ssl may be set temporarily. if (p_ssl && var != NULL && vim_strchr(var, '\\') != NULL) { - char_u *p = vim_strsave(var); + char_u *p = xstrdup(var); if (mustfree) { xfree(var); diff --git a/src/nvim/os/shell.c b/src/nvim/os/shell.c index f3b3c1dfbf..25f51f89a9 100644 --- a/src/nvim/os/shell.c +++ b/src/nvim/os/shell.c @@ -52,11 +52,11 @@ static void save_patterns(int num_pat, char **pat, int *num_file, char ***file) { *file = xmalloc((size_t)num_pat * sizeof(char_u *)); for (int i = 0; i < num_pat; i++) { - char_u *s = vim_strsave((char_u *)pat[i]); + char *s = xstrdup(pat[i]); // Be compatible with expand_filename(): halve the number of // backslashes. - backslash_halve((char *)s); - (*file)[i] = (char *)s; + backslash_halve(s); + (*file)[i] = s; } *num_file = num_pat; } @@ -160,7 +160,7 @@ int os_expand_wildcards(int num_pat, char **pat, int *num_file, char ***file, in } // get a name for the temp file - if ((tempname = vim_tempname()) == NULL) { + if ((tempname = (char_u *)vim_tempname()) == NULL) { emsg(_(e_notmp)); return FAIL; } @@ -746,7 +746,7 @@ char_u *get_cmd_output(char_u *cmd, char_u *infile, ShellOpts flags, size_t *ret } // get a name for the temp file - char_u *tempname = vim_tempname(); + char_u *tempname = (char_u *)vim_tempname(); if (tempname == NULL) { emsg(_(e_notmp)); return NULL; -- cgit From c5322e752e9e568de907f7a1ef733bbfe342140c Mon Sep 17 00:00:00 2001 From: Dundar Göc Date: Fri, 26 Aug 2022 23:11:25 +0200 Subject: refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/os/shell.c | 20 ++++++++++---------- src/nvim/os/users.c | 6 +++--- 2 files changed, 13 insertions(+), 13 deletions(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/shell.c b/src/nvim/os/shell.c index 25f51f89a9..cf66899493 100644 --- a/src/nvim/os/shell.c +++ b/src/nvim/os/shell.c @@ -129,7 +129,7 @@ int os_expand_wildcards(int num_pat, char **pat, int *num_file, char ***file, in bool is_fish_shell = #if defined(UNIX) - STRNCMP(invocation_path_tail(p_sh, NULL), "fish", 4) == 0; + STRNCMP(invocation_path_tail((char_u *)p_sh, NULL), "fish", 4) == 0; #else false; #endif @@ -182,14 +182,14 @@ int os_expand_wildcards(int num_pat, char **pat, int *num_file, char ***file, in && *(pat[0] + len - 1) == '`') { shell_style = STYLE_BT; } else if ((len = STRLEN(p_sh)) >= 3) { - if (STRCMP(p_sh + len - 3, "csh") == 0) { + if (strcmp(p_sh + len - 3, "csh") == 0) { shell_style = STYLE_GLOB; - } else if (STRCMP(p_sh + len - 3, "zsh") == 0) { + } else if (strcmp(p_sh + len - 3, "zsh") == 0) { shell_style = STYLE_PRINT; } } if (shell_style == STYLE_ECHO - && strstr(path_tail((char *)p_sh), "sh") != NULL) { + && strstr(path_tail(p_sh), "sh") != NULL) { shell_style = STYLE_VIMGLOB; } @@ -555,11 +555,11 @@ notfound: char **shell_build_argv(const char *cmd, const char *extra_args) FUNC_ATTR_NONNULL_RET { - size_t argc = tokenize(p_sh, NULL) + (cmd ? tokenize(p_shcf, NULL) : 0); + size_t argc = tokenize((char_u *)p_sh, NULL) + (cmd ? tokenize(p_shcf, NULL) : 0); char **rv = xmalloc((argc + 4) * sizeof(*rv)); // Split 'shell' - size_t i = tokenize(p_sh, rv); + size_t i = tokenize((char_u *)p_sh, rv); if (extra_args) { rv[i++] = xstrdup(extra_args); // Push a copy of `extra_args` @@ -700,7 +700,7 @@ int call_shell(char_u *cmd, ShellOpts opts, char_u *extra_shell_arg) if (p_verbose > 3) { verbose_enter(); - smsg(_("Executing command: \"%s\""), cmd == NULL ? p_sh : cmd); + smsg(_("Executing command: \"%s\""), cmd == NULL ? p_sh : (char *)cmd); msg_putchar('\n'); verbose_leave(); } @@ -1316,7 +1316,7 @@ static char *shell_xescape_xquote(const char *cmd) } const char *ecmd = cmd; - if (*p_sxe != NUL && STRCMP(p_sxq, "(") == 0) { + if (*p_sxe != NUL && strcmp(p_sxq, "(") == 0) { ecmd = (char *)vim_strsave_escaped_ext((char_u *)cmd, p_sxe, '^', false); } size_t ncmd_size = strlen(ecmd) + STRLEN(p_sxq) * 2 + 1; @@ -1324,9 +1324,9 @@ static char *shell_xescape_xquote(const char *cmd) // When 'shellxquote' is ( append ). // When 'shellxquote' is "( append )". - if (STRCMP(p_sxq, "(") == 0) { + if (strcmp(p_sxq, "(") == 0) { vim_snprintf(ncmd, ncmd_size, "(%s)", ecmd); - } else if (STRCMP(p_sxq, "\"(") == 0) { + } else if (strcmp(p_sxq, "\"(") == 0) { vim_snprintf(ncmd, ncmd_size, "\"(%s)\"", ecmd); } else { vim_snprintf(ncmd, ncmd_size, "%s%s%s", p_sxq, ecmd, p_sxq); diff --git a/src/nvim/os/users.c b/src/nvim/os/users.c index bd34e917b2..0c662e8843 100644 --- a/src/nvim/os/users.c +++ b/src/nvim/os/users.c @@ -93,7 +93,7 @@ int os_get_usernames(garray_T *users) for (i = 0; i < users->ga_len; i++) { char *local_user = ((char **)users->ga_data)[i]; - if (STRCMP(local_user, user_env) == 0) { + if (strcmp(local_user, user_env) == 0) { break; } } @@ -208,14 +208,14 @@ char *get_users(expand_T *xp, int idx) /// @return 0 if name does not match any user name. /// 1 if name partially matches the beginning of a user name. /// 2 is name fully matches a user name. -int match_user(char_u *name) +int match_user(char *name) { int n = (int)STRLEN(name); int result = 0; init_users(); for (int i = 0; i < ga_users.ga_len; i++) { - if (STRCMP(((char_u **)ga_users.ga_data)[i], name) == 0) { + if (strcmp(((char **)ga_users.ga_data)[i], name) == 0) { return 2; // full match } if (STRNCMP(((char_u **)ga_users.ga_data)[i], name, n) == 0) { -- cgit From 684bc749efef0fa31395d349f4495d79ec5f3fd5 Mon Sep 17 00:00:00 2001 From: Dundar Göc Date: Fri, 26 Aug 2022 23:11:25 +0200 Subject: refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/os/env.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/env.c b/src/nvim/os/env.c index 2f2a8c7fdc..34ed3aaf6e 100644 --- a/src/nvim/os/env.c +++ b/src/nvim/os/env.c @@ -476,7 +476,7 @@ void init_homedir(void) // Change to the directory and get the actual path. This resolves // links. Don't do it when we can't return. if (os_dirname((char_u *)os_buf, MAXPATHL) == OK && os_chdir(os_buf) == 0) { - if (!os_chdir(var) && os_dirname(IObuff, IOSIZE) == OK) { + if (!os_chdir(var) && os_dirname((char_u *)IObuff, IOSIZE) == OK) { var = (char *)IObuff; } if (os_chdir(os_buf) != 0) { @@ -804,7 +804,7 @@ static char *remove_tail(char *path, char *pend, char *dirname) char *new_tail = pend - len - 1; if (new_tail >= path - && FNAMENCMP((char_u *)new_tail, (char_u *)dirname, len) == 0 + && path_fnamencmp(new_tail, dirname, len) == 0 && (new_tail == path || after_pathsep(path, new_tail))) { return new_tail; } @@ -1098,7 +1098,7 @@ size_t home_replace(const buf_T *const buf, const char *src, char *const dst, si size_t len = dirlen; for (;;) { if (len - && FNAMENCMP(src, (char_u *)p, len) == 0 + && path_fnamencmp(src, p, len) == 0 && (vim_ispathsep(src[len]) || (!one && (src[len] == ',' || src[len] == ' ')) || src[len] == NUL)) { -- cgit From 3ff46544c9872b4161fd098569c30b55fe3abd36 Mon Sep 17 00:00:00 2001 From: Dundar Göc Date: Fri, 26 Aug 2022 23:11:25 +0200 Subject: refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/os/env.c | 6 +++--- src/nvim/os/shell.c | 8 ++++---- src/nvim/os/users.c | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/env.c b/src/nvim/os/env.c index 34ed3aaf6e..bcc0fba8d0 100644 --- a/src/nvim/os/env.c +++ b/src/nvim/os/env.c @@ -451,7 +451,7 @@ void init_homedir(void) var = NULL; const char *exp = os_getenv(os_buf); if (exp != NULL && *exp != NUL - && STRLEN(exp) + STRLEN(p) < MAXPATHL) { + && strlen(exp) + strlen(p) < MAXPATHL) { vim_snprintf(os_buf, MAXPATHL, "%s%s", exp, p + 1); var = os_buf; } @@ -800,7 +800,7 @@ static char *vim_version_dir(const char *vimdir) /// @return The new pend including dirname or just pend static char *remove_tail(char *path, char *pend, char *dirname) { - size_t len = STRLEN(dirname); + size_t len = strlen(dirname); char *new_tail = pend - len - 1; if (new_tail >= path @@ -1146,7 +1146,7 @@ char *home_replace_save(buf_T *buf, const char *src) { size_t len = 3; // space for "~/" and trailing NUL if (src != NULL) { // just in case - len += STRLEN(src); + len += strlen(src); } char *dst = xmalloc(len); home_replace(buf, src, dst, len, true); diff --git a/src/nvim/os/shell.c b/src/nvim/os/shell.c index cf66899493..ca3e32e871 100644 --- a/src/nvim/os/shell.c +++ b/src/nvim/os/shell.c @@ -178,7 +178,7 @@ int os_expand_wildcards(int num_pat, char **pat, int *num_file, char ***file, in // STYLE_ECHO: space separated. // A shell we don't know, stay safe and use "echo". if (num_pat == 1 && *pat[0] == '`' - && (len = STRLEN(pat[0])) > 2 + && (len = strlen(pat[0])) > 2 && *(pat[0] + len - 1) == '`') { shell_style = STYLE_BT; } else if ((len = STRLEN(p_sh)) >= 3) { @@ -198,7 +198,7 @@ int os_expand_wildcards(int num_pat, char **pat, int *num_file, char ***file, in // Worst case: "unset nonomatch; print -N >" plus two is 29 len = STRLEN(tempname) + 29; if (shell_style == STYLE_VIMGLOB) { - len += STRLEN(sh_vimglob_func); + len += strlen(sh_vimglob_func); } for (i = 0; i < num_pat; i++) { @@ -519,7 +519,7 @@ int os_expand_wildcards(int num_pat, char **pat, int *num_file, char ***file, in continue; } - p = xmalloc(STRLEN((*file)[i]) + 1 + dir); + p = xmalloc(strlen((*file)[i]) + 1 + dir); STRCPY(p, (*file)[i]); if (dir) { add_pathsep((char *)p); // add '/' to a directory name @@ -1319,7 +1319,7 @@ static char *shell_xescape_xquote(const char *cmd) if (*p_sxe != NUL && strcmp(p_sxq, "(") == 0) { ecmd = (char *)vim_strsave_escaped_ext((char_u *)cmd, p_sxe, '^', false); } - size_t ncmd_size = strlen(ecmd) + STRLEN(p_sxq) * 2 + 1; + size_t ncmd_size = strlen(ecmd) + strlen(p_sxq) * 2 + 1; char *ncmd = xmalloc(ncmd_size); // When 'shellxquote' is ( append ). diff --git a/src/nvim/os/users.c b/src/nvim/os/users.c index 0c662e8843..7b0f3ddaed 100644 --- a/src/nvim/os/users.c +++ b/src/nvim/os/users.c @@ -210,7 +210,7 @@ char *get_users(expand_T *xp, int idx) /// 2 is name fully matches a user name. int match_user(char *name) { - int n = (int)STRLEN(name); + int n = (int)strlen(name); int result = 0; init_users(); -- cgit From 644a3f48b117abd1d0d0aab5ec96cd62392ca0f1 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 14 Sep 2022 19:49:55 +0800 Subject: fix(events): make CursorHold behave as documented --- src/nvim/os/input.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/input.c b/src/nvim/os/input.c index ea9f31d776..8fc4a5dce5 100644 --- a/src/nvim/os/input.c +++ b/src/nvim/os/input.c @@ -38,6 +38,8 @@ static RBuffer *input_buffer = NULL; static bool input_eof = false; static int global_fd = -1; static bool blocking = false; +static int cursorhold_time = 0; ///< time waiting for CursorHold event +static int cursorhold_tb_change_cnt = 0; ///< tb_change_cnt when waiting started #ifdef INCLUDE_GENERATED_DECLARATIONS # include "os/input.c.generated.h" @@ -97,13 +99,25 @@ static void create_cursorhold_event(bool events_enabled) multiqueue_put(main_loop.events, cursorhold_event, 0); } +static void restart_cursorhold_wait(int tb_change_cnt) +{ + cursorhold_time = 0; + cursorhold_tb_change_cnt = tb_change_cnt; +} + /// Low level input function /// /// wait until either the input buffer is non-empty or, if `events` is not NULL /// until `events` is non-empty. int os_inchar(uint8_t *buf, int maxlen, int ms, int tb_change_cnt, MultiQueue *events) { + // This check is needed so that feeding typeahead from RPC can prevent CursorHold. + if (tb_change_cnt != cursorhold_tb_change_cnt) { + restart_cursorhold_wait(tb_change_cnt); + } + if (maxlen && rbuffer_size(input_buffer)) { + restart_cursorhold_wait(tb_change_cnt); return (int)rbuffer_read(input_buffer, (char *)buf, (size_t)maxlen); } @@ -118,18 +132,23 @@ int os_inchar(uint8_t *buf, int maxlen, int ms, int tb_change_cnt, MultiQueue *e return 0; } } else { - if ((result = inbuf_poll((int)p_ut, events)) == kInputNone) { + uint64_t wait_start = os_hrtime(); + assert((int)p_ut >= cursorhold_time); + if ((result = inbuf_poll((int)p_ut - cursorhold_time, events)) == kInputNone) { if (read_stream.closed && silent_mode) { // Drained eventloop & initial input; exit silent/batch-mode (-es/-Es). read_error_exit(); } - + restart_cursorhold_wait(tb_change_cnt); if (trigger_cursorhold() && !typebuf_changed(tb_change_cnt)) { create_cursorhold_event(events == main_loop.events); } else { before_blocking(); result = inbuf_poll(-1, events); } + } else { + cursorhold_time += (int)((os_hrtime() - wait_start) / 1000000); + cursorhold_time = MIN(cursorhold_time, (int)p_ut); } } @@ -141,6 +160,7 @@ int os_inchar(uint8_t *buf, int maxlen, int ms, int tb_change_cnt, MultiQueue *e } if (maxlen && rbuffer_size(input_buffer)) { + restart_cursorhold_wait(tb_change_cnt); // Safe to convert rbuffer_read to int, it will never overflow since we use // relatively small buffers. return (int)rbuffer_read(input_buffer, (char *)buf, (size_t)maxlen); -- cgit From 6d557e324fd4223fff3279a0112f40431c540163 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sun, 18 Sep 2022 03:17:15 +0200 Subject: vim-patch:8.1.0941: macros for MS-Windows are inconsistent (#20215) Problem: Macros for MS-Windows are inconsistent, using "32", "3264 and others. Solution: Use MSWIN for all MS-Windows builds. Use FEAT_GUI_MSWIN for the GUI build. (Hirohito Higashi, closes vim/vim#3932) https://github.com/vim/vim/commit/4f97475d326c2773a78561fb874e4f23c25cbcd9 --- src/nvim/os/env.c | 24 ++++++++++++------------ src/nvim/os/fs.c | 18 +++++++++--------- src/nvim/os/os_defs.h | 4 ++-- src/nvim/os/process.c | 8 ++++---- src/nvim/os/pty_process.h | 2 +- src/nvim/os/signal.c | 4 ++-- src/nvim/os/stdpaths.c | 8 ++++---- src/nvim/os/tty.c | 2 +- src/nvim/os/users.c | 4 ++-- src/nvim/os/win_defs.h | 2 +- 10 files changed, 38 insertions(+), 38 deletions(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/env.c b/src/nvim/os/env.c index bcc0fba8d0..bd79b43574 100644 --- a/src/nvim/os/env.c +++ b/src/nvim/os/env.c @@ -20,7 +20,7 @@ #include "nvim/version.h" #include "nvim/vim.h" -#ifdef WIN32 +#ifdef MSWIN # include "nvim/mbyte.h" // for utf8_to_utf16, utf16_to_utf8 #endif @@ -128,7 +128,7 @@ int os_setenv(const char *name, const char *value, int overwrite) if (name[0] == '\0') { return -1; } -#ifdef WIN32 +#ifdef MSWIN if (!overwrite && os_getenv(name) != NULL) { return 0; } @@ -143,7 +143,7 @@ int os_setenv(const char *name, const char *value, int overwrite) #endif uv_mutex_lock(&mutex); int r; -#ifdef WIN32 +#ifdef MSWIN // libintl uses getenv() for LC_ALL/LANG/etc., so we must use _putenv_s(). if (striequal(name, "LC_ALL") || striequal(name, "LANGUAGE") || striequal(name, "LANG") || striequal(name, "LC_MESSAGES")) { @@ -186,7 +186,7 @@ int os_unsetenv(const char *name) size_t os_get_fullenv_size(void) { size_t len = 0; -#ifdef _WIN32 +#ifdef MSWIN wchar_t *envstrings = GetEnvironmentStringsW(); wchar_t *p = envstrings; size_t l; @@ -235,7 +235,7 @@ void os_free_fullenv(char **env) /// @param env_size size of `env`, @see os_fullenv_size void os_copy_fullenv(char **env, size_t env_size) { -#ifdef _WIN32 +#ifdef MSWIN wchar_t *envstrings = GetEnvironmentStringsW(); if (!envstrings) { return; @@ -280,7 +280,7 @@ void os_copy_fullenv(char **env, size_t env_size) /// @return [allocated] environment variable's value, or NULL char *os_getenvname_at_index(size_t index) { -#ifdef _WIN32 +#ifdef MSWIN wchar_t *envstrings = GetEnvironmentStringsW(); if (!envstrings) { return NULL; @@ -347,7 +347,7 @@ char *os_getenvname_at_index(size_t index) /// @return the process ID. int64_t os_get_pid(void) { -#ifdef _WIN32 +#ifdef MSWIN return (int64_t)GetCurrentProcessId(); #else return (int64_t)getpid(); @@ -368,7 +368,7 @@ void os_get_hostname(char *hostname, size_t size) } else { xstrlcpy(hostname, vutsname.nodename, size); } -#elif defined(WIN32) +#elif defined(MSWIN) wchar_t host_utf16[MAX_COMPUTERNAME_LENGTH + 1]; DWORD host_wsize = sizeof(host_utf16) / sizeof(host_utf16[0]); if (GetComputerNameW(host_utf16, &host_wsize) == 0) { @@ -418,7 +418,7 @@ void init_homedir(void) const char *var = os_getenv("HOME"); -#ifdef WIN32 +#ifdef MSWIN // Typically, $HOME is not defined on Windows, unless the user has // specifically defined it for Vim's sake. However, on Windows NT // platforms, $HOMEDRIVE and $HOMEPATH are automatically defined for @@ -900,7 +900,7 @@ char *vim_getenv(const char *name) // init_path() should have been called before now. assert(get_vim_var_str(VV_PROGPATH)[0] != NUL); -#ifdef WIN32 +#ifdef MSWIN if (strcmp(name, "HOME") == 0) { return xstrdup(homedir); } @@ -1056,7 +1056,7 @@ size_t home_replace(const buf_T *const buf, const char *src, char *const dst, si } const char *homedir_env = os_getenv("HOME"); -#ifdef WIN32 +#ifdef MSWIN if (homedir_env == NULL) { homedir_env = os_getenv("USERPROFILE"); } @@ -1174,7 +1174,7 @@ char *get_env_name(expand_T *xp, int idx) bool os_setenv_append_path(const char *fname) FUNC_ATTR_NONNULL_ALL { -#ifdef WIN32 +#ifdef MSWIN // 8191 (plus NUL) is considered the practical maximum. # define MAX_ENVPATHLEN 8192 #else diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c index 158c22efaf..68e96eea6e 100644 --- a/src/nvim/os/fs.c +++ b/src/nvim/os/fs.c @@ -27,7 +27,7 @@ #include "nvim/path.h" #include "nvim/strings.h" -#ifdef WIN32 +#ifdef MSWIN # include "nvim/mbyte.h" // for utf8_to_utf16, utf16_to_utf8 #endif @@ -151,7 +151,7 @@ bool os_isdir(const char *name) int os_nodetype(const char *name) FUNC_ATTR_NONNULL_ALL { -#ifndef WIN32 // Unix +#ifndef MSWIN // Unix uv_stat_t statbuf; if (0 != os_stat(name, &statbuf)) { return NODE_NORMAL; // File doesn't exist. @@ -241,7 +241,7 @@ bool os_can_exe(const char *name, char **abspath, bool use_path) FUNC_ATTR_NONNULL_ARG(1) { if (!use_path || gettail_dir(name) != name) { -#ifdef WIN32 +#ifdef MSWIN if (is_executable_ext(name, abspath)) { #else // Must have path separator, cannot execute files in the current directory. @@ -270,7 +270,7 @@ static bool is_executable(const char *name, char **abspath) return false; } -#ifdef WIN32 +#ifdef MSWIN // Windows does not have exec bit; just check if the file exists and is not // a directory. const bool ok = S_ISREG(mode); @@ -287,7 +287,7 @@ static bool is_executable(const char *name, char **abspath) return ok; } -#ifdef WIN32 +#ifdef MSWIN /// 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 @@ -351,7 +351,7 @@ static bool is_executable_in_path(const char *name, char **abspath) return false; } -#ifdef WIN32 +#ifdef MSWIN // Prepend ".;" to $PATH. size_t pathlen = strlen(path_env); char *path = memcpy(xmallocz(pathlen + 2), "." ENV_SEPSTR, 2); @@ -374,7 +374,7 @@ static bool is_executable_in_path(const char *name, char **abspath) STRLCPY(buf, p, e - p + 1); append_path(buf, name, buf_len); -#ifdef WIN32 +#ifdef MSWIN if (is_executable_ext(buf, abspath)) { #else if (is_executable(buf, abspath)) { @@ -446,7 +446,7 @@ FILE *os_fopen(const char *path, const char *flags) default: abort(); } -#ifdef WIN32 +#ifdef MSWIN if (flags[1] == 'b') { iflags |= O_BINARY; } @@ -1208,7 +1208,7 @@ char *os_realpath(const char *name, char *buf) return result == kLibuvSuccess ? buf : NULL; } -#ifdef WIN32 +#ifdef MSWIN # include /// When "fname" is the name of a shortcut (*.lnk) resolve the file it points diff --git a/src/nvim/os/os_defs.h b/src/nvim/os/os_defs.h index a4361859ec..a30e16eeba 100644 --- a/src/nvim/os/os_defs.h +++ b/src/nvim/os/os_defs.h @@ -7,7 +7,7 @@ #include #include -#ifdef WIN32 +#ifdef MSWIN # include "nvim/os/win_defs.h" #else # include "nvim/os/unix_defs.h" @@ -43,7 +43,7 @@ /// Converts system error code to libuv error code. #define os_translate_sys_error uv_translate_sys_error -#ifdef WIN32 +#ifdef MSWIN # define os_strtok strtok_s #else # define os_strtok strtok_r diff --git a/src/nvim/os/process.c b/src/nvim/os/process.c index e70bc71961..28aea08595 100644 --- a/src/nvim/os/process.c +++ b/src/nvim/os/process.c @@ -8,7 +8,7 @@ #include // for HANDLE (win32) -#ifdef WIN32 +#ifdef MSWIN # include // for CreateToolhelp32Snapshot #endif @@ -38,7 +38,7 @@ # include "os/process.c.generated.h" #endif -#ifdef WIN32 +#ifdef MSWIN static bool os_proc_tree_kill_rec(HANDLE process, int sig) { if (process == NULL) { @@ -114,7 +114,7 @@ int os_proc_children(int ppid, int **proc_list, size_t *proc_count) *proc_list = NULL; *proc_count = 0; -#ifdef WIN32 +#ifdef MSWIN PROCESSENTRY32 pe; // Snapshot of all processes. @@ -215,7 +215,7 @@ int os_proc_children(int ppid, int **proc_list, size_t *proc_count) return 0; } -#ifdef WIN32 +#ifdef MSWIN /// Gets various properties of the process identified by `pid`. /// /// @param pid Process to inspect. diff --git a/src/nvim/os/pty_process.h b/src/nvim/os/pty_process.h index 94923499ca..07d346be22 100644 --- a/src/nvim/os/pty_process.h +++ b/src/nvim/os/pty_process.h @@ -1,7 +1,7 @@ #ifndef NVIM_OS_PTY_PROCESS_H #define NVIM_OS_PTY_PROCESS_H -#ifdef WIN32 +#ifdef MSWIN # include "nvim/os/pty_process_win.h" #else # include "nvim/os/pty_process_unix.h" diff --git a/src/nvim/os/signal.c b/src/nvim/os/signal.c index e592570966..9aa8d8051b 100644 --- a/src/nvim/os/signal.c +++ b/src/nvim/os/signal.c @@ -4,7 +4,7 @@ #include #include #include -#ifndef WIN32 +#ifndef MSWIN # include // for sigset_t #endif @@ -34,7 +34,7 @@ static bool rejecting_deadly; void signal_init(void) { -#ifndef WIN32 +#ifndef MSWIN // Ensure a clean slate by unblocking all signals. For example, if SIGCHLD is // blocked, libuv may hang after spawning a subprocess on Linux. #5230 sigset_t mask; diff --git a/src/nvim/os/stdpaths.c b/src/nvim/os/stdpaths.c index 59d315d44c..31d85ac2eb 100644 --- a/src/nvim/os/stdpaths.c +++ b/src/nvim/os/stdpaths.c @@ -21,7 +21,7 @@ static const char *xdg_env_vars[] = { [kXDGDataDirs] = "XDG_DATA_DIRS", }; -#ifdef WIN32 +#ifdef MSWIN static const char *const xdg_defaults_env_vars[] = { [kXDGConfigHome] = "LOCALAPPDATA", [kXDGDataHome] = "LOCALAPPDATA", @@ -37,7 +37,7 @@ static const char *const xdg_defaults_env_vars[] = { /// /// Used in case environment variables contain nothing. Need to be expanded. static const char *const xdg_defaults[] = { -#ifdef WIN32 +#ifdef MSWIN [kXDGConfigHome] = "~\\AppData\\Local", [kXDGDataHome] = "~\\AppData\\Local", [kXDGCacheHome] = "~\\AppData\\Local\\Temp", @@ -69,7 +69,7 @@ char *stdpaths_get_xdg_var(const XDGVarType idx) const char *env_val = os_getenv(env); -#ifdef WIN32 +#ifdef MSWIN if (env_val == NULL && xdg_defaults_env_vars[idx] != NULL) { env_val = os_getenv(xdg_defaults_env_vars[idx]); } @@ -107,7 +107,7 @@ char *get_xdg_home(const XDGVarType idx) { char *dir = stdpaths_get_xdg_var(idx); if (dir) { -#if defined(WIN32) +#if defined(MSWIN) dir = concat_fnames_realloc(dir, ((idx == kXDGDataHome || idx == kXDGStateHome) ? "nvim-data" : "nvim"), diff --git a/src/nvim/os/tty.c b/src/nvim/os/tty.c index 126b1b0044..1b15613a93 100644 --- a/src/nvim/os/tty.c +++ b/src/nvim/os/tty.c @@ -12,7 +12,7 @@ # include "os/tty.c.generated.h" #endif -#ifdef WIN32 +#ifdef MSWIN # if !defined(ENABLE_VIRTUAL_TERMINAL_PROCESSING) # define ENABLE_VIRTUAL_TERMINAL_PROCESSING 0x0004 # endif diff --git a/src/nvim/os/users.c b/src/nvim/os/users.c index 7b0f3ddaed..33e6563c4c 100644 --- a/src/nvim/os/users.c +++ b/src/nvim/os/users.c @@ -14,7 +14,7 @@ #ifdef HAVE_PWD_H # include #endif -#ifdef WIN32 +#ifdef MSWIN # include #endif @@ -56,7 +56,7 @@ int os_get_usernames(garray_T *users) } endpwent(); } -#elif defined(WIN32) +#elif defined(MSWIN) { DWORD nusers = 0, ntotal = 0, i; PUSER_INFO_0 uinfo; diff --git a/src/nvim/os/win_defs.h b/src/nvim/os/win_defs.h index 1ae86d6bbe..4f8a242a51 100644 --- a/src/nvim/os/win_defs.h +++ b/src/nvim/os/win_defs.h @@ -1,7 +1,7 @@ #ifndef NVIM_OS_WIN_DEFS_H #define NVIM_OS_WIN_DEFS_H -#ifndef WIN32 +#ifndef MSWIN # error Header must be included only when compiling for Windows. #endif -- cgit From 647da34bbd4cf19a4bcc11899df24e00d6b8fcbe Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 18 Sep 2022 22:55:30 +0800 Subject: fix: assert failure when changing 'ut' while waiting for CursorHold (#20241) --- src/nvim/os/input.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/input.c b/src/nvim/os/input.c index 8fc4a5dce5..fc7390a303 100644 --- a/src/nvim/os/input.c +++ b/src/nvim/os/input.c @@ -133,7 +133,7 @@ int os_inchar(uint8_t *buf, int maxlen, int ms, int tb_change_cnt, MultiQueue *e } } else { uint64_t wait_start = os_hrtime(); - assert((int)p_ut >= cursorhold_time); + cursorhold_time = MIN(cursorhold_time, (int)p_ut); if ((result = inbuf_poll((int)p_ut - cursorhold_time, events)) == kInputNone) { if (read_stream.closed && silent_mode) { // Drained eventloop & initial input; exit silent/batch-mode (-es/-Es). @@ -148,7 +148,6 @@ int os_inchar(uint8_t *buf, int maxlen, int ms, int tb_change_cnt, MultiQueue *e } } else { cursorhold_time += (int)((os_hrtime() - wait_start) / 1000000); - cursorhold_time = MIN(cursorhold_time, (int)p_ut); } } -- cgit From 8317b9199edc6936fec829f4908f9c74dc874ce4 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 24 Sep 2022 22:28:41 +0800 Subject: fix(input): use click number of last click for mouse drag (#20300) --- src/nvim/os/input.c | 48 +++++++++++++++++++++++------------------------- 1 file changed, 23 insertions(+), 25 deletions(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/input.c b/src/nvim/os/input.c index fc7390a303..cb0dba8cac 100644 --- a/src/nvim/os/input.c +++ b/src/nvim/os/input.c @@ -306,37 +306,35 @@ static uint8_t check_multiclick(int code, int grid, int row, int col) static int orig_mouse_row = 0; static uint64_t orig_mouse_time = 0; // time of previous mouse click - if (code == KE_LEFTRELEASE - || code == KE_RIGHTRELEASE - || code == KE_MIDDLERELEASE - || code == KE_MOUSEDOWN - || code == KE_MOUSEUP - || code == KE_MOUSELEFT - || code == KE_MOUSERIGHT - || code == KE_MOUSEMOVE) { + if ((code >= KE_MOUSEDOWN && code <= KE_MOUSERIGHT) || code == KE_MOUSEMOVE) { return 0; } - uint64_t mouse_time = os_hrtime(); // time of current mouse click (ns) - - // compute the time elapsed since the previous mouse click and - // convert p_mouse from ms to ns - uint64_t timediff = mouse_time - orig_mouse_time; - uint64_t mouset = (uint64_t)p_mouset * 1000000; - if (code == orig_mouse_code - && timediff < mouset - && orig_num_clicks != 4 - && orig_mouse_grid == grid - && orig_mouse_col == col - && orig_mouse_row == row) { - orig_num_clicks++; - } else { - orig_num_clicks = 1; + + // For click events the number of clicks is updated. + if (code == KE_LEFTMOUSE || code == KE_RIGHTMOUSE || code == KE_MIDDLEMOUSE) { + uint64_t mouse_time = os_hrtime(); // time of current mouse click (ns) + // compute the time elapsed since the previous mouse click and + // convert p_mouse from ms to ns + uint64_t timediff = mouse_time - orig_mouse_time; + uint64_t mouset = (uint64_t)p_mouset * 1000000; + if (code == orig_mouse_code + && timediff < mouset + && orig_num_clicks != 4 + && orig_mouse_grid == grid + && orig_mouse_col == col + && orig_mouse_row == row) { + orig_num_clicks++; + } else { + orig_num_clicks = 1; + } + orig_mouse_code = code; + orig_mouse_time = mouse_time; } - orig_mouse_code = code; + // For drag and release events the number of clicks is kept. + orig_mouse_grid = grid; orig_mouse_col = col; orig_mouse_row = row; - orig_mouse_time = mouse_time; uint8_t modifiers = 0; if (orig_num_clicks == 2) { -- cgit From 91e912f8d40284c74d4a997c8c95961eebb35d91 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sun, 25 Sep 2022 15:26:37 +0200 Subject: refactor: move klib out of src/nvim/ #20341 It's confusing to mix vendored dependencies with neovim source code. A clean separation is simpler to keep track of and simpler to document. --- src/nvim/os/pty_conpty_win.h | 2 +- src/nvim/os/pty_process_unix.c | 2 +- src/nvim/os/shell.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/pty_conpty_win.h b/src/nvim/os/pty_conpty_win.h index 15e7c3da0c..0c25a5970e 100644 --- a/src/nvim/os/pty_conpty_win.h +++ b/src/nvim/os/pty_conpty_win.h @@ -1,7 +1,7 @@ #ifndef NVIM_OS_PTY_CONPTY_WIN_H #define NVIM_OS_PTY_CONPTY_WIN_H -#include "nvim/lib/kvec.h" +#include "klib/kvec.h" #include "nvim/os/input.h" #ifndef HPCON diff --git a/src/nvim/os/pty_process_unix.c b/src/nvim/os/pty_process_unix.c index c5d6af0ff6..0b7af87267 100644 --- a/src/nvim/os/pty_process_unix.c +++ b/src/nvim/os/pty_process_unix.c @@ -31,11 +31,11 @@ #include +#include "klib/klist.h" #include "nvim/event/loop.h" #include "nvim/event/process.h" #include "nvim/event/rstream.h" #include "nvim/event/wstream.h" -#include "nvim/lib/klist.h" #include "nvim/log.h" #include "nvim/os/os.h" #include "nvim/os/pty_process_unix.h" diff --git a/src/nvim/os/shell.c b/src/nvim/os/shell.c index ca3e32e871..9766c8f3d9 100644 --- a/src/nvim/os/shell.c +++ b/src/nvim/os/shell.c @@ -7,6 +7,7 @@ #include #include +#include "klib/kvec.h" #include "nvim/ascii.h" #include "nvim/charset.h" #include "nvim/eval.h" @@ -15,7 +16,6 @@ #include "nvim/event/rstream.h" #include "nvim/ex_cmds.h" #include "nvim/fileio.h" -#include "nvim/lib/kvec.h" #include "nvim/log.h" #include "nvim/main.h" #include "nvim/memline.h" -- cgit From df646572c53f55268a5dbb61628d7c3b302d5663 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Fri, 30 Sep 2022 09:53:52 +0200 Subject: docs: fix typos (#20394) Co-authored-by: Raphael Co-authored-by: smjonas Co-authored-by: zeertzjq --- src/nvim/os/shell.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/shell.c b/src/nvim/os/shell.c index 9766c8f3d9..750d2f342f 100644 --- a/src/nvim/os/shell.c +++ b/src/nvim/os/shell.c @@ -805,7 +805,7 @@ done: /// char *output = NULL; /// size_t nread = 0; /// char *argv[] = {"ls", "-la", NULL}; -/// int exitcode = os_sytem(argv, NULL, 0, &output, &nread); +/// int exitcode = os_system(argv, NULL, 0, &output, &nread); /// /// @param argv The commandline arguments to be passed to the shell. `argv` /// will be consumed. -- cgit From 1ca3a3749f4addb175f96f41fa0fb210e1fa297d Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Thu, 13 Oct 2022 15:25:23 +0200 Subject: refactor(windows): move os_icon_xx functions --- src/nvim/os/os_win_console.c | 47 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'src/nvim/os') diff --git a/src/nvim/os/os_win_console.c b/src/nvim/os/os_win_console.c index 20b7f869f1..ec0f03a1dc 100644 --- a/src/nvim/os/os_win_console.c +++ b/src/nvim/os/os_win_console.c @@ -2,6 +2,7 @@ // it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com #include "nvim/os/input.h" +#include "nvim/os/os.h" #include "nvim/os/os_win_console.h" #include "nvim/vim.h" @@ -9,6 +10,10 @@ # include "os/os_win_console.c.generated.h" #endif +static HWND hWnd = NULL; +static HICON hOrigIconSmall = NULL; +static HICON hOrigIcon = NULL; + int os_get_conin_fd(void) { const HANDLE conin_handle = CreateFile("CONIN$", @@ -45,3 +50,45 @@ void os_replace_stdout_and_stderr_to_conout(void) const int conerr_fd = _open_osfhandle((intptr_t)conout_handle, 0); assert(conerr_fd == STDERR_FILENO); } + +/// Sets Windows console icon, or pass NULL to restore original icon. +void os_icon_set(HICON hIconSmall, HICON hIcon) +{ + if (hWnd == NULL) { + return; + } + hIconSmall = hIconSmall ? hIconSmall : hOrigIconSmall; + hIcon = hIcon ? hIcon : hOrigIcon; + + if (hIconSmall != NULL) { + SendMessage(hWnd, WM_SETICON, (WPARAM)ICON_SMALL, (LPARAM)hIconSmall); + } + if (hIcon != NULL) { + SendMessage(hWnd, WM_SETICON, (WPARAM)ICON_BIG, (LPARAM)hIcon); + } +} + +/// Sets Nvim logo as Windows console icon. +/// +/// Saves the original icon so it can be restored at exit. +void os_icon_init(void) +{ + if ((hWnd = GetConsoleWindow()) == NULL) { + return; + } + // Save Windows console icon to be restored later. + hOrigIconSmall = (HICON)SendMessage(hWnd, WM_GETICON, (WPARAM)ICON_SMALL, (LPARAM)0); + hOrigIcon = (HICON)SendMessage(hWnd, WM_GETICON, (WPARAM)ICON_BIG, (LPARAM)0); + + const char *vimruntime = os_getenv("VIMRUNTIME"); + if (vimruntime != NULL) { + snprintf(NameBuff, MAXPATHL, "%s" _PATHSEPSTR "neovim.ico", vimruntime); + if (!os_path_exists(NameBuff)) { + WLOG("neovim.ico not found: %s", NameBuff); + } else { + HICON hVimIcon = LoadImage(NULL, NameBuff, IMAGE_ICON, 64, 64, + LR_LOADFROMFILE | LR_LOADMAP3DCOLORS); + os_icon_set(hVimIcon, hVimIcon); + } + } +} -- cgit From 784e498c4a9c1f03266ced5ec3f55c3a6c94b80d Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Fri, 21 Oct 2022 14:47:44 +0200 Subject: refactor: clang-tidy fixes to silence clangd warning (#20683) * refactor: readability-uppercase-literal-suffix * refactor: readability-named-parameter * refactor: bugprone-suspicious-string-compare * refactor: google-readability-casting * refactor: readability-redundant-control-flow * refactor: bugprone-too-small-loop-variable * refactor: readability-non-const-parameter * refactor: readability-avoid-const-params-in-decls * refactor: google-readability-todo * refactor: readability-inconsistent-declaration-parameter-name * refactor: bugprone-suspicious-missing-comma * refactor: remove noisy or slow warnings --- src/nvim/os/fileio.h | 4 ++-- src/nvim/os/time.c | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/fileio.h b/src/nvim/os/fileio.h index 426dc422c2..da23a54c4e 100644 --- a/src/nvim/os/fileio.h +++ b/src/nvim/os/fileio.h @@ -37,7 +37,7 @@ typedef enum { ///< EAGAIN was encountered. } FileOpenFlags; -static inline bool file_eof(const FileDescriptor *const fp) +static inline bool file_eof(const FileDescriptor *fp) REAL_FATTR_PURE REAL_FATTR_WARN_UNUSED_RESULT REAL_FATTR_NONNULL_ALL; /// Check whether end of file was encountered @@ -51,7 +51,7 @@ static inline bool file_eof(const FileDescriptor *const fp) return fp->eof && rbuffer_size(fp->rv) == 0; } -static inline int file_fd(const FileDescriptor *const fp) +static inline int file_fd(const FileDescriptor *fp) REAL_FATTR_PURE REAL_FATTR_WARN_UNUSED_RESULT REAL_FATTR_NONNULL_ALL; /// Return the file descriptor associated with the FileDescriptor structure diff --git a/src/nvim/os/time.c b/src/nvim/os/time.c index 396bf6986a..161c8d28b8 100644 --- a/src/nvim/os/time.c +++ b/src/nvim/os/time.c @@ -67,7 +67,7 @@ void os_delay(uint64_t ms, bool ignoreinput) } LOOP_PROCESS_EVENTS_UNTIL(&main_loop, NULL, (int)ms, got_int); } else { - os_microdelay(ms * 1000u, ignoreinput); + os_microdelay(ms * 1000U, ignoreinput); } } @@ -80,10 +80,10 @@ void os_delay(uint64_t ms, bool ignoreinput) /// If false, waiting is aborted on any input. void os_microdelay(uint64_t us, bool ignoreinput) { - uint64_t elapsed = 0u; + uint64_t elapsed = 0U; uint64_t base = uv_hrtime(); // Convert microseconds to nanoseconds, or UINT64_MAX on overflow. - const uint64_t ns = (us < UINT64_MAX / 1000u) ? us * 1000u : UINT64_MAX; + const uint64_t ns = (us < UINT64_MAX / 1000U) ? us * 1000U : UINT64_MAX; uv_mutex_lock(&delay_mutex); @@ -92,7 +92,7 @@ void os_microdelay(uint64_t us, bool ignoreinput) // Else we check for input in ~100ms intervals. const uint64_t ns_delta = ignoreinput ? ns - elapsed - : MIN(ns - elapsed, 100000000u); // 100ms + : MIN(ns - elapsed, 100000000U); // 100ms const int rv = uv_cond_timedwait(&delay_cond, &delay_mutex, ns_delta); if (0 != rv && UV_ETIMEDOUT != rv) { -- cgit From a7d100f052b45a106d1385ed419509c047c12431 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 30 Oct 2022 06:49:39 +0800 Subject: fix: avoid unsigned overflow in home_replace() (#20854) --- src/nvim/os/env.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/nvim/os') diff --git a/src/nvim/os/env.c b/src/nvim/os/env.c index bd79b43574..faafc546a4 100644 --- a/src/nvim/os/env.c +++ b/src/nvim/os/env.c @@ -1119,10 +1119,16 @@ size_t home_replace(const buf_T *const buf, const char *src, char *const dst, si len = envlen; } + if (dstlen == 0) { + break; // Avoid overflowing below. + } // if (!one) skip to separator: space or comma. while (*src && (one || (*src != ',' && *src != ' ')) && --dstlen > 0) { *dst_p++ = *src++; } + if (dstlen == 0) { + break; // Avoid overflowing below. + } // Skip separator. while ((*src == ' ' || *src == ',') && --dstlen > 0) { *dst_p++ = *src++; -- cgit From 731cdde28ea8d48cc23ba2752a08c261c87eee92 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sat, 22 Oct 2022 12:36:38 +0200 Subject: refactor: fix clang-tidy warnings Enable and fix bugprone-misplaced-widening-cast warning. Fix some modernize-macro-to-enum and readability-else-after-return warnings, but don't enable them. While the warnings can be useful, they are in general too noisy to enable. --- src/nvim/os/env.c | 12 +++++------- src/nvim/os/fs.c | 9 +++------ src/nvim/os/input.c | 3 +-- 3 files changed, 9 insertions(+), 15 deletions(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/env.c b/src/nvim/os/env.c index faafc546a4..ca6bff662d 100644 --- a/src/nvim/os/env.c +++ b/src/nvim/os/env.c @@ -837,10 +837,9 @@ const void *vim_env_iter(const char delim, const char *const val, const void *co if (dirend == NULL) { *len = strlen(varval); return NULL; - } else { - *len = (size_t)(dirend - varval); - return dirend + 1; } + *len = (size_t)(dirend - varval); + return dirend + 1; } /// Iterates $PATH-like delimited list `val` in reverse order. @@ -870,11 +869,10 @@ const void *vim_env_iter_rev(const char delim, const char *const val, const void *len = varlen; *dir = val; return NULL; - } else { - *dir = colon + 1; - *len = (size_t)(varend - colon); - return colon - 1; } + *dir = colon + 1; + *len = (size_t)(varend - colon); + return colon - 1; } /// @param[out] exe_name should be at least MAXPATHL in size diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c index 68e96eea6e..2a0018da9c 100644 --- a/src/nvim/os/fs.c +++ b/src/nvim/os/fs.c @@ -121,9 +121,8 @@ bool os_isrealdir(const char *name) fs_loop_unlock(); if (S_ISLNK(request.statbuf.st_mode)) { return false; - } else { - return S_ISDIR(request.statbuf.st_mode); } + return S_ISDIR(request.statbuf.st_mode); } /// Check if the given path exists and is a directory. @@ -249,9 +248,8 @@ bool os_can_exe(const char *name, char **abspath, bool use_path) && is_executable(name, abspath)) { #endif return true; - } else { - return false; } + return false; } return is_executable_in_path(name, abspath); @@ -756,9 +754,8 @@ int32_t os_getperm(const char *name) int stat_result = os_stat(name, &statbuf); if (stat_result == kLibuvSuccess) { return (int32_t)statbuf.st_mode; - } else { - return stat_result; } + return stat_result; } /// Set the permission of a file. diff --git a/src/nvim/os/input.c b/src/nvim/os/input.c index cb0dba8cac..f8c1ee57ea 100644 --- a/src/nvim/os/input.c +++ b/src/nvim/os/input.c @@ -469,9 +469,8 @@ static InbufPollResult inbuf_poll(int ms, MultiQueue *events) if (input_ready(events)) { return kInputAvail; - } else { - return input_eof ? kInputEof : kInputNone; } + return input_eof ? kInputEof : kInputNone; } void input_done(void) -- cgit From 8045296e8b6d10611a5fce2db0b9b90a1989100c Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 7 Nov 2022 09:08:25 +0800 Subject: fix(stdpath): default to /tmp if stdpath('run') cannot be created #20952 Fix #20949 --- src/nvim/os/stdpaths.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/nvim/os') diff --git a/src/nvim/os/stdpaths.c b/src/nvim/os/stdpaths.c index 31d85ac2eb..2aaf776fc6 100644 --- a/src/nvim/os/stdpaths.c +++ b/src/nvim/os/stdpaths.c @@ -87,6 +87,9 @@ char *stdpaths_get_xdg_var(const XDGVarType idx) } else if (idx == kXDGRuntimeDir) { // Special-case: stdpath('run') is defined at startup. ret = vim_gettempdir(); + if (ret == NULL) { + ret = "/tmp/"; + } size_t len = strlen(ret); ret = xstrndup(ret, len >= 2 ? len - 1 : 0); // Trim trailing slash. } -- cgit From d337814906b1377e34aa2c2dfd8aa16285328692 Mon Sep 17 00:00:00 2001 From: Victor Blanchard <48864055+Viblanc@users.noreply.github.com> Date: Mon, 7 Nov 2022 04:31:50 +0100 Subject: feat: ":write ++p" creates parent dirs #20835 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - `:write ++p foo/bar/baz.txt` should create parent directories `foo/bar/` if they do not exist - Note: `:foo ++…` is usually for options. No existing options have a single-char abbreviation (presumably by design), so it's safe to special-case `++p` here. - Same for `writefile(…, 'foo/bar/baz.txt', 'p')` - `BufWriteCmd` can see the ++p flag via `v:cmdarg`. closes #19884 --- src/nvim/os/fileio.c | 8 ++++++++ src/nvim/os/fileio.h | 1 + src/nvim/os/fs.c | 31 +++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+) (limited to 'src/nvim/os') diff --git a/src/nvim/os/fileio.c b/src/nvim/os/fileio.c index b1710737d0..280a9c2bee 100644 --- a/src/nvim/os/fileio.c +++ b/src/nvim/os/fileio.c @@ -71,6 +71,7 @@ int file_open(FileDescriptor *const ret_fp, const char *const fname, const int f FLAG(flags, kFileReadOnly, O_RDONLY, kFalse, wr != kTrue); #ifdef O_NOFOLLOW FLAG(flags, kFileNoSymlink, O_NOFOLLOW, kNone, true); + FLAG(flags, kFileMkDir, O_CREAT|O_WRONLY, kTrue, !(flags & kFileCreateOnly)); #endif #undef FLAG // wr is used for kFileReadOnly flag, but on @@ -78,6 +79,13 @@ int file_open(FileDescriptor *const ret_fp, const char *const fname, const int f // `error: variable ‘wr’ set but not used [-Werror=unused-but-set-variable]` (void)wr; + if (flags & kFileMkDir) { + int mkdir_ret = os_file_mkdir((char *)fname, 0755); + if (mkdir_ret < 0) { + return mkdir_ret; + } + } + const int fd = os_open(fname, os_open_flags, mode); if (fd < 0) { diff --git a/src/nvim/os/fileio.h b/src/nvim/os/fileio.h index da23a54c4e..5e47bbf921 100644 --- a/src/nvim/os/fileio.h +++ b/src/nvim/os/fileio.h @@ -35,6 +35,7 @@ typedef enum { ///< be used with kFileCreateOnly. kFileNonBlocking = 128, ///< Do not restart read() or write() syscall if ///< EAGAIN was encountered. + kFileMkDir = 256, } FileOpenFlags; static inline bool file_eof(const FileDescriptor *fp) diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c index 68e96eea6e..3c9578979e 100644 --- a/src/nvim/os/fs.c +++ b/src/nvim/os/fs.c @@ -946,6 +946,37 @@ int os_mkdir_recurse(const char *const dir, int32_t mode, char **const failed_di return 0; } +/// Create the parent directory of a file if it does not exist +/// +/// @param[in] fname Full path of the file name whose parent directories +/// we want to create +/// @param[in] mode Permissions for the newly-created directory. +/// +/// @return `0` for success, libuv error code for failure. +int os_file_mkdir(char *fname, int32_t mode) + FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT +{ + if (!dir_of_file_exists((char_u *)fname)) { + char *tail = path_tail_with_sep(fname); + char *last_char = tail + strlen(tail) - 1; + if (vim_ispathsep(*last_char)) { + emsg(_(e_noname)); + return -1; + } + char c = *tail; + *tail = NUL; + int r; + char *failed_dir; + if ((r = os_mkdir_recurse(fname, mode, &failed_dir) < 0)) { + semsg(_(e_mkdir), failed_dir, os_strerror(r)); + xfree(failed_dir); + } + *tail = c; + return r; + } + return 0; +} + /// Create a unique temporary directory. /// /// @param[in] template Template of the path to the directory with XXXXXX -- cgit From 2755510f7800ff675a5fbe2cfaa59459ff3ab6b2 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sat, 12 Nov 2022 13:34:14 +0100 Subject: ci(windows): treat compiler warnings as errors Reduce the warning level from 3 to 1 and fix all warnings. --- src/nvim/os/pty_conpty_win.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/pty_conpty_win.c b/src/nvim/os/pty_conpty_win.c index f9478d951f..43c89f8865 100644 --- a/src/nvim/os/pty_conpty_win.c +++ b/src/nvim/os/pty_conpty_win.c @@ -67,7 +67,7 @@ conpty_t *os_conpty_init(char **in_name, char **out_name, uint16_t width, uint16 | PIPE_ACCESS_OUTBOUND | FILE_FLAG_FIRST_PIPE_INSTANCE; sa.nLength = sizeof(sa); - snprintf(buf, sizeof(buf), "\\\\.\\pipe\\nvim-term-in-%d-%d", + snprintf(buf, sizeof(buf), "\\\\.\\pipe\\nvim-term-in-%lld-%d", os_get_pid(), count); *in_name = xstrdup(buf); if ((in_read = CreateNamedPipeA(*in_name, @@ -81,7 +81,7 @@ conpty_t *os_conpty_init(char **in_name, char **out_name, uint16_t width, uint16 emsg = "create input pipe failed"; goto failed; } - snprintf(buf, sizeof(buf), "\\\\.\\pipe\\nvim-term-out-%d-%d", + snprintf(buf, sizeof(buf), "\\\\.\\pipe\\nvim-term-out-%lld-%d", os_get_pid(), count); *out_name = xstrdup(buf); if ((out_write = CreateNamedPipeA(*out_name, -- cgit From 66360675cf4d091b7460e4a8e1435c13216c1929 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sun, 11 Sep 2022 17:12:44 +0200 Subject: build: allow IWYU to fix includes for all .c files Allow Include What You Use to remove unnecessary includes and only include what is necessary. This helps with reducing compilation times and makes it easier to visualise which dependencies are actually required. Work on https://github.com/neovim/neovim/issues/549, but doesn't close it since this only works fully for .c files and not headers. --- src/nvim/os/dl.c | 3 ++- src/nvim/os/env.c | 13 +++++++++++++ src/nvim/os/fileio.c | 13 +++++-------- src/nvim/os/fs.c | 20 +++++++++++++++----- src/nvim/os/fs.h | 4 ++-- src/nvim/os/input.c | 16 ++++++++++++---- src/nvim/os/lang.c | 10 +++++----- src/nvim/os/mem.c | 1 + src/nvim/os/process.c | 24 ++++++++++++++---------- src/nvim/os/pty_process_unix.c | 15 ++++++++++----- src/nvim/os/pty_process_unix.h | 2 ++ src/nvim/os/shell.c | 21 ++++++++++++++++++--- src/nvim/os/signal.c | 7 ++----- src/nvim/os/stdpaths.c | 1 + src/nvim/os/time.c | 18 +++++++++++++++--- src/nvim/os/tty.c | 4 ++-- src/nvim/os/unix_defs.h | 3 +++ src/nvim/os/users.c | 6 +++++- 18 files changed, 127 insertions(+), 54 deletions(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/dl.c b/src/nvim/os/dl.c index 7d095d31e3..519cef7876 100644 --- a/src/nvim/os/dl.c +++ b/src/nvim/os/dl.c @@ -4,13 +4,14 @@ /// Functions for using external native libraries #include +#include #include #include +#include "nvim/gettext.h" #include "nvim/memory.h" #include "nvim/message.h" #include "nvim/os/dl.h" -#include "nvim/os/os.h" /// possible function prototypes that can be called by os_libcall() /// int -> int diff --git a/src/nvim/os/env.c b/src/nvim/os/env.c index ca6bff662d..8f58f5217e 100644 --- a/src/nvim/os/env.c +++ b/src/nvim/os/env.c @@ -4,19 +4,32 @@ // Environment inspection #include +#include +#include +#include +#include +#include #include +#include "auto/config.h" #include "nvim/ascii.h" +#include "nvim/buffer_defs.h" #include "nvim/charset.h" #include "nvim/cmdexpand.h" #include "nvim/eval.h" +#include "nvim/ex_cmds_defs.h" +#include "nvim/gettext.h" +#include "nvim/globals.h" +#include "nvim/log.h" #include "nvim/macros.h" #include "nvim/map.h" #include "nvim/memory.h" #include "nvim/message.h" +#include "nvim/option_defs.h" #include "nvim/os/os.h" #include "nvim/path.h" #include "nvim/strings.h" +#include "nvim/types.h" #include "nvim/version.h" #include "nvim/vim.h" diff --git a/src/nvim/os/fileio.c b/src/nvim/os/fileio.c index 280a9c2bee..bdea82f1ff 100644 --- a/src/nvim/os/fileio.c +++ b/src/nvim/os/fileio.c @@ -11,22 +11,19 @@ #include #include #include - -#include "auto/config.h" - -#ifdef HAVE_SYS_UIO_H -# include -#endif - +#include #include -#include "nvim/globals.h" +#include "auto/config.h" +#include "nvim/gettext.h" #include "nvim/macros.h" #include "nvim/memory.h" #include "nvim/message.h" #include "nvim/os/fileio.h" #include "nvim/os/os.h" +#include "nvim/os/os_defs.h" #include "nvim/rbuffer.h" +#include "nvim/types.h" #ifdef INCLUDE_GENERATED_DECLARATIONS # include "os/fileio.c.generated.h" diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c index 0cadabbb47..2ae0a81e3d 100644 --- a/src/nvim/os/fs.c +++ b/src/nvim/os/fs.c @@ -5,11 +5,23 @@ #include #include #include -#include #include #include +#include +#include +#include +#include +#include #include "auto/config.h" +#include "nvim/gettext.h" +#include "nvim/globals.h" +#include "nvim/log.h" +#include "nvim/macros.h" +#include "nvim/option_defs.h" +#include "nvim/os/fs_defs.h" +#include "nvim/types.h" +#include "nvim/vim.h" #ifdef HAVE_SYS_UIO_H # include @@ -18,14 +30,12 @@ #include #include "nvim/ascii.h" -#include "nvim/assert.h" #include "nvim/memory.h" #include "nvim/message.h" -#include "nvim/option.h" #include "nvim/os/os.h" -#include "nvim/os/os_defs.h" #include "nvim/path.h" -#include "nvim/strings.h" + +struct iovec; #ifdef MSWIN # include "nvim/mbyte.h" // for utf8_to_utf16, utf16_to_utf8 diff --git a/src/nvim/os/fs.h b/src/nvim/os/fs.h index c68081da02..75c24b8db2 100644 --- a/src/nvim/os/fs.h +++ b/src/nvim/os/fs.h @@ -1,8 +1,8 @@ #ifndef NVIM_OS_FS_H #define NVIM_OS_FS_H -#include "nvim/os/fs_defs.h" // for uv_* -#include "nvim/types.h" // for char_u +#include "nvim/os/fs_defs.h" +#include "nvim/types.h" #ifdef INCLUDE_GENERATED_DECLARATIONS # include "os/fs.h.generated.h" diff --git a/src/nvim/os/input.c b/src/nvim/os/input.c index f8c1ee57ea..d6afb1b62a 100644 --- a/src/nvim/os/input.c +++ b/src/nvim/os/input.c @@ -3,25 +3,33 @@ #include #include +#include +#include #include #include #include "nvim/api/private/defs.h" #include "nvim/ascii.h" #include "nvim/autocmd.h" +#include "nvim/buffer_defs.h" #include "nvim/event/loop.h" +#include "nvim/event/multiqueue.h" #include "nvim/event/rstream.h" +#include "nvim/event/stream.h" #include "nvim/getchar.h" +#include "nvim/gettext.h" +#include "nvim/globals.h" #include "nvim/keycodes.h" +#include "nvim/log.h" +#include "nvim/macros.h" #include "nvim/main.h" -#include "nvim/mbyte.h" -#include "nvim/memory.h" #include "nvim/msgpack_rpc/channel.h" +#include "nvim/option_defs.h" #include "nvim/os/input.h" +#include "nvim/os/time.h" #include "nvim/profile.h" -#include "nvim/screen.h" +#include "nvim/rbuffer.h" #include "nvim/state.h" -#include "nvim/ui.h" #include "nvim/vim.h" #define READ_BUFFER_SIZE 0xfff diff --git a/src/nvim/os/lang.c b/src/nvim/os/lang.c index 28f43ff3af..57c82bba86 100644 --- a/src/nvim/os/lang.c +++ b/src/nvim/os/lang.c @@ -7,16 +7,16 @@ # include # undef Boolean # undef FileInfo -#endif -#include "auto/config.h" +# include "auto/config.h" +# ifdef HAVE_LOCALE_H +# include +# endif +# include "nvim/os/os.h" -#ifdef HAVE_LOCALE_H -# include #endif #include "nvim/os/lang.h" -#include "nvim/os/os.h" void lang_init(void) { diff --git a/src/nvim/os/mem.c b/src/nvim/os/mem.c index eccb3c97e5..0b7e8065ef 100644 --- a/src/nvim/os/mem.c +++ b/src/nvim/os/mem.c @@ -3,6 +3,7 @@ /// Functions for accessing system memory information. +#include #include #include "nvim/os/os.h" diff --git a/src/nvim/os/process.c b/src/nvim/os/process.c index 28aea08595..d9273e69da 100644 --- a/src/nvim/os/process.c +++ b/src/nvim/os/process.c @@ -6,10 +6,21 @@ /// psutil is a good reference for cross-platform syscall voodoo: /// https://github.com/giampaolo/psutil/tree/master/psutil/arch -#include // for HANDLE (win32) +#include +#include +#include +#include +#include +#include + +#include "nvim/log.h" +#include "nvim/memory.h" +#include "nvim/os/process.h" #ifdef MSWIN -# include // for CreateToolhelp32Snapshot +# include + +# include "nvim/api/private/helpers.h" #endif #if defined(__FreeBSD__) // XXX: OpenBSD ? @@ -27,15 +38,8 @@ # include #endif -#include "nvim/api/private/helpers.h" -#include "nvim/globals.h" -#include "nvim/log.h" -#include "nvim/os/os.h" -#include "nvim/os/os_defs.h" -#include "nvim/os/process.h" - #ifdef INCLUDE_GENERATED_DECLARATIONS -# include "os/process.c.generated.h" +# include "os/process.c.generated.h" // IWYU pragma: export #endif #ifdef MSWIN diff --git a/src/nvim/os/pty_process_unix.c b/src/nvim/os/pty_process_unix.c index 0b7af87267..143f0b3900 100644 --- a/src/nvim/os/pty_process_unix.c +++ b/src/nvim/os/pty_process_unix.c @@ -2,13 +2,15 @@ // it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com // Some of the code came from pangoterm and libuv -#include + +#include +#include +#include +#include #include #include #include -#include #include -#include // forkpty is not in POSIX, so headers are platform-specific #if defined(__FreeBSD__) || defined(__DragonFly__) @@ -31,13 +33,16 @@ #include +#include "auto/config.h" #include "klib/klist.h" +#include "nvim/eval/typval.h" #include "nvim/event/loop.h" #include "nvim/event/process.h" -#include "nvim/event/rstream.h" -#include "nvim/event/wstream.h" +#include "nvim/event/stream.h" #include "nvim/log.h" #include "nvim/os/os.h" +#include "nvim/os/os_defs.h" +#include "nvim/os/pty_process.h" #include "nvim/os/pty_process_unix.h" #ifdef INCLUDE_GENERATED_DECLARATIONS diff --git a/src/nvim/os/pty_process_unix.h b/src/nvim/os/pty_process_unix.h index 765490b92b..0cc68cf3e9 100644 --- a/src/nvim/os/pty_process_unix.h +++ b/src/nvim/os/pty_process_unix.h @@ -1,8 +1,10 @@ #ifndef NVIM_OS_PTY_PROCESS_UNIX_H #define NVIM_OS_PTY_PROCESS_UNIX_H +#include #include +#include "nvim/event/loop.h" #include "nvim/event/process.h" typedef struct pty_process { diff --git a/src/nvim/os/shell.c b/src/nvim/os/shell.c index 750d2f342f..b4bee6e550 100644 --- a/src/nvim/os/shell.c +++ b/src/nvim/os/shell.c @@ -3,30 +3,45 @@ #include #include -#include +#include +#include #include #include +#include "auto/config.h" #include "klib/kvec.h" #include "nvim/ascii.h" +#include "nvim/buffer_defs.h" #include "nvim/charset.h" #include "nvim/eval.h" +#include "nvim/eval/typval_defs.h" #include "nvim/event/libuv_process.h" #include "nvim/event/loop.h" +#include "nvim/event/multiqueue.h" +#include "nvim/event/process.h" #include "nvim/event/rstream.h" +#include "nvim/event/stream.h" +#include "nvim/event/wstream.h" #include "nvim/ex_cmds.h" #include "nvim/fileio.h" -#include "nvim/log.h" +#include "nvim/gettext.h" +#include "nvim/globals.h" +#include "nvim/macros.h" #include "nvim/main.h" +#include "nvim/mbyte.h" #include "nvim/memline.h" #include "nvim/memory.h" #include "nvim/message.h" #include "nvim/option_defs.h" +#include "nvim/os/fs.h" +#include "nvim/os/os_defs.h" #include "nvim/os/shell.h" #include "nvim/os/signal.h" +#include "nvim/os/time.h" #include "nvim/path.h" +#include "nvim/pos.h" #include "nvim/profile.h" -#include "nvim/screen.h" +#include "nvim/rbuffer.h" #include "nvim/strings.h" #include "nvim/tag.h" #include "nvim/types.h" diff --git a/src/nvim/os/signal.c b/src/nvim/os/signal.c index 9aa8d8051b..08d24d47e2 100644 --- a/src/nvim/os/signal.c +++ b/src/nvim/os/signal.c @@ -3,23 +3,20 @@ #include #include -#include +#include #ifndef MSWIN # include // for sigset_t #endif -#include "nvim/ascii.h" #include "nvim/autocmd.h" +#include "nvim/buffer_defs.h" #include "nvim/eval.h" -#include "nvim/event/loop.h" #include "nvim/event/signal.h" #include "nvim/globals.h" #include "nvim/log.h" #include "nvim/main.h" #include "nvim/memline.h" -#include "nvim/memory.h" #include "nvim/os/signal.h" -#include "nvim/vim.h" static SignalWatcher spipe, shup, squit, sterm, susr1, swinch; #ifdef SIGPWR diff --git a/src/nvim/os/stdpaths.c b/src/nvim/os/stdpaths.c index 2aaf776fc6..a99a8d25ce 100644 --- a/src/nvim/os/stdpaths.c +++ b/src/nvim/os/stdpaths.c @@ -2,6 +2,7 @@ // it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com #include +#include #include "nvim/ascii.h" #include "nvim/fileio.h" diff --git a/src/nvim/os/time.c b/src/nvim/os/time.c index 161c8d28b8..7ba2bd155e 100644 --- a/src/nvim/os/time.c +++ b/src/nvim/os/time.c @@ -1,22 +1,34 @@ // This is an open source non-commercial project. Dear PVS-Studio, please check // it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com -#include +#include #include +#include +#include +#include +#include + #include -#include "nvim/assert.h" +#include "auto/config.h" #include "nvim/event/loop.h" +#include "nvim/gettext.h" +#include "nvim/globals.h" +#include "nvim/log.h" +#include "nvim/macros.h" #include "nvim/main.h" +#include "nvim/memory.h" #include "nvim/os/input.h" #include "nvim/os/os.h" #include "nvim/os/time.h" +struct tm; + static uv_mutex_t delay_mutex; static uv_cond_t delay_cond; #ifdef INCLUDE_GENERATED_DECLARATIONS -# include "os/time.c.generated.h" +# include "os/time.c.generated.h" // IWYU pragma: export #endif /// Initializes the time module diff --git a/src/nvim/os/tty.c b/src/nvim/os/tty.c index 1b15613a93..b5124bd83a 100644 --- a/src/nvim/os/tty.c +++ b/src/nvim/os/tty.c @@ -5,11 +5,11 @@ // Terminal/console utils // -#include "nvim/os/os.h" +#include "nvim/os/os.h" // IWYU pragma: keep (Windows) #include "nvim/os/tty.h" #ifdef INCLUDE_GENERATED_DECLARATIONS -# include "os/tty.c.generated.h" +# include "os/tty.c.generated.h" // IWYU pragma: export #endif #ifdef MSWIN diff --git a/src/nvim/os/unix_defs.h b/src/nvim/os/unix_defs.h index 4ed3b51694..8d002fc5e9 100644 --- a/src/nvim/os/unix_defs.h +++ b/src/nvim/os/unix_defs.h @@ -3,6 +3,9 @@ #include #include +#if defined(HAVE_TERMIOS_H) +# include +#endif // POSIX.1-2008 says that NAME_MAX should be in here #include diff --git a/src/nvim/os/users.c b/src/nvim/os/users.c index 33e6563c4c..1865d6789e 100644 --- a/src/nvim/os/users.c +++ b/src/nvim/os/users.c @@ -3,6 +3,9 @@ // users.c -- operating system user information +#include +#include +#include #include #include "auto/config.h" @@ -10,7 +13,8 @@ #include "nvim/garray.h" #include "nvim/memory.h" #include "nvim/os/os.h" -#include "nvim/strings.h" +#include "nvim/types.h" +#include "nvim/vim.h" #ifdef HAVE_PWD_H # include #endif -- cgit From a8489308ab00f51bff197f29e76276b16ad0d985 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 17 Nov 2022 18:41:07 +0800 Subject: vim-patch:8.2.3041: detecting if the process of a swap file is running fails Problem: Detecting if the process of a swap file is running fails if the process is owned by another user. Solution: Check for the ESRCH error. (closes vim/vim#8436) https://github.com/vim/vim/commit/44dea9da4b2a21dd1e03f2bd94b4f2679d4613e5 Co-authored-by: Bram Moolenaar --- src/nvim/os/process.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/process.c b/src/nvim/os/process.c index d9273e69da..f4d95e141b 100644 --- a/src/nvim/os/process.c +++ b/src/nvim/os/process.c @@ -264,5 +264,16 @@ Dictionary os_proc_info(int pid) /// Return true if process `pid` is running. bool os_proc_running(int pid) { - return uv_kill(pid, 0) == 0; + int err = uv_kill(pid, 0); + // If there is no error the process must be running. + if (err == 0) { + return true; + } + // If the error is ESRCH then the process is not running. + if (err == UV_ESRCH) { + return false; + } + // If the process is running and owned by another user we get EPERM. With + // other errors the process might be running, assuming it is then. + return true; } -- cgit From 40f3f75867bf03abfd90e0389a38197a00d37af1 Mon Sep 17 00:00:00 2001 From: Dundar Göc Date: Fri, 26 Aug 2022 23:11:25 +0200 Subject: refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/os/env.c | 58 ++++++++++++++++++++++++++--------------------------- src/nvim/os/shell.c | 44 ++++++++++++++++++++-------------------- 2 files changed, 51 insertions(+), 51 deletions(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/env.c b/src/nvim/os/env.c index 8f58f5217e..dac3cae199 100644 --- a/src/nvim/os/env.c +++ b/src/nvim/os/env.c @@ -554,7 +554,7 @@ char *expand_env_save(char *src) char_u *expand_env_save_opt(char_u *src, bool one) { char_u *p = xmalloc(MAXPATHL); - expand_env_esc(src, p, MAXPATHL, false, one, NULL); + expand_env_esc((char *)src, (char *)p, MAXPATHL, false, one, NULL); return p; } @@ -568,7 +568,7 @@ char_u *expand_env_save_opt(char_u *src, bool one) /// @param dstlen Maximum length of the result void expand_env(char *src, char *dst, int dstlen) { - expand_env_esc((char_u *)src, (char_u *)dst, dstlen, false, false, NULL); + expand_env_esc(src, dst, dstlen, false, false, NULL); } /// Expand environment variable with path name and escaping. @@ -580,34 +580,34 @@ void expand_env(char *src, char *dst, int dstlen) /// @param esc Escape spaces in expanded variables /// @param one `srcp` is a single filename /// @param prefix Start again after this (can be NULL) -void expand_env_esc(char_u *restrict srcp, char_u *restrict dst, int dstlen, bool esc, bool one, - char_u *prefix) +void expand_env_esc(char *restrict srcp, char *restrict dst, int dstlen, bool esc, bool one, + char *prefix) FUNC_ATTR_NONNULL_ARG(1, 2) { - char_u *tail; - char_u *var; + char *tail; + char *var; bool copy_char; bool mustfree; // var was allocated, need to free it later bool at_start = true; // at start of a name - int prefix_len = (prefix == NULL) ? 0 : (int)STRLEN(prefix); + int prefix_len = (prefix == NULL) ? 0 : (int)strlen(prefix); - char *src = skipwhite((char *)srcp); + char *src = skipwhite(srcp); dstlen--; // leave one char space for "\," while (*src && dstlen > 0) { // Skip over `=expr`. if (src[0] == '`' && src[1] == '=') { - var = (char_u *)src; + var = src; src += 2; (void)skip_expr(&src); if (*src == '`') { src++; } - size_t len = (size_t)(src - (char *)var); + size_t len = (size_t)(src - var); if (len > (size_t)dstlen) { len = (size_t)dstlen; } - memcpy((char *)dst, (char *)var, len); + memcpy(dst, var, len); dst += len; dstlen -= (int)len; continue; @@ -620,7 +620,7 @@ void expand_env_esc(char_u *restrict srcp, char_u *restrict dst, int dstlen, boo // The variable name is copied into dst temporarily, because it may // be a string in read-only memory and a NUL needs to be appended. if (*src != '~') { // environment var - tail = (char_u *)src + 1; + tail = src + 1; var = dst; int c = dstlen - 1; @@ -649,7 +649,7 @@ void expand_env_esc(char_u *restrict srcp, char_u *restrict dst, int dstlen, boo } #endif *var = NUL; - var = (char_u *)vim_getenv((char *)dst); + var = vim_getenv(dst); mustfree = true; #if defined(UNIX) } @@ -657,12 +657,12 @@ void expand_env_esc(char_u *restrict srcp, char_u *restrict dst, int dstlen, boo } else if (src[1] == NUL // home directory || vim_ispathsep(src[1]) || vim_strchr(" ,\t\n", src[1]) != NULL) { - var = (char_u *)homedir; - tail = (char_u *)src + 1; + var = homedir; + tail = src + 1; } else { // user directory #if defined(UNIX) // Copy ~user to dst[], so we can put a NUL after it. - tail = (char_u *)src; + tail = src; var = dst; int c = dstlen - 1; while (c-- > 0 @@ -675,15 +675,15 @@ void expand_env_esc(char_u *restrict srcp, char_u *restrict dst, int dstlen, boo // Get the user directory. If this fails the shell is used to expand // ~user, which is slower and may fail on old versions of /bin/sh. var = (*dst == NUL) ? NULL - : (char_u *)os_get_userdir((char *)dst + 1); + : os_get_userdir(dst + 1); mustfree = true; if (var == NULL) { expand_T xpc; ExpandInit(&xpc); xpc.xp_context = EXPAND_FILES; - var = (char_u *)ExpandOne(&xpc, (char *)dst, NULL, - WILD_ADD_SLASH|WILD_SILENT, WILD_EXPAND_FREE); + var = ExpandOne(&xpc, dst, NULL, + WILD_ADD_SLASH|WILD_SILENT, WILD_EXPAND_FREE); mustfree = true; } #else @@ -710,8 +710,8 @@ void expand_env_esc(char_u *restrict srcp, char_u *restrict dst, int dstlen, boo // If "var" contains white space, escape it with a backslash. // Required for ":e ~/tt" when $HOME includes a space. - if (esc && var != NULL && strpbrk((char *)var, " \t") != NULL) { - char_u *p = vim_strsave_escaped(var, (char_u *)" \t"); + if (esc && var != NULL && strpbrk(var, " \t") != NULL) { + char *p = (char *)vim_strsave_escaped((char_u *)var, (char_u *)" \t"); if (mustfree) { xfree(var); @@ -721,13 +721,13 @@ void expand_env_esc(char_u *restrict srcp, char_u *restrict dst, int dstlen, boo } if (var != NULL && *var != NUL - && (STRLEN(var) + STRLEN(tail) + 1 < (unsigned)dstlen)) { + && (strlen(var) + strlen(tail) + 1 < (unsigned)dstlen)) { STRCPY(dst, var); - dstlen -= (int)STRLEN(var); - int c = (int)STRLEN(var); + dstlen -= (int)strlen(var); + int c = (int)strlen(var); // if var[] ends in a path separator and tail[] starts // with it, skip a character - if (after_pathsep((char *)dst, (char *)dst + c) + if (after_pathsep(dst, dst + c) #if defined(BACKSLASH_IN_FILENAME) && dst[-1] != ':' #endif @@ -735,7 +735,7 @@ void expand_env_esc(char_u *restrict srcp, char_u *restrict dst, int dstlen, boo tail++; } dst += c; - src = (char *)tail; + src = tail; copy_char = false; } if (mustfree) { @@ -749,17 +749,17 @@ void expand_env_esc(char_u *restrict srcp, char_u *restrict dst, int dstlen, boo // ":edit foo ~ foo". at_start = false; if (src[0] == '\\' && src[1] != NUL) { - *dst++ = (char_u)(*src++); + *dst++ = *src++; dstlen--; } else if ((src[0] == ' ' || src[0] == ',') && !one) { at_start = true; } if (dstlen > 0) { - *dst++ = (char_u)(*src++); + *dst++ = *src++; dstlen--; if (prefix != NULL - && src - prefix_len >= (char *)srcp + && src - prefix_len >= srcp && STRNCMP(src - prefix_len, prefix, prefix_len) == 0) { at_start = true; } diff --git a/src/nvim/os/shell.c b/src/nvim/os/shell.c index b4bee6e550..c1359d6ece 100644 --- a/src/nvim/os/shell.c +++ b/src/nvim/os/shell.c @@ -120,15 +120,15 @@ int os_expand_wildcards(int num_pat, char **pat, int *num_file, char ***file, in { int i; size_t len; - char_u *p; + char *p; bool dir; char_u *extra_shell_arg = NULL; ShellOpts shellopts = kShellOptExpand | kShellOptSilent; int j; - char_u *tempname; - char_u *command; + char *tempname; + char *command; FILE *fd; - char_u *buffer; + char *buffer; #define STYLE_ECHO 0 // use "echo", the default #define STYLE_GLOB 1 // use "glob", for csh #define STYLE_VIMGLOB 2 // use "vimglob", for Posix sh @@ -175,7 +175,7 @@ int os_expand_wildcards(int num_pat, char **pat, int *num_file, char ***file, in } // get a name for the temp file - if ((tempname = (char_u *)vim_tempname()) == NULL) { + if ((tempname = vim_tempname()) == NULL) { emsg(_(e_notmp)); return FAIL; } @@ -196,7 +196,7 @@ int os_expand_wildcards(int num_pat, char **pat, int *num_file, char ***file, in && (len = strlen(pat[0])) > 2 && *(pat[0] + len - 1) == '`') { shell_style = STYLE_BT; - } else if ((len = STRLEN(p_sh)) >= 3) { + } else if ((len = strlen(p_sh)) >= 3) { if (strcmp(p_sh + len - 3, "csh") == 0) { shell_style = STYLE_GLOB; } else if (strcmp(p_sh + len - 3, "zsh") == 0) { @@ -211,7 +211,7 @@ int os_expand_wildcards(int num_pat, char **pat, int *num_file, char ***file, in // Compute the length of the command. We need 2 extra bytes: for the // optional '&' and for the NUL. // Worst case: "unset nonomatch; print -N >" plus two is 29 - len = STRLEN(tempname) + 29; + len = strlen(tempname) + 29; if (shell_style == STYLE_VIMGLOB) { len += strlen(sh_vimglob_func); } @@ -248,7 +248,7 @@ int os_expand_wildcards(int num_pat, char **pat, int *num_file, char ***file, in STRCPY(command, "("); } STRCAT(command, pat[0] + 1); // exclude first backtick - p = command + STRLEN(command) - 1; + p = command + strlen(command) - 1; if (is_fish_shell) { *p-- = ';'; STRCAT(command, " end"); @@ -294,7 +294,7 @@ int os_expand_wildcards(int num_pat, char **pat, int *num_file, char ***file, in // characters, except inside ``. bool intick = false; - p = command + STRLEN(command); + p = command + strlen(command); *p++ = ' '; for (j = 0; pat[i][j] != NUL; j++) { if (pat[i][j] == '`') { @@ -319,7 +319,7 @@ int os_expand_wildcards(int num_pat, char **pat, int *num_file, char ***file, in } // Copy one character. - *p++ = (char_u)pat[i][j]; + *p++ = pat[i][j]; } *p = NUL; } @@ -347,7 +347,7 @@ int os_expand_wildcards(int num_pat, char **pat, int *num_file, char ***file, in } // execute the shell command - i = call_shell(command, shellopts, extra_shell_arg); + i = call_shell((char_u *)command, shellopts, extra_shell_arg); // When running in the background, give it some time to create the temp // file, but don't wait for it to finish. @@ -358,7 +358,7 @@ int os_expand_wildcards(int num_pat, char **pat, int *num_file, char ***file, in xfree(command); if (i) { // os_call_shell() failed - os_remove((char *)tempname); + os_remove(tempname); xfree(tempname); // With interactive completion, the error message is not printed. if (!(flags & EW_SILENT)) { @@ -377,7 +377,7 @@ int os_expand_wildcards(int num_pat, char **pat, int *num_file, char ***file, in } // read the names from the file into memory - fd = fopen((char *)tempname, READBIN); + fd = fopen(tempname, READBIN); if (fd == NULL) { // Something went wrong, perhaps a file name with a special char. if (!(flags & EW_SILENT)) { @@ -407,9 +407,9 @@ int os_expand_wildcards(int num_pat, char **pat, int *num_file, char ***file, in buffer = xmalloc(len + 1); // fread() doesn't terminate buffer with NUL; // appropriate termination (not always NUL) is done below. - size_t readlen = fread((char *)buffer, 1, len, fd); + size_t readlen = fread(buffer, 1, len, fd); fclose(fd); - os_remove((char *)tempname); + os_remove(tempname); if (readlen != len) { // unexpected read error semsg(_(e_notread), tempname); @@ -427,7 +427,7 @@ int os_expand_wildcards(int num_pat, char **pat, int *num_file, char ***file, in while (*p != ' ' && *p != '\n') { p++; } - p = (char_u *)skipwhite((char *)p); // skip to next entry + p = skipwhite(p); // skip to next entry } // file names are separated with NL } else if (shell_style == STYLE_BT || shell_style == STYLE_VIMGLOB) { @@ -440,7 +440,7 @@ int os_expand_wildcards(int num_pat, char **pat, int *num_file, char ***file, in if (*p != NUL) { p++; } - p = (char_u *)skipwhite((char *)p); // skip leading white space + p = skipwhite(p); // skip leading white space } // file names are separated with NUL } else { @@ -454,7 +454,7 @@ int os_expand_wildcards(int num_pat, char **pat, int *num_file, char ***file, in if (shell_style == STYLE_PRINT && !did_find_nul) { // If there is a NUL, set did_find_nul, else set check_spaces buffer[len] = NUL; - if (len && (int)STRLEN(buffer) < (int)len) { + if (len && (int)strlen(buffer) < (int)len) { did_find_nul = true; } else { check_spaces = true; @@ -493,7 +493,7 @@ int os_expand_wildcards(int num_pat, char **pat, int *num_file, char ***file, in // Isolate the individual file names. p = buffer; for (i = 0; i < *num_file; i++) { - (*file)[i] = (char *)p; + (*file)[i] = p; // Space or NL separates if (shell_style == STYLE_ECHO || shell_style == STYLE_BT || shell_style == STYLE_VIMGLOB) { @@ -505,7 +505,7 @@ int os_expand_wildcards(int num_pat, char **pat, int *num_file, char ***file, in *p = NUL; } else { *p++ = NUL; - p = (char_u *)skipwhite((char *)p); // skip to next entry + p = skipwhite(p); // skip to next entry } } else { // NUL separates while (*p && p < buffer + len) { // skip entry @@ -537,9 +537,9 @@ int os_expand_wildcards(int num_pat, char **pat, int *num_file, char ***file, in p = xmalloc(strlen((*file)[i]) + 1 + dir); STRCPY(p, (*file)[i]); if (dir) { - add_pathsep((char *)p); // add '/' to a directory name + add_pathsep(p); // add '/' to a directory name } - (*file)[j++] = (char *)p; + (*file)[j++] = p; } xfree(buffer); *num_file = j; -- cgit From 0cbc23d3cc327109176c0a9c0f8a48fc5196a6cd Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Tue, 22 Nov 2022 01:07:45 +0100 Subject: fix: pvs warnings (#21145) * fix(PVS/V009): start file with special comment * fix(PVS/V501): identical sub-expressions for comparison * fix(PVS/V560): part of conditional expression is always true/false * fix(PVS/V593): review expression of type A = B < C * fix(PVS/V614): potentially uninitialized variable used --- src/nvim/os/fs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c index 2ae0a81e3d..d694025bc2 100644 --- a/src/nvim/os/fs.c +++ b/src/nvim/os/fs.c @@ -974,7 +974,7 @@ int os_file_mkdir(char *fname, int32_t mode) *tail = NUL; int r; char *failed_dir; - if ((r = os_mkdir_recurse(fname, mode, &failed_dir) < 0)) { + if (((r = os_mkdir_recurse(fname, mode, &failed_dir)) < 0)) { semsg(_(e_mkdir), failed_dir, os_strerror(r)); xfree(failed_dir); } -- cgit From c2a9c64d231ff234a32189996ed88a8c91c0c046 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 25 Nov 2022 11:34:59 +0800 Subject: vim-patch:8.2.4155: translating strftime() argument results in check error Problem: Translating strftime() argument results in check error. Solution: Add gettext comment. https://github.com/vim/vim/commit/7e93577a957e4f402bb690c4c8629fd831e24a9d Co-authored-by: Bram Moolenaar --- src/nvim/os/time.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/os') diff --git a/src/nvim/os/time.c b/src/nvim/os/time.c index 7ba2bd155e..7fc43d7991 100644 --- a/src/nvim/os/time.c +++ b/src/nvim/os/time.c @@ -188,6 +188,7 @@ char *os_ctime_r(const time_t *restrict clock, char *restrict result, size_t res if (clock_local_ptr == NULL) { xstrlcpy(result, _("(Invalid)"), result_len); } else { + // xgettext:no-c-format strftime(result, result_len, _("%a %b %d %H:%M:%S %Y"), clock_local_ptr); } xstrlcat(result, "\n", result_len); -- cgit From 3b96ccf7d35be90e49029dec76344d3d92ad91dc Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sat, 26 Nov 2022 18:57:46 +0100 Subject: refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/os/env.c | 2 +- src/nvim/os/fs.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/env.c b/src/nvim/os/env.c index dac3cae199..29bfbfcfdf 100644 --- a/src/nvim/os/env.c +++ b/src/nvim/os/env.c @@ -760,7 +760,7 @@ void expand_env_esc(char *restrict srcp, char *restrict dst, int dstlen, bool es if (prefix != NULL && src - prefix_len >= srcp - && STRNCMP(src - prefix_len, prefix, prefix_len) == 0) { + && strncmp(src - prefix_len, prefix, (size_t)prefix_len) == 0) { at_start = true; } } diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c index d694025bc2..8c4fee58b1 100644 --- a/src/nvim/os/fs.c +++ b/src/nvim/os/fs.c @@ -180,7 +180,7 @@ int os_nodetype(const char *name) // Edge case from Vim os_win32.c: // We can't open a file with a name "\\.\con" or "\\.\prn", trying to read // from it later will cause Vim to hang. Thus return NODE_WRITABLE here. - if (STRNCMP(name, "\\\\.\\", 4) == 0) { + if (strncmp(name, "\\\\.\\", 4) == 0) { return NODE_WRITABLE; } -- cgit From 7328c4de54ac96b39853b3f43736aff863fd209d Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 29 Nov 2022 11:18:15 +0800 Subject: vim-patch:9.0.0733: use of strftime() is not safe (#21228) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem: Use of strftime() is not safe. Solution: Check the return value of strftime(). Use a larger buffer and correctly pass the available space. (Dominique Pellé, closes vim/vim#11348) https://github.com/vim/vim/commit/84d14ccdb50dc9f362066a2c83bfaf331314e5ea Co-authored-by: Dominique Pelle --- src/nvim/os/time.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/time.c b/src/nvim/os/time.c index 7fc43d7991..360565fbc5 100644 --- a/src/nvim/os/time.c +++ b/src/nvim/os/time.c @@ -186,10 +186,16 @@ char *os_ctime_r(const time_t *restrict clock, char *restrict result, size_t res struct tm *clock_local_ptr = os_localtime_r(clock, &clock_local); // MSVC returns NULL for an invalid value of seconds. if (clock_local_ptr == NULL) { - xstrlcpy(result, _("(Invalid)"), result_len); + xstrlcpy(result, _("(Invalid)"), result_len - 1); } else { // xgettext:no-c-format - strftime(result, result_len, _("%a %b %d %H:%M:%S %Y"), clock_local_ptr); + if (strftime(result, result_len - 1, _("%a %b %d %H:%M:%S %Y"), clock_local_ptr) == 0) { + // Quoting "man strftime": + // > If the length of the result string (including the terminating + // > null byte) would exceed max bytes, then strftime() returns 0, + // > and the contents of the array are undefined. + xstrlcpy(result, _("(Invalid)"), result_len - 1); + } } xstrlcat(result, "\n", result_len); return result; -- cgit From 98695b49992daa2b40eb3d5b5e4a86e99c92ed0e Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 29 Nov 2022 11:48:06 +0800 Subject: vim-patch:8.1.1313: warnings for using localtime() and ctime() (#21229) Problem: Warnings for using localtime() and ctime(). Solution: Use localtime_r() if available. Avoid using ctime(). https://github.com/vim/vim/commit/63d2555c9cefbbeeca3ec87fdd5d241e9488f9dd Co-authored-by: Bram Moolenaar --- src/nvim/os/time.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/time.c b/src/nvim/os/time.c index 360565fbc5..873302a27d 100644 --- a/src/nvim/os/time.c +++ b/src/nvim/os/time.c @@ -179,7 +179,8 @@ struct tm *os_localtime(struct tm *result) FUNC_ATTR_NONNULL_ALL /// @param result[out] Pointer to a 'char' where the result should be placed /// @param result_len length of result buffer /// @return human-readable string of current local time -char *os_ctime_r(const time_t *restrict clock, char *restrict result, size_t result_len) +char *os_ctime_r(const time_t *restrict clock, char *restrict result, size_t result_len, + bool add_newline) FUNC_ATTR_NONNULL_ALL FUNC_ATTR_NONNULL_RET { struct tm clock_local; @@ -197,7 +198,9 @@ char *os_ctime_r(const time_t *restrict clock, char *restrict result, size_t res xstrlcpy(result, _("(Invalid)"), result_len - 1); } } - xstrlcat(result, "\n", result_len); + if (add_newline) { + xstrlcat(result, "\n", result_len); + } return result; } @@ -206,11 +209,11 @@ char *os_ctime_r(const time_t *restrict clock, char *restrict result, size_t res /// @param result[out] Pointer to a 'char' where the result should be placed /// @param result_len length of result buffer /// @return human-readable string of current local time -char *os_ctime(char *result, size_t result_len) +char *os_ctime(char *result, size_t result_len, bool add_newline) FUNC_ATTR_NONNULL_ALL FUNC_ATTR_NONNULL_RET { time_t rawtime = time(NULL); - return os_ctime_r(&rawtime, result, result_len); + return os_ctime_r(&rawtime, result, result_len, add_newline); } /// Portable version of POSIX strptime() -- cgit From ec1738a6ed08dd3a89fd07950fa2dcc55a72b705 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Wed, 21 Dec 2022 12:00:05 +0100 Subject: refactor: replace char_u with char 16 - remove STRNCMP (#21208) refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/os/input.c | 2 +- src/nvim/os/shell.c | 2 +- src/nvim/os/users.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/input.c b/src/nvim/os/input.c index d6afb1b62a..5d2ac1e102 100644 --- a/src/nvim/os/input.c +++ b/src/nvim/os/input.c @@ -266,7 +266,7 @@ size_t input_enqueue(String keys) uint8_t buf[19] = { 0 }; // Do not simplify the keys here. Simplification will be done later. unsigned int new_size - = trans_special((const uint8_t **)&ptr, (size_t)(end - ptr), buf, FSK_KEYCODE, true, NULL); + = trans_special((const char **)&ptr, (size_t)(end - ptr), buf, FSK_KEYCODE, true, NULL); if (new_size) { new_size = handle_mouse_event(&ptr, buf, new_size); diff --git a/src/nvim/os/shell.c b/src/nvim/os/shell.c index c1359d6ece..d647780847 100644 --- a/src/nvim/os/shell.c +++ b/src/nvim/os/shell.c @@ -144,7 +144,7 @@ int os_expand_wildcards(int num_pat, char **pat, int *num_file, char ***file, in bool is_fish_shell = #if defined(UNIX) - STRNCMP(invocation_path_tail((char_u *)p_sh, NULL), "fish", 4) == 0; + strncmp((char *)invocation_path_tail((char_u *)p_sh, NULL), "fish", 4) == 0; #else false; #endif diff --git a/src/nvim/os/users.c b/src/nvim/os/users.c index 1865d6789e..57dc2eb797 100644 --- a/src/nvim/os/users.c +++ b/src/nvim/os/users.c @@ -222,7 +222,7 @@ int match_user(char *name) if (strcmp(((char **)ga_users.ga_data)[i], name) == 0) { return 2; // full match } - if (STRNCMP(((char_u **)ga_users.ga_data)[i], name, n) == 0) { + if (strncmp(((char **)ga_users.ga_data)[i], name, (size_t)n) == 0) { result = 1; // partial match } } -- cgit From a283a99165865e88ea8df366d1b2db290e9c637a Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Mon, 2 Jan 2023 17:56:17 -0500 Subject: refactor: eliminate os_unix.c #21621 --- src/nvim/os/fs.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'src/nvim/os') diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c index 8c4fee58b1..4906dd0df2 100644 --- a/src/nvim/os/fs.c +++ b/src/nvim/os/fs.c @@ -779,6 +779,38 @@ int os_setperm(const char *const name, int perm) return (r == kLibuvSuccess ? OK : FAIL); } +#if defined(HAVE_ACL) +# ifdef HAVE_SYS_ACL_H +# include +# endif +# ifdef HAVE_SYS_ACCESS_H +# include +# endif + +// Return a pointer to the ACL of file "fname" in allocated memory. +// Return NULL if the ACL is not available for whatever reason. +vim_acl_T os_get_acl(const char_u *fname) +{ + vim_acl_T ret = NULL; + return ret; +} + +// Set the ACL of file "fname" to "acl" (unless it's NULL). +void os_set_acl(const char_u *fname, vim_acl_T aclent) +{ + if (aclent == NULL) { + return; + } +} + +void os_free_acl(vim_acl_T aclent) +{ + if (aclent == NULL) { + return; + } +} +#endif + #ifdef UNIX /// Checks if the current user owns a file. /// -- cgit From 628b717022815a431ea0b980444d6115c644f8c8 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Thu, 5 Jan 2023 17:39:03 +0100 Subject: refactor: extract code to open stdin for reading --- src/nvim/os/fileio.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'src/nvim/os') diff --git a/src/nvim/os/fileio.c b/src/nvim/os/fileio.c index bdea82f1ff..e93e1febcb 100644 --- a/src/nvim/os/fileio.c +++ b/src/nvim/os/fileio.c @@ -167,6 +167,30 @@ FileDescriptor *file_open_fd_new(int *const error, const int fd, const int flags return fp; } +/// Opens standard input as a FileDescriptor. +FileDescriptor *file_open_stdin(void) + FUNC_ATTR_MALLOC FUNC_ATTR_WARN_UNUSED_RESULT +{ + int error; + int stdin_dup_fd; + if (stdin_fd > 0) { + stdin_dup_fd = stdin_fd; + } else { + stdin_dup_fd = os_dup(STDIN_FILENO); +#ifdef MSWIN + // Replace the original stdin with the console input handle. + os_replace_stdin_to_conin(); +#endif + } + FileDescriptor *const stdin_dup = file_open_fd_new(&error, stdin_dup_fd, + kFileReadOnly|kFileNonBlocking); + assert(stdin_dup != NULL); + if (error != 0) { + ELOG("failed to open stdin: %s", os_strerror(error)); + } + return stdin_dup; +} + /// Close file and free its buffer /// /// @param[in,out] fp File to close. -- cgit From 08c2c7480619ccdf0c92fe6ce76da5b73b0e395b Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sat, 26 Nov 2022 18:57:46 +0100 Subject: refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/os/env.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/env.c b/src/nvim/os/env.c index 29bfbfcfdf..4b892fac28 100644 --- a/src/nvim/os/env.c +++ b/src/nvim/os/env.c @@ -634,7 +634,7 @@ void expand_env_esc(char *restrict srcp, char *restrict dst, int dstlen, bool es } else // NOLINT #endif { - while (c-- > 0 && *tail != NUL && vim_isIDc(*tail)) { + while (c-- > 0 && *tail != NUL && vim_isIDc((uint8_t)(*tail))) { *var++ = *tail++; } } @@ -667,7 +667,7 @@ void expand_env_esc(char *restrict srcp, char *restrict dst, int dstlen, bool es int c = dstlen - 1; while (c-- > 0 && *tail - && vim_isfilec(*tail) + && vim_isfilec((uint8_t)(*tail)) && !vim_ispathsep(*tail)) { *var++ = *tail++; } -- cgit From 1d16bba4d8b8b648d2dabd610924bcf3051a0f29 Mon Sep 17 00:00:00 2001 From: bfredl Date: Sat, 7 Jan 2023 10:06:03 +0100 Subject: fix(embed): handle stdio in server properly Rename stdin/stdout in the server, so that RPC data won't get corrupted. This also restores the use of stderr to write directly to the terminal. --- src/nvim/os/pty_process_unix.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/nvim/os') diff --git a/src/nvim/os/pty_process_unix.c b/src/nvim/os/pty_process_unix.c index 143f0b3900..cd2150a6a6 100644 --- a/src/nvim/os/pty_process_unix.c +++ b/src/nvim/os/pty_process_unix.c @@ -168,6 +168,14 @@ static struct termios termios_default; /// @param tty_fd TTY file descriptor, or -1 if not in a terminal. void pty_process_save_termios(int tty_fd) { + if (embedded_mode) { + // TODO(bfredl): currently we cannot use the state of the host terminal in + // the server. when the TUI process launches the server, the state has already + // changed. we would need to serialize termios_default in the TUI process and + // transmit it. Altough, just always using the clean slate of init_termios() might + // be preferrable anyway. + return; + } if (tty_fd == -1) { return; } -- cgit From 149209400383c673fdb4fdd1c9a7639139f17936 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Mon, 9 Jan 2023 14:13:06 +0100 Subject: refactor: replace char_u with char 17 - remove STRLCPY (#21235) refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/os/env.c | 10 +++++----- src/nvim/os/fs.c | 8 ++++---- src/nvim/os/users.c | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/env.c b/src/nvim/os/env.c index 4b892fac28..ef9b9c5958 100644 --- a/src/nvim/os/env.c +++ b/src/nvim/os/env.c @@ -488,8 +488,8 @@ void init_homedir(void) if (var != NULL) { // Change to the directory and get the actual path. This resolves // links. Don't do it when we can't return. - if (os_dirname((char_u *)os_buf, MAXPATHL) == OK && os_chdir(os_buf) == 0) { - if (!os_chdir(var) && os_dirname((char_u *)IObuff, IOSIZE) == OK) { + if (os_dirname(os_buf, MAXPATHL) == OK && os_chdir(os_buf) == 0) { + if (!os_chdir(var) && os_dirname(IObuff, IOSIZE) == OK) { var = (char *)IObuff; } if (os_chdir(os_buf) != 0) { @@ -500,7 +500,7 @@ void init_homedir(void) // Fall back to current working directory if home is not found if ((var == NULL || *var == NUL) - && os_dirname((char_u *)os_buf, sizeof(os_buf)) == OK) { + && os_dirname(os_buf, sizeof(os_buf)) == OK) { var = os_buf; } #endif @@ -1056,7 +1056,7 @@ size_t home_replace(const buf_T *const buf, const char *src, char *const dst, si } if (buf != NULL && buf->b_help) { - const size_t dlen = STRLCPY(dst, path_tail((char *)src), dstlen); + const size_t dlen = xstrlcpy(dst, path_tail((char *)src), dstlen); return MIN(dlen, dstlen - 1); } @@ -1176,7 +1176,7 @@ char *get_env_name(expand_T *xp, int idx) assert(idx >= 0); char *envname = os_getenvname_at_index((size_t)idx); if (envname) { - STRLCPY(xp->xp_buf, envname, EXPAND_BUF_LEN); + xstrlcpy(xp->xp_buf, envname, EXPAND_BUF_LEN); xfree(envname); return xp->xp_buf; } diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c index 4906dd0df2..b8ade07038 100644 --- a/src/nvim/os/fs.c +++ b/src/nvim/os/fs.c @@ -105,12 +105,12 @@ int os_chdir(const char *path) /// @param buf Buffer to store the directory name. /// @param len Length of `buf`. /// @return `OK` for success, `FAIL` for failure. -int os_dirname(char_u *buf, size_t len) +int os_dirname(char *buf, size_t len) FUNC_ATTR_NONNULL_ALL { int error_number; - if ((error_number = uv_cwd((char *)buf, &len)) != kLibuvSuccess) { - STRLCPY(buf, uv_strerror(error_number), len); + if ((error_number = uv_cwd(buf, &len)) != kLibuvSuccess) { + xstrlcpy(buf, uv_strerror(error_number), len); return FAIL; } return OK; @@ -379,7 +379,7 @@ static bool is_executable_in_path(const char *name, char **abspath) char *e = xstrchrnul(p, ENV_SEPCHAR); // Combine the $PATH segment with `name`. - STRLCPY(buf, p, e - p + 1); + xstrlcpy(buf, p, (size_t)(e - p) + 1); append_path(buf, name, buf_len); #ifdef MSWIN diff --git a/src/nvim/os/users.c b/src/nvim/os/users.c index 57dc2eb797..ef2986246b 100644 --- a/src/nvim/os/users.c +++ b/src/nvim/os/users.c @@ -146,7 +146,7 @@ int os_get_uname(uv_uid_t uid, char *s, size_t len) if ((pw = getpwuid(uid)) != NULL // NOLINT(runtime/threadsafe_fn) && pw->pw_name != NULL && *(pw->pw_name) != NUL) { - STRLCPY(s, pw->pw_name, len); + xstrlcpy(s, pw->pw_name, len); return OK; } #endif -- cgit From 50f03773f4b9f4638489ccfd0503dc9e39e5de78 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Mon, 9 Jan 2023 15:37:34 +0100 Subject: refactor: replace char_u with char 18 (#21237) refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/os/signal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/signal.c b/src/nvim/os/signal.c index 08d24d47e2..b8daaabba2 100644 --- a/src/nvim/os/signal.c +++ b/src/nvim/os/signal.c @@ -172,7 +172,7 @@ static void deadly_signal(int signum) ILOG("got signal %d (%s)", signum, signal_name(signum)); - snprintf((char *)IObuff, sizeof(IObuff), "Vim: Caught deadly signal '%s'\r\n", + snprintf(IObuff, sizeof(IObuff), "Vim: Caught deadly signal '%s'\r\n", signal_name(signum)); // Preserve files and exit. -- cgit From 38140a63fb255e7659c9a585bfbd32601a3f10f0 Mon Sep 17 00:00:00 2001 From: bfredl Date: Mon, 9 Jan 2023 14:09:01 +0100 Subject: refactor(pty): remove old logic for inheriting termios from host terminal --- src/nvim/os/pty_process_unix.c | 30 ++---------------------------- 1 file changed, 2 insertions(+), 28 deletions(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/pty_process_unix.c b/src/nvim/os/pty_process_unix.c index cd2150a6a6..2413f0339b 100644 --- a/src/nvim/os/pty_process_unix.c +++ b/src/nvim/os/pty_process_unix.c @@ -160,39 +160,13 @@ static pid_t forkpty(int *amaster, char *name, struct termios *termp, struct win #endif -/// termios saved at startup (for TUI) or initialized by pty_process_spawn(). -static struct termios termios_default; - -/// Saves the termios properties associated with `tty_fd`. -/// -/// @param tty_fd TTY file descriptor, or -1 if not in a terminal. -void pty_process_save_termios(int tty_fd) -{ - if (embedded_mode) { - // TODO(bfredl): currently we cannot use the state of the host terminal in - // the server. when the TUI process launches the server, the state has already - // changed. we would need to serialize termios_default in the TUI process and - // transmit it. Altough, just always using the clean slate of init_termios() might - // be preferrable anyway. - return; - } - if (tty_fd == -1) { - return; - } - int rv = tcgetattr(tty_fd, &termios_default); - if (rv != 0) { - ELOG("tcgetattr failed (tty_fd=%d): %s", tty_fd, strerror(errno)); - } else { - DLOG("tty_fd=%d", tty_fd); - } -} - /// @returns zero on success, or negative error code int pty_process_spawn(PtyProcess *ptyproc) FUNC_ATTR_NONNULL_ALL { + // termios initialized at first use + static struct termios termios_default; if (!termios_default.c_cflag) { - // TODO(jkeyes): We could pass NULL to forkpty() instead ... init_termios(&termios_default); } -- cgit From f2141de9e462ed8976b2a59337c32a0fcba2a11d Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Fri, 13 Jan 2023 00:35:39 +0100 Subject: refactor: replace char_u with char 20 (#21714) refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/os/env.c | 2 +- src/nvim/os/shell.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/env.c b/src/nvim/os/env.c index ef9b9c5958..263bc32190 100644 --- a/src/nvim/os/env.c +++ b/src/nvim/os/env.c @@ -711,7 +711,7 @@ void expand_env_esc(char *restrict srcp, char *restrict dst, int dstlen, bool es // If "var" contains white space, escape it with a backslash. // Required for ":e ~/tt" when $HOME includes a space. if (esc && var != NULL && strpbrk(var, " \t") != NULL) { - char *p = (char *)vim_strsave_escaped((char_u *)var, (char_u *)" \t"); + char *p = vim_strsave_escaped(var, " \t"); if (mustfree) { xfree(var); diff --git a/src/nvim/os/shell.c b/src/nvim/os/shell.c index d647780847..dce671c9b5 100644 --- a/src/nvim/os/shell.c +++ b/src/nvim/os/shell.c @@ -1332,7 +1332,7 @@ static char *shell_xescape_xquote(const char *cmd) const char *ecmd = cmd; if (*p_sxe != NUL && strcmp(p_sxq, "(") == 0) { - ecmd = (char *)vim_strsave_escaped_ext((char_u *)cmd, p_sxe, '^', false); + ecmd = vim_strsave_escaped_ext(cmd, (char *)p_sxe, '^', false); } size_t ncmd_size = strlen(ecmd) + strlen(p_sxq) * 2 + 1; char *ncmd = xmalloc(ncmd_size); -- cgit From e89c39d6f016a4140293755250e968e839009617 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sat, 14 Jan 2023 08:58:28 +0100 Subject: refactor: replace char_u with char 21 (#21779) refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/os/env.c | 6 +++--- src/nvim/os/fs.c | 2 +- src/nvim/os/shell.c | 60 ++++++++++++++++++++++++++--------------------------- 3 files changed, 34 insertions(+), 34 deletions(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/env.c b/src/nvim/os/env.c index 263bc32190..e1db7a8ef7 100644 --- a/src/nvim/os/env.c +++ b/src/nvim/os/env.c @@ -543,7 +543,7 @@ void free_homedir(void) /// @see {expand_env} char *expand_env_save(char *src) { - return (char *)expand_env_save_opt((char_u *)src, false); + return (char *)expand_env_save_opt(src, false); } /// Similar to expand_env_save() but when "one" is `true` handle the string as @@ -551,10 +551,10 @@ char *expand_env_save(char *src) /// @param src String containing environment variables to expand /// @param one Should treat as only one file name /// @see {expand_env} -char_u *expand_env_save_opt(char_u *src, bool one) +char_u *expand_env_save_opt(char *src, bool one) { char_u *p = xmalloc(MAXPATHL); - expand_env_esc((char *)src, (char *)p, MAXPATHL, false, one, NULL); + expand_env_esc(src, (char *)p, MAXPATHL, false, one, NULL); return p; } diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c index b8ade07038..e0449d468a 100644 --- a/src/nvim/os/fs.c +++ b/src/nvim/os/fs.c @@ -995,7 +995,7 @@ int os_mkdir_recurse(const char *const dir, int32_t mode, char **const failed_di int os_file_mkdir(char *fname, int32_t mode) FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT { - if (!dir_of_file_exists((char_u *)fname)) { + if (!dir_of_file_exists(fname)) { char *tail = path_tail_with_sep(fname); char *last_char = tail + strlen(tail) - 1; if (vim_ispathsep(*last_char)) { diff --git a/src/nvim/os/shell.c b/src/nvim/os/shell.c index dce671c9b5..8177f06c64 100644 --- a/src/nvim/os/shell.c +++ b/src/nvim/os/shell.c @@ -65,7 +65,7 @@ typedef struct { static void save_patterns(int num_pat, char **pat, int *num_file, char ***file) { - *file = xmalloc((size_t)num_pat * sizeof(char_u *)); + *file = xmalloc((size_t)num_pat * sizeof(char *)); for (int i = 0; i < num_pat; i++) { char *s = xstrdup(pat[i]); // Be compatible with expand_filename(): halve the number of @@ -122,7 +122,7 @@ int os_expand_wildcards(int num_pat, char **pat, int *num_file, char ***file, in size_t len; char *p; bool dir; - char_u *extra_shell_arg = NULL; + char *extra_shell_arg = NULL; ShellOpts shellopts = kShellOptExpand | kShellOptSilent; int j; char *tempname; @@ -144,7 +144,7 @@ int os_expand_wildcards(int num_pat, char **pat, int *num_file, char ***file, in bool is_fish_shell = #if defined(UNIX) - strncmp((char *)invocation_path_tail((char_u *)p_sh, NULL), "fish", 4) == 0; + strncmp((char *)invocation_path_tail(p_sh, NULL), "fish", 4) == 0; #else false; #endif @@ -337,17 +337,17 @@ int os_expand_wildcards(int num_pat, char **pat, int *num_file, char ***file, in // the argument list, otherwise zsh gives an error message and doesn't // expand any other pattern. if (shell_style == STYLE_PRINT) { - extra_shell_arg = (char_u *)"-G"; // Use zsh NULL_GLOB option + extra_shell_arg = "-G"; // Use zsh NULL_GLOB option // If we use -f then shell variables set in .cshrc won't get expanded. // vi can do it, so we will too, but it is only necessary if there is a "$" // in one of the patterns, otherwise we can still use the fast option. } else if (shell_style == STYLE_GLOB && !have_dollars(num_pat, pat)) { - extra_shell_arg = (char_u *)"-f"; // Use csh fast option + extra_shell_arg = "-f"; // Use csh fast option } // execute the shell command - i = call_shell((char_u *)command, shellopts, extra_shell_arg); + i = call_shell(command, shellopts, extra_shell_arg); // When running in the background, give it some time to create the temp // file, but don't wait for it to finish. @@ -488,7 +488,7 @@ int os_expand_wildcards(int num_pat, char **pat, int *num_file, char ***file, in goto notfound; } *num_file = i; - *file = xmalloc(sizeof(char_u *) * (size_t)i); + *file = xmalloc(sizeof(char *) * (size_t)i); // Isolate the individual file names. p = buffer; @@ -570,18 +570,18 @@ notfound: char **shell_build_argv(const char *cmd, const char *extra_args) FUNC_ATTR_NONNULL_RET { - size_t argc = tokenize((char_u *)p_sh, NULL) + (cmd ? tokenize(p_shcf, NULL) : 0); + size_t argc = tokenize(p_sh, NULL) + (cmd ? tokenize((char *)p_shcf, NULL) : 0); char **rv = xmalloc((argc + 4) * sizeof(*rv)); // Split 'shell' - size_t i = tokenize((char_u *)p_sh, rv); + size_t i = tokenize(p_sh, rv); if (extra_args) { rv[i++] = xstrdup(extra_args); // Push a copy of `extra_args` } if (cmd) { - i += tokenize(p_shcf, rv + i); // Split 'shellcmdflag' + i += tokenize((char *)p_shcf, rv + i); // Split 'shellcmdflag' rv[i++] = shell_xescape_xquote(cmd); // Copy (and escape) `cmd`. } @@ -653,7 +653,7 @@ char *shell_argv_to_str(char **const argv) /// @param extra_args Extra arguments to the shell, or NULL. /// /// @return shell command exit code -int os_call_shell(char_u *cmd, ShellOpts opts, char_u *extra_args) +int os_call_shell(char *cmd, ShellOpts opts, char *extra_args) { DynamicBuffer input = DYNAMIC_BUFFER_INIT; char *output = NULL, **output_ptr = NULL; @@ -682,7 +682,7 @@ int os_call_shell(char_u *cmd, ShellOpts opts, char_u *extra_args) } size_t nread; - int exitcode = do_os_system(shell_build_argv((char *)cmd, (char *)extra_args), + int exitcode = do_os_system(shell_build_argv(cmd, extra_args), input.data, input.len, output_ptr, &nread, emsg_silent, forward_output); xfree(input.data); @@ -708,14 +708,14 @@ int os_call_shell(char_u *cmd, ShellOpts opts, char_u *extra_args) /// Invalidates cached tags. /// /// @return shell command exit code -int call_shell(char_u *cmd, ShellOpts opts, char_u *extra_shell_arg) +int call_shell(char *cmd, ShellOpts opts, char *extra_shell_arg) { int retval; proftime_T wait_time; if (p_verbose > 3) { verbose_enter(); - smsg(_("Executing command: \"%s\""), cmd == NULL ? p_sh : (char *)cmd); + smsg(_("Executing command: \"%s\""), cmd == NULL ? p_sh : cmd); msg_putchar('\n'); verbose_leave(); } @@ -752,23 +752,23 @@ int call_shell(char_u *cmd, ShellOpts opts, char_u *extra_shell_arg) /// @param ret_len length of the stdout /// /// @return an allocated string, or NULL for error. -char_u *get_cmd_output(char_u *cmd, char_u *infile, ShellOpts flags, size_t *ret_len) +char *get_cmd_output(char *cmd, char *infile, ShellOpts flags, size_t *ret_len) { - char_u *buffer = NULL; + char *buffer = NULL; if (check_secure()) { return NULL; } // get a name for the temp file - char_u *tempname = (char_u *)vim_tempname(); + char *tempname = vim_tempname(); if (tempname == NULL) { emsg(_(e_notmp)); return NULL; } // Add the redirection stuff - char_u *command = (char_u *)make_filter_cmd((char *)cmd, (char *)infile, (char *)tempname); + char *command = make_filter_cmd(cmd, infile, tempname); // Call the shell to execute the command (errors are ignored). // Don't check timestamps here. @@ -779,7 +779,7 @@ char_u *get_cmd_output(char_u *cmd, char_u *infile, ShellOpts flags, size_t *ret xfree(command); // read the names from the file into memory - FILE *fd = os_fopen((char *)tempname, READBIN); + FILE *fd = os_fopen(tempname, READBIN); if (fd == NULL) { semsg(_(e_notopen), tempname); @@ -791,9 +791,9 @@ char_u *get_cmd_output(char_u *cmd, char_u *infile, ShellOpts flags, size_t *ret fseek(fd, 0L, SEEK_SET); buffer = xmalloc(len + 1); - size_t i = fread((char *)buffer, 1, len, fd); + size_t i = fread(buffer, 1, len, fd); fclose(fd); - os_remove((char *)tempname); + os_remove(tempname); if (i != len) { semsg(_(e_notread), tempname); XFREE_CLEAR(buffer); @@ -1165,14 +1165,14 @@ static void out_data_cb(Stream *stream, RBuffer *buf, size_t count, void *data, /// @param argv The vector that will be filled with copies of the parsed /// words. It can be NULL if the caller only needs to count words. /// @return The number of words parsed. -static size_t tokenize(const char_u *const str, char **const argv) +static size_t tokenize(const char *const str, char **const argv) FUNC_ATTR_NONNULL_ARG(1) { size_t argc = 0; - const char *p = (const char *)str; + const char *p = str; while (*p != NUL) { - const size_t len = word_length((const char_u *)p); + const size_t len = word_length(p); if (argv != NULL) { // Fill the slot @@ -1190,9 +1190,9 @@ static size_t tokenize(const char_u *const str, char **const argv) /// /// @param str A pointer to the first character of the word /// @return The offset from `str` at which the word ends. -static size_t word_length(const char_u *str) +static size_t word_length(const char *str) { - const char_u *p = str; + const char *p = str; bool inquote = false; size_t length = 0; @@ -1223,10 +1223,10 @@ static void read_input(DynamicBuffer *buf) { size_t written = 0, l = 0, len = 0; linenr_T lnum = curbuf->b_op_start.lnum; - char_u *lp = (char_u *)ml_get(lnum); + char *lp = ml_get(lnum); for (;;) { - l = strlen((char *)lp + written); + l = strlen(lp + written); if (l == 0) { len = 0; } else if (lp[written] == NL) { @@ -1235,7 +1235,7 @@ static void read_input(DynamicBuffer *buf) dynamic_buffer_ensure(buf, buf->len + len); buf->data[buf->len++] = NUL; } else { - char_u *s = (char_u *)vim_strchr((char *)lp + written, NL); + char *s = vim_strchr(lp + written, NL); len = s == NULL ? l : (size_t)(s - (lp + written)); dynamic_buffer_ensure(buf, buf->len + len); memcpy(buf->data + buf->len, lp + written, len); @@ -1255,7 +1255,7 @@ static void read_input(DynamicBuffer *buf) if (lnum > curbuf->b_op_end.lnum) { break; } - lp = (char_u *)ml_get(lnum); + lp = ml_get(lnum); written = 0; } else if (len > 0) { written += len; -- cgit