diff options
author | bfredl <bjorn.linse@gmail.com> | 2022-11-22 11:02:24 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-22 11:02:24 +0100 |
commit | cd386b2c72eaacd9acac27380ee34db1accad9cb (patch) | |
tree | 15f906032e4091204450ed197da3ad97ddcb5049 /src/nvim/os | |
parent | 5eb5f4948826e9d47685ea9e257409cc3e693614 (diff) | |
parent | 40f3f75867bf03abfd90e0389a38197a00d37af1 (diff) | |
download | rneovim-cd386b2c72eaacd9acac27380ee34db1accad9cb.tar.gz rneovim-cd386b2c72eaacd9acac27380ee34db1accad9cb.tar.bz2 rneovim-cd386b2c72eaacd9acac27380ee34db1accad9cb.zip |
Merge pull request #20151 from dundargoc/refactor/char_u/13
refactor: replace char_u with char 13: remove `STRLEN` part 3
Diffstat (limited to 'src/nvim/os')
-rw-r--r-- | src/nvim/os/env.c | 58 | ||||
-rw-r--r-- | src/nvim/os/shell.c | 44 |
2 files changed, 51 insertions, 51 deletions
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; |