diff options
author | Dundar Göc <gocdundar@gmail.com> | 2022-08-26 23:11:25 +0200 |
---|---|---|
committer | dundargoc <gocdundar@gmail.com> | 2022-09-10 11:17:40 +0200 |
commit | 684bc749efef0fa31395d349f4495d79ec5f3fd5 (patch) | |
tree | 2f20ecdf42e443e48ac981d204c316449aa87821 | |
parent | 82d93429e78b661027c05f3fbc862aa0e0c6cd95 (diff) | |
download | rneovim-684bc749efef0fa31395d349f4495d79ec5f3fd5.tar.gz rneovim-684bc749efef0fa31395d349f4495d79ec5f3fd5.tar.bz2 rneovim-684bc749efef0fa31395d349f4495d79ec5f3fd5.zip |
refactor: replace char_u with char
Work on https://github.com/neovim/neovim/issues/459
39 files changed, 262 insertions, 275 deletions
diff --git a/src/nvim/arglist.c b/src/nvim/arglist.c index 0000636417..02e3a99aab 100644 --- a/src/nvim/arglist.c +++ b/src/nvim/arglist.c @@ -633,7 +633,7 @@ void ex_argdedupe(exarg_T *eap FUNC_ATTR_UNUSED) { for (int i = 0; i < ARGCOUNT; i++) { for (int j = i + 1; j < ARGCOUNT; j++) { - if (FNAMECMP(ARGLIST[i].ae_fname, ARGLIST[j].ae_fname) == 0) { + if (path_fnamecmp(ARGLIST[i].ae_fname, ARGLIST[j].ae_fname) == 0) { xfree(ARGLIST[j].ae_fname); memmove(ARGLIST + j, ARGLIST + j + 1, (size_t)(ARGCOUNT - j - 1) * sizeof(aentry_T)); diff --git a/src/nvim/autocmd.c b/src/nvim/autocmd.c index 635875b16f..9d37647a4e 100644 --- a/src/nvim/autocmd.c +++ b/src/nvim/autocmd.c @@ -2396,7 +2396,7 @@ bool au_exists(const char *const arg) FUNC_ATTR_WARN_UNUSED_RESULT } // if pattern is "<buffer>", special handling is needed which uses curbuf - // for pattern "<buffer=N>, FNAMECMP() will work fine + // for pattern "<buffer=N>, path_fnamecmp() will work fine if (pattern != NULL && STRICMP(pattern, "<buffer>") == 0) { buflocal_buf = curbuf; } @@ -2404,12 +2404,12 @@ bool au_exists(const char *const arg) FUNC_ATTR_WARN_UNUSED_RESULT // Check if there is an autocommand with the given pattern. for (; ap != NULL; ap = ap->next) { // only use a pattern when it has not been removed and has commands. - // For buffer-local autocommands, FNAMECMP() works fine. + // For buffer-local autocommands, path_fnamecmp() works fine. if (ap->pat != NULL && ap->cmds != NULL && (group == AUGROUP_ALL || ap->group == group) && (pattern == NULL || (buflocal_buf == NULL - ? FNAMECMP(ap->pat, pattern) == 0 + ? path_fnamecmp(ap->pat, pattern) == 0 : ap->buflocal_nr == buflocal_buf->b_fnum))) { retval = true; break; diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 658d372cee..1cc68c9cee 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -2733,7 +2733,7 @@ void buflist_list(exarg_T *eap) IObuff[len++] = ' '; } while (--i > 0 && len < IOSIZE - 18); if (vim_strchr(eap->arg, 't') && buf->b_last_used) { - undo_fmt_time(IObuff + len, (size_t)(IOSIZE - len), buf->b_last_used); + undo_fmt_time((char_u *)IObuff + len, (size_t)(IOSIZE - len), buf->b_last_used); } else { vim_snprintf((char *)IObuff + len, (size_t)(IOSIZE - len), _("line %" PRId64), buf == curbuf ? (int64_t)curwin->w_cursor.lnum : (int64_t)buflist_findlnum(buf)); @@ -2965,7 +2965,7 @@ static bool otherfile_buf(buf_T *buf, char *ffname, FileID *file_id_p, bool file if (ffname == NULL || *ffname == NUL || buf->b_ffname == NULL) { return true; } - if (FNAMECMP(ffname, buf->b_ffname) == 0) { + if (path_fnamecmp(ffname, buf->b_ffname) == 0) { return false; } { diff --git a/src/nvim/cmdexpand.c b/src/nvim/cmdexpand.c index d2cfb25bf9..3e9edea372 100644 --- a/src/nvim/cmdexpand.c +++ b/src/nvim/cmdexpand.c @@ -361,7 +361,7 @@ static char *ExpandOne_start(int mode, expand_T *xp, char *str, int options) // expand_wildcards, only need to check the first two. non_suf_match = 0; for (int i = 0; i < 2; i++) { - if (match_suffix((char_u *)xp->xp_files[i])) { + if (match_suffix(xp->xp_files[i])) { non_suf_match++; } } diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 0f2547120d..ead01fcbad 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -8117,7 +8117,7 @@ repeat: // Do not call shorten_fname() here since it removes the prefix // even though the path does not have a prefix. - if (FNAMENCMP(p, dirname, namelen) == 0) { + if (path_fnamencmp(p, dirname, namelen) == 0) { p += namelen; if (vim_ispathsep(*p)) { while (*p && vim_ispathsep(*p)) { @@ -8329,7 +8329,7 @@ char *do_string_sub(char *str, char *pat, char *sub, typval_T *expr, char *flags while (vim_regexec_nl(®match, (char_u *)str, (colnr_T)(tail - str))) { // Skip empty match except for first match. if (regmatch.startp[0] == regmatch.endp[0]) { - if ((char_u *)zero_width == regmatch.startp[0]) { + if (zero_width == regmatch.startp[0]) { // avoid getting stuck on a match with an empty string int i = utfc_ptr2len(tail); memmove((char_u *)ga.ga_data + ga.ga_len, tail, (size_t)i); @@ -8337,7 +8337,7 @@ char *do_string_sub(char *str, char *pat, char *sub, typval_T *expr, char *flags tail += i; continue; } - zero_width = (char *)regmatch.startp[0]; + zero_width = regmatch.startp[0]; } // Get some space for a temporary buffer to do the substitution @@ -8350,14 +8350,14 @@ char *do_string_sub(char *str, char *pat, char *sub, typval_T *expr, char *flags (regmatch.endp[0] - regmatch.startp[0]))); // copy the text up to where the match is - int i = (int)(regmatch.startp[0] - (char_u *)tail); + int i = (int)(regmatch.startp[0] - tail); memmove((char_u *)ga.ga_data + ga.ga_len, tail, (size_t)i); // add the substituted text (void)vim_regsub(®match, (char_u *)sub, expr, (char_u *)ga.ga_data + ga.ga_len + i, sublen, REGSUB_COPY | REGSUB_MAGIC); ga.ga_len += i + sublen - 1; - tail = (char *)regmatch.endp[0]; + tail = regmatch.endp[0]; if (*tail == NUL) { break; } diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c index fa48f227e3..b59caab34f 100644 --- a/src/nvim/eval/funcs.c +++ b/src/nvim/eval/funcs.c @@ -4984,9 +4984,9 @@ static void find_some_match(typval_T *const argvars, typval_T *const rettv, li = TV_LIST_ITEM_NEXT(l, li); idx++; } else { - startcol = (colnr_T)(regmatch.startp[0] - + utfc_ptr2len((char *)regmatch.startp[0]) - str); - if (startcol > (colnr_T)len || str + startcol <= regmatch.startp[0]) { + startcol = (colnr_T)((char_u *)regmatch.startp[0] + + utfc_ptr2len(regmatch.startp[0]) - str); + if (startcol > (colnr_T)len || str + startcol <= (char_u *)regmatch.startp[0]) { match = false; break; } @@ -5005,8 +5005,8 @@ static void find_some_match(typval_T *const argvars, typval_T *const rettv, const size_t rd = (size_t)(regmatch.endp[0] - regmatch.startp[0]); TV_LIST_ITEM_TV(li1)->vval.v_string = xmemdupz((const char *)regmatch.startp[0], rd); - TV_LIST_ITEM_TV(li3)->vval.v_number = (varnumber_T)(regmatch.startp[0] - expr); - TV_LIST_ITEM_TV(li4)->vval.v_number = (varnumber_T)(regmatch.endp[0] - expr); + TV_LIST_ITEM_TV(li3)->vval.v_number = (varnumber_T)((char_u *)regmatch.startp[0] - expr); + TV_LIST_ITEM_TV(li4)->vval.v_number = (varnumber_T)(regmatch.endp[0] - (char *)expr); if (l != NULL) { TV_LIST_ITEM_TV(li2)->vval.v_number = (varnumber_T)idx; } @@ -5041,10 +5041,10 @@ static void find_some_match(typval_T *const argvars, typval_T *const rettv, } else { if (type == kSomeMatch) { rettv->vval.v_number = - (varnumber_T)(regmatch.startp[0] - str); + (varnumber_T)((char_u *)regmatch.startp[0] - str); } else { rettv->vval.v_number = - (varnumber_T)(regmatch.endp[0] - str); + (varnumber_T)(regmatch.endp[0] - (char *)str); } rettv->vval.v_number += (varnumber_T)(str - expr); } @@ -6225,8 +6225,8 @@ static void f_rename(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) rettv->vval.v_number = -1; } else { char buf[NUMBUFLEN]; - rettv->vval.v_number = vim_rename((const char_u *)tv_get_string(&argvars[0]), - (const char_u *)tv_get_string_buf(&argvars[1], buf)); + rettv->vval.v_number = vim_rename(tv_get_string(&argvars[0]), + tv_get_string_buf(&argvars[1], buf)); } } @@ -8193,11 +8193,11 @@ static void f_split(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) break; } // Advance to just after the match. - if (regmatch.endp[0] > (char_u *)str) { + if (regmatch.endp[0] > str) { col = 0; } else { // Don't get stuck at the same match. - col = utfc_ptr2len((char *)regmatch.endp[0]); + col = utfc_ptr2len(regmatch.endp[0]); } str = (const char *)regmatch.endp[0]; } diff --git a/src/nvim/eval/userfunc.c b/src/nvim/eval/userfunc.c index a1c4b8b893..70c9e02d5c 100644 --- a/src/nvim/eval/userfunc.c +++ b/src/nvim/eval/userfunc.c @@ -2462,7 +2462,7 @@ void ex_function(exarg_T *eap) p = vim_strchr((char *)scriptname, '/'); plen = (int)STRLEN(p); slen = (int)STRLEN(SOURCING_NAME); - if (slen > plen && FNAMECMP(p, SOURCING_NAME + slen - plen) == 0) { + if (slen > plen && path_fnamecmp(p, SOURCING_NAME + slen - plen) == 0) { j = OK; } xfree(scriptname); @@ -2632,7 +2632,7 @@ char *get_user_func_name(expand_T *xp, int idx) return (char *)fp->uf_name; // Prevent overflow. } - cat_func_name(IObuff, fp); + cat_func_name((char_u *)IObuff, fp); if (xp->xp_context != EXPAND_USER_FUNC) { STRCAT(IObuff, "("); if (!fp->uf_varargs && GA_EMPTY(&fp->uf_args)) { diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index 4f33a2d883..96bef4902c 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -559,10 +559,10 @@ void ex_sort(exarg_T *eap) end_col = len; if (regmatch.regprog != NULL && vim_regexec(®match, s, 0)) { if (sort_rx) { - start_col = (colnr_T)(regmatch.startp[0] - (char_u *)s); - end_col = (colnr_T)(regmatch.endp[0] - (char_u *)s); + start_col = (colnr_T)(regmatch.startp[0] - s); + end_col = (colnr_T)(regmatch.endp[0] - s); } else { - start_col = (colnr_T)(regmatch.endp[0] - (char_u *)s); + start_col = (colnr_T)(regmatch.endp[0] - s); } } else if (regmatch.regprog != NULL) { end_col = 0; diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index 2a378f6f02..5defabc05a 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -2836,12 +2836,12 @@ static void append_command(char *cmd) } STRCAT(IObuff, ": "); d = (char *)IObuff + STRLEN(IObuff); - while (*s != NUL && (char_u *)d - IObuff + 5 < IOSIZE) { + while (*s != NUL && d - IObuff + 5 < IOSIZE) { if ((char_u)s[0] == 0xc2 && (char_u)s[1] == 0xa0) { s += 2; STRCPY(d, "<a0>"); d += 4; - } else if ((char_u *)d - IObuff + utfc_ptr2len(s) + 1 >= IOSIZE) { + } else if (d - IObuff + utfc_ptr2len(s) + 1 >= IOSIZE) { break; } else { mb_copy_char((const char **)&s, &d); diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 60c89f61a8..2b7797ddc8 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -2005,7 +2005,7 @@ static int command_line_handle_key(CommandLineState *s) } else { int j = utf_char2bytes(s->c, (char *)IObuff); IObuff[j] = NUL; // exclude composing chars - put_on_cmdline(IObuff, j, true); + put_on_cmdline((char_u *)IObuff, j, true); } return command_line_changed(s); } diff --git a/src/nvim/file_search.c b/src/nvim/file_search.c index 5416be651d..b3491e98c2 100644 --- a/src/nvim/file_search.c +++ b/src/nvim/file_search.c @@ -112,7 +112,7 @@ typedef struct ff_visited { FileID file_id; // The memory for this struct is allocated according to the length of // ffv_fname. - char_u ffv_fname[1]; // actually longer + char ffv_fname[1]; // actually longer } ff_visited_T; // We might have to manage several visited lists during a search. @@ -463,7 +463,7 @@ void *vim_findfile_init(char *path, char *filename, char *stopdirs, int level, i xfree(buf); goto error_return; } - STRLCAT(ff_expand_buffer, search_ctx->ffsc_fix_path, eb_len + (size_t)len + 1); + xstrlcat(ff_expand_buffer, search_ctx->ffsc_fix_path, eb_len + (size_t)len + 1); add_pathsep(ff_expand_buffer); } else { len = (int)STRLEN(search_ctx->ffsc_fix_path); @@ -813,8 +813,7 @@ char_u *vim_findfile(void *search_ctx_arg) } if (os_dirname((char_u *)ff_expand_buffer, MAXPATHL) == OK) { - p = path_shorten_fname(file_path, - (char_u *)ff_expand_buffer); + p = (char_u *)path_shorten_fname((char *)file_path, ff_expand_buffer); if (p != NULL) { STRMOVE(file_path, p); } @@ -859,8 +858,8 @@ char_u *vim_findfile(void *search_ctx_arg) if (STRNCMP(stackp->ffs_wc_path, "**", 2) == 0) { for (int i = stackp->ffs_filearray_cur; i < stackp->ffs_filearray_size; i++) { - if (FNAMECMP(stackp->ffs_filearray[i], - stackp->ffs_fix_path) == 0) { + if (path_fnamecmp(stackp->ffs_filearray[i], + (char *)stackp->ffs_fix_path) == 0) { continue; // don't repush same directory } if (!os_isdir(stackp->ffs_filearray[i])) { @@ -883,9 +882,9 @@ char_u *vim_findfile(void *search_ctx_arg) ff_stack_T *sptr; // is the last starting directory in the stop list? - if (ff_path_in_stoplist((char_u *)search_ctx->ffsc_start_dir, + if (ff_path_in_stoplist(search_ctx->ffsc_start_dir, (int)(path_end - (char_u *)search_ctx->ffsc_start_dir), - (char_u **)search_ctx->ffsc_stopdirs_v) == true) { + search_ctx->ffsc_stopdirs_v) == true) { break; } @@ -981,7 +980,7 @@ static ff_visited_list_hdr_T *ff_get_visited_list(char *filename, if (*list_headp != NULL) { retptr = *list_headp; while (retptr != NULL) { - if (FNAMECMP(filename, retptr->ffvl_filename) == 0) { + if (path_fnamecmp(filename, retptr->ffvl_filename) == 0) { #ifdef FF_VERBOSE if (p_verbose >= 5) { verbose_enter_scroll(); @@ -1080,7 +1079,7 @@ static int ff_check_visited(ff_visited_T **visited_list, char *fname, char *wc_p // check against list of already visited files for (vp = *visited_list; vp != NULL; vp = vp->ffv_next) { - if ((url && FNAMECMP(vp->ffv_fname, ff_expand_buffer) == 0) + if ((url && path_fnamecmp(vp->ffv_fname, ff_expand_buffer) == 0) || (!url && vp->file_id_valid && os_fileid_equal(&(vp->file_id), &file_id))) { // are the wildcard parts equal @@ -1224,7 +1223,7 @@ static void ff_clear(ff_search_ctx_T *search_ctx) /// check if the given path is in the stopdirs /// /// @return true if yes else false -static int ff_path_in_stoplist(char_u *path, int path_len, char_u **stopdirs_v) +static int ff_path_in_stoplist(char *path, int path_len, char **stopdirs_v) { int i = 0; @@ -1243,12 +1242,12 @@ static int ff_path_in_stoplist(char_u *path, int path_len, char_u **stopdirs_v) // match for parent directory. So '/home' also matches // '/home/rks'. Check for PATHSEP in stopdirs_v[i], else // '/home/r' would also match '/home/rks' - if (FNAMENCMP(stopdirs_v[i], path, path_len) == 0 + if (path_fnamencmp(stopdirs_v[i], path, (size_t)path_len) == 0 && vim_ispathsep(stopdirs_v[i][path_len])) { return true; } } else { - if (FNAMECMP(stopdirs_v[i], path) == 0) { + if (path_fnamecmp(stopdirs_v[i], path) == 0) { return true; } } diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index 7b117aa6e3..0bc7f736bc 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -117,7 +117,7 @@ struct bw_info { static char *e_auchangedbuf = N_("E812: Autocommands changed buffer or buffer name"); -void filemess(buf_T *buf, char_u *name, char_u *s, int attr) +void filemess(buf_T *buf, char *name, char *s, int attr) { int msg_scroll_save; @@ -126,7 +126,7 @@ void filemess(buf_T *buf, char_u *name, char_u *s, int attr) } add_quoted_fname((char *)IObuff, IOSIZE - 100, buf, (const char *)name); // Avoid an over-long translation to cause trouble. - STRLCAT(IObuff, s, IOSIZE); + xstrlcat(IObuff, s, IOSIZE); // For the first message may have to start a new line. // For further ones overwrite the previous one, reset msg_scroll before // calling filemess(). @@ -350,7 +350,7 @@ int readfile(char *fname, char *sfname, linenr_T from, linenr_T lines_to_skip, // If the name is too long we might crash further on, quit here. if (namelen >= MAXPATHL) { - filemess(curbuf, (char_u *)fname, (char_u *)_("Illegal file name"), 0); + filemess(curbuf, fname, _("Illegal file name"), 0); msg_end(); msg_scroll = msg_save; return FAIL; @@ -361,7 +361,7 @@ int readfile(char *fname, char *sfname, linenr_T from, linenr_T lines_to_skip, // swap file may destroy it! Reported on MS-DOS and Win 95. if (after_pathsep(fname, fname + namelen)) { if (!silent) { - filemess(curbuf, (char_u *)fname, (char_u *)_(msg_is_a_directory), 0); + filemess(curbuf, fname, _(msg_is_a_directory), 0); } msg_end(); msg_scroll = msg_save; @@ -383,10 +383,10 @@ int readfile(char *fname, char *sfname, linenr_T from, linenr_T lines_to_skip, ) { if (S_ISDIR(perm)) { if (!silent) { - filemess(curbuf, (char_u *)fname, (char_u *)_(msg_is_a_directory), 0); + filemess(curbuf, fname, _(msg_is_a_directory), 0); } } else { - filemess(curbuf, (char_u *)fname, (char_u *)_("is not a file"), 0); + filemess(curbuf, fname, _("is not a file"), 0); } msg_end(); msg_scroll = msg_save; @@ -475,9 +475,9 @@ int readfile(char *fname, char *sfname, linenr_T from, linenr_T lines_to_skip, } if (!silent) { if (dir_of_file_exists((char_u *)fname)) { - filemess(curbuf, (char_u *)sfname, (char_u *)new_file_message(), 0); + filemess(curbuf, sfname, new_file_message(), 0); } else { - filemess(curbuf, (char_u *)sfname, (char_u *)_("[New DIRECTORY]"), 0); + filemess(curbuf, sfname, _("[New DIRECTORY]"), 0); } } // Even though this is a new file, it might have been @@ -497,15 +497,15 @@ int readfile(char *fname, char *sfname, linenr_T from, linenr_T lines_to_skip, } return OK; // a new file is not an error } else { - filemess(curbuf, (char_u *)sfname, (char_u *)((fd == UV_EFBIG) ? _("[File too big]") : + filemess(curbuf, sfname, ((fd == UV_EFBIG) ? _("[File too big]") : #if defined(UNIX) && defined(EOVERFLOW) - // libuv only returns -errno - // in Unix and in Windows - // open() does not set - // EOVERFLOW - (fd == -EOVERFLOW) ? _("[File too big]") : + // libuv only returns -errno + // in Unix and in Windows + // open() does not set + // EOVERFLOW + (fd == -EOVERFLOW) ? _("[File too big]") : #endif - _("[Permission Denied]")), 0); + _("[Permission Denied]")), 0); curbuf->b_p_ro = true; // must use "w!" now } @@ -661,7 +661,7 @@ int readfile(char *fname, char *sfname, linenr_T from, linenr_T lines_to_skip, if (!recoverymode && !filtering && !(flags & READ_DUMMY) && !silent) { if (!read_stdin && !read_buffer) { - filemess(curbuf, (char_u *)sfname, (char_u *)"", 0); + filemess(curbuf, sfname, "", 0); } } @@ -1728,7 +1728,7 @@ failed: if (got_int) { if (!(flags & READ_DUMMY)) { - filemess(curbuf, (char_u *)sfname, (char_u *)_(e_interr), 0); + filemess(curbuf, sfname, _(e_interr), 0); if (newfile) { curbuf->b_p_ro = true; // must use "w!" now } @@ -2253,7 +2253,7 @@ int buf_write(buf_T *buf, char *fname, char *sfname, linenr_T start, linenr_T en fname = sfname; #endif - if (buf->b_ffname != NULL && FNAMECMP(ffname, buf->b_ffname) == 0) { + if (buf->b_ffname != NULL && path_fnamecmp(ffname, buf->b_ffname) == 0) { overwriting = true; } else { overwriting = false; @@ -2455,9 +2455,9 @@ int buf_write(buf_T *buf, char *fname, char *sfname, linenr_T start, linenr_T en #ifndef UNIX (char_u *)sfname, #else - (char_u *)fname, + fname, #endif - (char_u *)"", 0); // show that we are busy + "", 0); // show that we are busy } msg_scroll = false; // always overwrite the file message now @@ -2596,7 +2596,7 @@ int buf_write(buf_T *buf, char *fname, char *sfname, linenr_T start, linenr_T en STRCPY(IObuff, fname); for (i = 4913;; i += 123) { char *tail = path_tail((char *)IObuff); - size_t size = (size_t)((char_u *)tail - IObuff); + size_t size = (size_t)(tail - IObuff); snprintf(tail, IOSIZE - size, "%d", i); if (!os_fileinfo_link((char *)IObuff, &file_info)) { break; @@ -2884,7 +2884,7 @@ nobackup: // If the renaming of the original file to the backup file // works, quit here. /// - if (vim_rename((char_u *)fname, (char_u *)backup) == 0) { + if (vim_rename(fname, backup) == 0) { break; } @@ -3100,7 +3100,7 @@ restore_backup: // In that case we leave the copy around. // If file does not exist, put the copy in its place if (!os_path_exists(fname)) { - vim_rename((char_u *)backup, (char_u *)fname); + vim_rename(backup, fname); } // if original file does exist throw away the copy if (os_path_exists(fname)) { @@ -3108,7 +3108,7 @@ restore_backup: } } else { // try to put the original file back - vim_rename((char_u *)backup, (char_u *)fname); + vim_rename(backup, fname); } } @@ -3375,7 +3375,7 @@ restore_backup: end = 1; // success } } else { - if (vim_rename((char_u *)backup, (char_u *)fname) == 0) { + if (vim_rename(backup, fname) == 0) { end = 1; } } @@ -3471,7 +3471,7 @@ restore_backup: if (org == NULL) { emsg(_("E205: Patchmode: can't save original file")); } else if (!os_path_exists(org)) { - vim_rename((char_u *)backup, (char_u *)org); + vim_rename(backup, org); XFREE_CLEAR(backup); // don't delete the file #ifdef UNIX os_file_settime(org, @@ -3716,20 +3716,20 @@ void msg_add_lines(int insert_space, long lnum, off_T nchars) { char_u *p; - p = IObuff + STRLEN(IObuff); + p = (char_u *)IObuff + STRLEN(IObuff); if (insert_space) { *p++ = ' '; } if (shortmess(SHM_LINES)) { - vim_snprintf((char *)p, (size_t)(IOSIZE - (p - IObuff)), "%" PRId64 "L, %" PRId64 "B", + vim_snprintf((char *)p, (size_t)(IOSIZE - (p - (char_u *)IObuff)), "%" PRId64 "L, %" PRId64 "B", (int64_t)lnum, (int64_t)nchars); } else { - vim_snprintf((char *)p, (size_t)(IOSIZE - (p - IObuff)), + vim_snprintf((char *)p, (size_t)(IOSIZE - (p - (char_u *)IObuff)), NGETTEXT("%" PRId64 " line, ", "%" PRId64 " lines, ", lnum), (int64_t)lnum); p += STRLEN(p); - vim_snprintf((char *)p, (size_t)(IOSIZE - (p - IObuff)), + vim_snprintf((char *)p, (size_t)(IOSIZE - (p - (char_u *)IObuff)), NGETTEXT("%" PRId64 " byte", "%" PRId64 " bytes", nchars), (int64_t)nchars); } @@ -4189,7 +4189,7 @@ void shorten_buf_fname(buf_T *buf, char_u *dirname, int force) if (buf->b_sfname != buf->b_ffname) { XFREE_CLEAR(buf->b_sfname); } - p = (char *)path_shorten_fname((char_u *)buf->b_ffname, dirname); + p = path_shorten_fname(buf->b_ffname, (char *)dirname); if (p != NULL) { buf->b_sfname = xstrdup(p); buf->b_fname = buf->b_sfname; @@ -4481,7 +4481,7 @@ int put_time(FILE *fd, time_t time_) /// function will (attempts to?) copy the file across if rename fails -- webb /// /// @return -1 for failure, 0 for success -int vim_rename(const char_u *from, const char_u *to) +int vim_rename(const char *from, const char *to) FUNC_ATTR_NONNULL_ALL { int fd_in; @@ -4498,7 +4498,7 @@ int vim_rename(const char_u *from, const char_u *to) // When the names are identical, there is nothing to do. When they refer // to the same file (ignoring case and slash/backslash differences) but // the file name differs we need to go through a temp file. - if (FNAMECMP(from, to) == 0) { + if (path_fnamecmp(from, to) == 0) { if (p_fic && (strcmp(path_tail((char *)from), path_tail((char *)to)) != 0)) { use_tmp_file = true; @@ -4536,13 +4536,13 @@ int vim_rename(const char_u *from, const char_u *to) snprintf(tail, (size_t)((MAXPATHL + 1) - (tail - (char *)tempname - 1)), "%d", n); if (!os_path_exists((char *)tempname)) { - if (os_rename(from, tempname) == OK) { - if (os_rename(tempname, to) == OK) { + if (os_rename((char_u *)from, tempname) == OK) { + if (os_rename(tempname, (char_u *)to) == OK) { return 0; } // Strange, the second step failed. Try moving the // file back and return failure. - (void)os_rename(tempname, from); + (void)os_rename(tempname, (char_u *)from); return -1; } // If it fails for one temp name it will most likely fail @@ -4560,15 +4560,15 @@ int vim_rename(const char_u *from, const char_u *to) os_remove((char *)to); // First try a normal rename, return if it works. - if (os_rename(from, to) == OK) { + if (os_rename((char_u *)from, (char_u *)to) == OK) { return 0; } // Rename() failed, try copying the file. - perm = os_getperm((const char *)from); + perm = os_getperm(from); #ifdef HAVE_ACL // For systems that support ACL: get the ACL from the original file. - acl = mch_get_acl(from); + acl = mch_get_acl((char_u *)from); #endif fd_in = os_open((char *)from, O_RDONLY, 0); if (fd_in < 0) { @@ -4621,7 +4621,7 @@ int vim_rename(const char_u *from, const char_u *to) os_setperm((const char *)to, perm); #endif #ifdef HAVE_ACL - mch_set_acl(to, acl); + mch_set_acl((char_u *)to, acl); mch_free_acl(acl); #endif if (errmsg != NULL) { diff --git a/src/nvim/garray.c b/src/nvim/garray.c index 1afabe4e10..adc3eda5ca 100644 --- a/src/nvim/garray.c +++ b/src/nvim/garray.c @@ -123,7 +123,7 @@ void ga_remove_duplicate_strings(garray_T *gap) // loop over the growing array in reverse for (int i = gap->ga_len - 1; i > 0; i--) { - if (FNAMECMP(fnames[i - 1], fnames[i]) == 0) { + if (path_fnamecmp(fnames[i - 1], fnames[i]) == 0) { xfree(fnames[i]); // close the gap (move all strings one slot lower) diff --git a/src/nvim/globals.h b/src/nvim/globals.h index 84c01e0140..1cd8db6266 100644 --- a/src/nvim/globals.h +++ b/src/nvim/globals.h @@ -670,7 +670,7 @@ EXTERN bool cmd_silent INIT(= false); // don't echo the command line EXTERN int swap_exists_action INIT(= SEA_NONE); ///< For dialog when swap file already exists. EXTERN bool swap_exists_did_quit INIT(= false); ///< Selected "quit" at the dialog. -EXTERN char_u IObuff[IOSIZE]; ///< Buffer for sprintf, I/O, etc. +EXTERN char IObuff[IOSIZE]; ///< Buffer for sprintf, I/O, etc. EXTERN char NameBuff[MAXPATHL]; ///< Buffer for expanding file names EXTERN char msg_buf[MSG_BUF_LEN]; ///< Small buffer for messages EXTERN char os_buf[ ///< Buffer for the os/ layer diff --git a/src/nvim/hardcopy.c b/src/nvim/hardcopy.c index 903349dcae..b530e2c5ec 100644 --- a/src/nvim/hardcopy.c +++ b/src/nvim/hardcopy.c @@ -734,7 +734,7 @@ void ex_hardcopy(exarg_T *eap) sprintf((char *)IObuff, _("Printing page %d (%zu%%)"), page_count + 1 + side, prtpos.bytes_printed * 100 / bytes_to_print); - if (!mch_print_begin_page(IObuff)) { + if (!mch_print_begin_page((char_u *)IObuff)) { goto print_fail; } @@ -744,7 +744,7 @@ void ex_hardcopy(exarg_T *eap) collated_copies + 1, settings.n_collated_copies); } - prt_message(IObuff); + prt_message((char_u *)IObuff); // Output header if required if (prt_header_height() > 0) { @@ -798,13 +798,13 @@ void ex_hardcopy(exarg_T *eap) vim_snprintf((char *)IObuff, IOSIZE, _("Printed: %s"), settings.jobname); - prt_message(IObuff); + prt_message((char_u *)IObuff); } print_fail: if (got_int || settings.user_abort) { - sprintf((char *)IObuff, "%s", _("Printing aborted")); - prt_message(IObuff); + snprintf(IObuff, IOSIZE, "%s", _("Printing aborted")); + prt_message((char_u *)IObuff); } mch_print_end(&settings); @@ -1493,8 +1493,8 @@ static int prt_find_resource(char *name, struct prt_ps_resource_S *resource) // Look for named resource file in runtimepath STRCPY(buffer, "print"); add_pathsep(buffer); - STRLCAT(buffer, name, MAXPATHL); - STRLCAT(buffer, ".ps", MAXPATHL); + xstrlcat(buffer, name, MAXPATHL); + xstrlcat(buffer, ".ps", MAXPATHL); resource->filename[0] = NUL; retval = (do_in_runtimepath(buffer, 0, prt_resource_name, resource->filename) && resource->filename[0] != NUL); diff --git a/src/nvim/help.c b/src/nvim/help.c index 210c7b518c..507c5904b3 100644 --- a/src/nvim/help.c +++ b/src/nvim/help.c @@ -428,7 +428,7 @@ int find_help_tags(const char *arg, int *num_matches, char ***matches, bool keep // completion. // Insert a backslash before '~', '$' and '.' to avoid their // special meaning. - if ((char_u *)d - IObuff > IOSIZE - 10) { // getting too long!? + if (d - IObuff > IOSIZE - 10) { // getting too long!? break; } switch (*s) { @@ -459,7 +459,7 @@ int find_help_tags(const char *arg, int *num_matches, char ***matches, bool keep if (*s < ' ' || (*s == '^' && s[1] && (ASCII_ISALPHA(s[1]) || vim_strchr("?@[\\]^", s[1]) != NULL))) { - if ((char_u *)d > IObuff && d[-1] != '_' && d[-1] != '\\') { + if (d > IObuff && d[-1] != '_' && d[-1] != '\\') { *d++ = '_'; // prepend a '_' to make x_CTRL-x } STRCPY(d, "CTRL-"); @@ -513,15 +513,15 @@ int find_help_tags(const char *arg, int *num_matches, char ***matches, bool keep *d = NUL; if (*IObuff == '`') { - if ((char_u *)d > IObuff + 2 && d[-1] == '`') { + if (d > IObuff + 2 && d[-1] == '`') { // remove the backticks from `command` memmove(IObuff, IObuff + 1, STRLEN(IObuff)); d[-2] = NUL; - } else if ((char_u *)d > IObuff + 3 && d[-2] == '`' && d[-1] == ',') { + } else if (d > IObuff + 3 && d[-2] == '`' && d[-1] == ',') { // remove the backticks and comma from `command`, memmove(IObuff, IObuff + 1, STRLEN(IObuff)); d[-3] = NUL; - } else if ((char_u *)d > IObuff + 4 && d[-3] == '`' + } else if (d > IObuff + 4 && d[-3] == '`' && d[-2] == '\\' && d[-1] == '.') { // remove the backticks and dot from `command`\. memmove(IObuff, IObuff + 1, STRLEN(IObuff)); @@ -687,8 +687,8 @@ void fix_help_buffer(void) // In the "help.txt" and "help.abx" file, add the locally added help // files. This uses the very first line in the help file. char *const fname = path_tail(curbuf->b_fname); - if (FNAMECMP(fname, "help.txt") == 0 - || (FNAMENCMP(fname, "help.", 5) == 0 + if (path_fnamecmp(fname, "help.txt") == 0 + || (path_fnamencmp(fname, "help.", 5) == 0 && ASCII_ISALPHA(fname[5]) && ASCII_ISALPHA(fname[6]) && TOLOWER_ASC(fname[7]) == 'x' @@ -715,8 +715,8 @@ void fix_help_buffer(void) // Find all "doc/ *.txt" files in this directory. if (!add_pathsep((char *)NameBuff) - || STRLCAT(NameBuff, "doc/*.??[tx]", // NOLINT - sizeof(NameBuff)) >= MAXPATHL) { + || xstrlcat(NameBuff, "doc/*.??[tx]", // NOLINT + sizeof(NameBuff)) >= MAXPATHL) { emsg(_(e_fnametoolong)); continue; } @@ -746,18 +746,18 @@ void fix_help_buffer(void) if (e1 == NULL || e2 == NULL) { continue; } - if (FNAMECMP(e1, ".txt") != 0 - && FNAMECMP(e1, fname + 4) != 0) { + if (path_fnamecmp(e1, ".txt") != 0 + && path_fnamecmp(e1, fname + 4) != 0) { // Not .txt and not .abx, remove it. XFREE_CLEAR(fnames[i1]); continue; } if (e1 - f1 != e2 - f2 - || FNAMENCMP(f1, f2, e1 - f1) != 0) { + || path_fnamencmp(f1, f2, (size_t)(e1 - f1)) != 0) { continue; } - if (FNAMECMP(e1, ".txt") == 0 - && FNAMECMP(e2, fname + 4) == 0) { + if (path_fnamecmp(e1, ".txt") == 0 + && path_fnamecmp(e2, fname + 4) == 0) { // use .abx instead of .txt XFREE_CLEAR(fnames[i1]); } @@ -772,7 +772,7 @@ void fix_help_buffer(void) if (fd == NULL) { continue; } - vim_fgets(IObuff, IOSIZE, fd); + vim_fgets((char_u *)IObuff, IOSIZE, fd); if (IObuff[0] == '*' && (s = vim_strchr((char *)IObuff + 1, '*')) != NULL) { @@ -819,7 +819,7 @@ void fix_help_buffer(void) convert_setup(&vc, NULL, NULL); ml_append(lnum, cp, (colnr_T)0, false); - if ((char_u *)cp != IObuff) { + if (cp != IObuff) { xfree(cp); } lnum++; @@ -871,8 +871,8 @@ static void helptags_one(char *dir, const char *ext, const char *tagfname, bool // Find all *.txt files. size_t dirlen = STRLCPY(NameBuff, dir, sizeof(NameBuff)); if (dirlen >= MAXPATHL - || STRLCAT(NameBuff, "/**/*", sizeof(NameBuff)) >= MAXPATHL // NOLINT - || STRLCAT(NameBuff, ext, sizeof(NameBuff)) >= MAXPATHL) { + || xstrlcat(NameBuff, "/**/*", sizeof(NameBuff)) >= MAXPATHL // NOLINT + || xstrlcat(NameBuff, ext, sizeof(NameBuff)) >= MAXPATHL) { emsg(_(e_fnametoolong)); return; } @@ -896,7 +896,7 @@ static void helptags_one(char *dir, const char *ext, const char *tagfname, bool // Do this before scanning through all the files. memcpy(NameBuff, dir, dirlen + 1); if (!add_pathsep((char *)NameBuff) - || STRLCAT(NameBuff, tagfname, sizeof(NameBuff)) >= MAXPATHL) { + || xstrlcat(NameBuff, tagfname, sizeof(NameBuff)) >= MAXPATHL) { emsg(_(e_fnametoolong)); return; } @@ -931,7 +931,7 @@ static void helptags_one(char *dir, const char *ext, const char *tagfname, bool const char *const fname = files[fi] + dirlen + 1; bool firstline = true; - while (!vim_fgets(IObuff, IOSIZE, fd) && !got_int) { + while (!vim_fgets((char_u *)IObuff, IOSIZE, fd) && !got_int) { if (firstline) { // Detect utf-8 file by a non-ASCII char in the first line. TriState this_utf8 = kNone; @@ -974,7 +974,7 @@ static void helptags_one(char *dir, const char *ext, const char *tagfname, bool // characters, there is white space before it and is // followed by a white character or end-of-line. if (s == p2 - && ((char_u *)p1 == IObuff || p1[-1] == ' ' || p1[-1] == '\t') + && (p1 == IObuff || p1[-1] == ' ' || p1[-1] == '\t') && (vim_strchr(" \t\n\r", s[1]) != NULL || s[1] == '\0')) { *p2 = '\0'; @@ -1067,7 +1067,7 @@ static void do_helptags(char *dirname, bool add_help_tags, bool ignore_writeerr) // Get a list of all files in the help directory and in subdirectories. STRLCPY(NameBuff, dirname, sizeof(NameBuff)); if (!add_pathsep((char *)NameBuff) - || STRLCAT(NameBuff, "**", sizeof(NameBuff)) >= MAXPATHL) { + || xstrlcat(NameBuff, "**", sizeof(NameBuff)) >= MAXPATHL) { emsg(_(e_fnametoolong)); return; } diff --git a/src/nvim/indent.c b/src/nvim/indent.c index af5bcd7d2a..0f7a5a8e44 100644 --- a/src/nvim/indent.c +++ b/src/nvim/indent.c @@ -721,7 +721,7 @@ int get_number_indent(linenr_T lnum) // start matching for the flp beyond any comment leader... if (vim_regexec(®match, ml_get(lnum) + lead_len, (colnr_T)0)) { pos.lnum = lnum; - pos.col = (colnr_T)(*regmatch.endp - (char_u *)ml_get(lnum)); + pos.col = (colnr_T)(*regmatch.endp - ml_get(lnum)); pos.coladd = 0; } vim_regfree(regmatch.regprog); diff --git a/src/nvim/insexpand.c b/src/nvim/insexpand.c index 7e229d5cb6..a5e7929525 100644 --- a/src/nvim/insexpand.c +++ b/src/nvim/insexpand.c @@ -665,7 +665,7 @@ static char_u *ins_compl_infercase_gettext(char_u *str, int char_len, int compl_ } *p = NUL; - return IObuff; + return (char_u *)IObuff; } /// This is like ins_compl_add(), but if 'ic' and 'inf' are set, then the @@ -1443,20 +1443,20 @@ static void ins_compl_files(int count, char **files, int thesaurus, int flags, r while (!got_int && !compl_interrupted && !vim_fgets(buf, LSIZE, fp)) { ptr = buf; while (vim_regexec(regmatch, (char *)buf, (colnr_T)(ptr - buf))) { - ptr = regmatch->startp[0]; + ptr = (char_u *)regmatch->startp[0]; if (ctrl_x_mode_line_or_eval()) { ptr = find_line_end(ptr); } else { ptr = find_word_end(ptr); } - add_r = ins_compl_add_infercase(regmatch->startp[0], - (int)(ptr - regmatch->startp[0]), + add_r = ins_compl_add_infercase((char_u *)regmatch->startp[0], + (int)(ptr - (char_u *)regmatch->startp[0]), p_ic, (char_u *)files[i], *dir, false); if (thesaurus) { // For a thesaurus, add all the words in the line ptr = buf; add_r = thesaurus_add_words_in_line(files[i], &ptr, *dir, - regmatch->startp[0]); + (char_u *)regmatch->startp[0]); } if (add_r == OK) { // if dir was BACKWARD then honor it just once @@ -2980,7 +2980,7 @@ static char_u *ins_comp_get_next_word_or_line(buf_T *ins_buf, pos_T *cur_match_p *cont_s_ipos = true; } IObuff[len] = NUL; - ptr = IObuff; + ptr = (char_u *)IObuff; } if (len == compl_length) { return NULL; diff --git a/src/nvim/lua/stdlib.c b/src/nvim/lua/stdlib.c index 3051017846..9b1890403e 100644 --- a/src/nvim/lua/stdlib.c +++ b/src/nvim/lua/stdlib.c @@ -60,8 +60,8 @@ static int regex_match(lua_State *lstate, regprog_T **prog, char_u *str) *prog = rm.regprog; if (match) { - lua_pushinteger(lstate, (lua_Integer)(rm.startp[0] - str)); - lua_pushinteger(lstate, (lua_Integer)(rm.endp[0] - str)); + lua_pushinteger(lstate, (lua_Integer)(rm.startp[0] - (char *)str)); + lua_pushinteger(lstate, (lua_Integer)(rm.endp[0] - (char *)str)); return 2; } return 0; diff --git a/src/nvim/mark.c b/src/nvim/mark.c index a6d0a68323..6f8aecb3ff 100644 --- a/src/nvim/mark.c +++ b/src/nvim/mark.c @@ -665,8 +665,8 @@ static void fname2fnum(xfmark_T *fm) } // Try to shorten the file name. - os_dirname(IObuff, IOSIZE); - p = path_shorten_fname((char_u *)NameBuff, IObuff); + os_dirname((char_u *)IObuff, IOSIZE); + p = (char_u *)path_shorten_fname(NameBuff, (char *)IObuff); // buflist_new() will call fmarks_check_names() (void)buflist_new((char *)NameBuff, (char *)p, (linenr_T)1, 0); @@ -686,21 +686,21 @@ void fmarks_check_names(buf_T *buf) } for (i = 0; i < NGLOBALMARKS; i++) { - fmarks_check_one(&namedfm[i], name, buf); + fmarks_check_one(&namedfm[i], (char *)name, buf); } FOR_ALL_WINDOWS_IN_TAB(wp, curtab) { for (i = 0; i < wp->w_jumplistlen; i++) { - fmarks_check_one(&wp->w_jumplist[i], name, buf); + fmarks_check_one(&wp->w_jumplist[i], (char *)name, buf); } } } -static void fmarks_check_one(xfmark_T *fm, char_u *name, buf_T *buf) +static void fmarks_check_one(xfmark_T *fm, char *name, buf_T *buf) { if (fm->fmark.fnum == 0 && fm->fname != NULL - && FNAMECMP(name, fm->fname) == 0) { + && path_fnamecmp(name, fm->fname) == 0) { fm->fmark.fnum = buf->b_fnum; XFREE_CLEAR(fm->fname); } diff --git a/src/nvim/memline.c b/src/nvim/memline.c index c288703328..9d1ad5903d 100644 --- a/src/nvim/memline.c +++ b/src/nvim/memline.c @@ -349,7 +349,7 @@ void ml_setname(buf_T *buf) { bool success = false; memfile_T *mfp; - char_u *fname; + char *fname; char *dirp; mfp = buf->b_ml.ml_mfp; @@ -369,7 +369,7 @@ void ml_setname(buf_T *buf) if (*dirp == NUL) { // tried all directories, fail break; } - fname = (char_u *)findswapname(buf, &dirp, mfp->mf_fname, &found_existing_dir); + fname = findswapname(buf, &dirp, mfp->mf_fname, &found_existing_dir); // alloc's fname if (dirp == NULL) { // out of memory break; @@ -379,7 +379,7 @@ void ml_setname(buf_T *buf) } // if the file name is the same we don't have to do anything - if (FNAMECMP(fname, mfp->mf_fname) == 0) { + if (path_fnamecmp(fname, mfp->mf_fname) == 0) { xfree(fname); success = true; break; @@ -391,10 +391,10 @@ void ml_setname(buf_T *buf) } // try to rename the swap file - if (vim_rename((char_u *)mfp->mf_fname, fname) == 0) { + if (vim_rename(mfp->mf_fname, fname) == 0) { success = true; mf_free_fnames(mfp); - mf_set_fnames(mfp, (char *)fname); + mf_set_fnames(mfp, fname); ml_upd_block0(buf, UB_SAME_DIR); break; } @@ -3273,7 +3273,7 @@ static char *findswapname(buf_T *buf, char **dirp, char *old_fname, bool *found_ } // A file name equal to old_fname is OK to use. - if (old_fname != NULL && FNAMECMP(fname, old_fname) == 0) { + if (old_fname != NULL && path_fnamecmp(fname, old_fname) == 0) { break; } @@ -3298,8 +3298,8 @@ static char *findswapname(buf_T *buf, char **dirp, char *old_fname, bool *found_ // buffer don't compare the directory names, they can // have a different mountpoint. if (b0.b0_flags & B0_SAME_DIR) { - if (FNAMECMP(path_tail((char *)buf->b_ffname), - path_tail((char *)b0.b0_fname)) != 0 + if (path_fnamecmp(path_tail(buf->b_ffname), + path_tail((char *)b0.b0_fname)) != 0 || !same_directory((char_u *)fname, (char_u *)buf->b_ffname)) { // Symlinks may point to the same file even // when the name differs, need to check the diff --git a/src/nvim/option.c b/src/nvim/option.c index dbc2102541..ab4db30aaf 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -654,8 +654,8 @@ void set_init_3(void) // Default for p_sp is "| tee", for p_srr is ">". // For known shells it is changed here to include stderr. // - if (FNAMECMP(p, "csh") == 0 - || FNAMECMP(p, "tcsh") == 0) { + if (path_fnamecmp(p, "csh") == 0 + || path_fnamecmp(p, "tcsh") == 0) { if (do_sp) { p_sp = "|& tee"; options[idx_sp].def_val = p_sp; @@ -664,16 +664,16 @@ void set_init_3(void) p_srr = ">&"; options[idx_srr].def_val = p_srr; } - } else if (FNAMECMP(p, "sh") == 0 - || FNAMECMP(p, "ksh") == 0 - || FNAMECMP(p, "mksh") == 0 - || FNAMECMP(p, "pdksh") == 0 - || FNAMECMP(p, "zsh") == 0 - || FNAMECMP(p, "zsh-beta") == 0 - || FNAMECMP(p, "bash") == 0 - || FNAMECMP(p, "fish") == 0 - || FNAMECMP(p, "ash") == 0 - || FNAMECMP(p, "dash") == 0) { + } else if (path_fnamecmp(p, "sh") == 0 + || path_fnamecmp(p, "ksh") == 0 + || path_fnamecmp(p, "mksh") == 0 + || path_fnamecmp(p, "pdksh") == 0 + || path_fnamecmp(p, "zsh") == 0 + || path_fnamecmp(p, "zsh-beta") == 0 + || path_fnamecmp(p, "bash") == 0 + || path_fnamecmp(p, "fish") == 0 + || path_fnamecmp(p, "ash") == 0 + || path_fnamecmp(p, "dash") == 0) { // Always use POSIX shell style redirection if we reach this if (do_sp) { p_sp = "2>&1| tee"; @@ -1237,19 +1237,19 @@ int do_set(char *arg, int opt_flags) *errbuf = NUL; i = getdigits_int(&arg, true, 0); if (i & 1) { - STRLCAT(errbuf, "b,", sizeof(errbuf)); + xstrlcat(errbuf, "b,", sizeof(errbuf)); } if (i & 2) { - STRLCAT(errbuf, "s,", sizeof(errbuf)); + xstrlcat(errbuf, "s,", sizeof(errbuf)); } if (i & 4) { - STRLCAT(errbuf, "h,l,", sizeof(errbuf)); + xstrlcat(errbuf, "h,l,", sizeof(errbuf)); } if (i & 8) { - STRLCAT(errbuf, "<,>,", sizeof(errbuf)); + xstrlcat(errbuf, "<,>,", sizeof(errbuf)); } if (i & 16) { - STRLCAT(errbuf, "[,],", sizeof(errbuf)); + xstrlcat(errbuf, "[,],", sizeof(errbuf)); } save_arg = (char_u *)arg; arg = errbuf; 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)) { diff --git a/src/nvim/path.c b/src/nvim/path.c index accd7badbb..38112be3ce 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -73,7 +73,7 @@ FileComparison path_full_compare(char *const s1, char *const s2, const bool chec if (checkname) { vim_FullName(exp1, full1, MAXPATHL, false); vim_FullName(s2, full2, MAXPATHL, false); - if (FNAMECMP(full1, full2) == 0) { + if (path_fnamecmp(full1, full2) == 0) { return kEqualFileNames; } } @@ -331,6 +331,12 @@ bool dir_of_file_exists(char_u *fname) /// Compare two file names /// +/// On some systems case in a file name does not matter, on others it does. +/// +/// @note Does not account for maximum name lengths and things like "../dir", +/// thus it is not 100% accurate. OS may also use different algorithm for +/// case-insensitive comparison. +/// /// Handles '/' and '\\' correctly and deals with &fileignorecase option. /// /// @param[in] fname1 First file name. @@ -575,7 +581,7 @@ bool path_has_exp_wildcard(const char_u *p) static size_t path_expand(garray_T *gap, const char_u *path, int flags) FUNC_ATTR_NONNULL_ALL { - return do_path_expand(gap, path, 0, flags, false); + return do_path_expand(gap, (char *)path, 0, flags, false); } static const char *scandir_next_with_dots(Directory *dir) @@ -596,7 +602,7 @@ static const char *scandir_next_with_dots(Directory *dir) /// Implementation of path_expand(). /// /// Chars before `path + wildoff` do not get expanded. -static size_t do_path_expand(garray_T *gap, const char_u *path, size_t wildoff, int flags, +static size_t do_path_expand(garray_T *gap, const char *path, size_t wildoff, int flags, bool didstar) FUNC_ATTR_NONNULL_ALL { @@ -623,18 +629,18 @@ static size_t do_path_expand(garray_T *gap, const char_u *path, size_t wildoff, char_u *p = buf; char_u *s = buf; char_u *e = NULL; - const char_u *path_end = path; + const char_u *path_end = (char_u *)path; while (*path_end != NUL) { // May ignore a wildcard that has a backslash before it; it will // be removed by rem_backslash() or file_pat_to_reg_pat() below. - if (path_end >= path + wildoff && rem_backslash((char *)path_end)) { + if (path_end >= (char_u *)path + wildoff && rem_backslash((char *)path_end)) { *p++ = *path_end++; } else if (vim_ispathsep_nocolon(*path_end)) { if (e != NULL) { break; } s = p + 1; - } else if (path_end >= path + wildoff + } else if (path_end >= (char_u *)path + wildoff && (vim_strchr("*?[{~$", *path_end) != NULL #ifndef WIN32 || (!p_fic && (flags & EW_ICASE) && mb_isalpha(utf_ptr2char((char *)path_end))) @@ -704,7 +710,7 @@ static size_t do_path_expand(garray_T *gap, const char_u *path, size_t wildoff, && *path_end == '/') { STRCPY(s, path_end + 1); stardepth++; - (void)do_path_expand(gap, buf, (size_t)(s - buf), flags, true); + (void)do_path_expand(gap, (char *)buf, (size_t)(s - buf), flags, true); stardepth--; } *s = NUL; @@ -713,17 +719,17 @@ static size_t do_path_expand(garray_T *gap, const char_u *path, size_t wildoff, char *dirpath = (*buf == NUL ? "." : (char *)buf); if (os_file_is_readable(dirpath) && os_scandir(&dir, dirpath)) { // Find all matching entries. - char_u *name; + char *name; scandir_next_with_dots(NULL); // initialize - while (!got_int && (name = (char_u *)scandir_next_with_dots(&dir)) != NULL) { + while (!got_int && (name = (char *)scandir_next_with_dots(&dir)) != NULL) { if ((name[0] != '.' || starts_with_dot || ((flags & EW_DODOT) && name[1] != NUL && (name[1] != '.' || name[2] != NUL))) // -V557 - && ((regmatch.regprog != NULL && vim_regexec(®match, (char *)name, 0)) + && ((regmatch.regprog != NULL && vim_regexec(®match, name, 0)) || ((flags & EW_NOTWILD) - && FNAMENCMP(path + (s - buf), name, e - s) == 0))) { + && path_fnamencmp(path + (s - buf), name, (size_t)(e - s)) == 0))) { STRCPY(s, name); len = STRLEN(buf); @@ -733,7 +739,7 @@ static size_t do_path_expand(garray_T *gap, const char_u *path, size_t wildoff, STRCPY(buf + len, "/**"); // NOLINT STRCPY(buf + len + 3, path_end); stardepth++; - (void)do_path_expand(gap, buf, len + 1, flags, true); + (void)do_path_expand(gap, (char *)buf, len + 1, flags, true); stardepth--; } @@ -741,7 +747,7 @@ static size_t do_path_expand(garray_T *gap, const char_u *path, size_t wildoff, if (path_has_exp_wildcard(path_end)) { // handle more wildcards // need to expand another component of the path // remove backslashes for the remaining components only - (void)do_path_expand(gap, buf, len + 1, flags, false); + (void)do_path_expand(gap, (char *)buf, len + 1, flags, false); } else { FileInfo file_info; @@ -797,9 +803,9 @@ static int find_previous_pathsep(char_u *path, char_u **psep) /// Returns true if "maybe_unique" is unique wrt other_paths in "gap". /// "maybe_unique" is the end portion of "((char_u **)gap->ga_data)[i]". -static bool is_unique(char_u *maybe_unique, garray_T *gap, int i) +static bool is_unique(char *maybe_unique, garray_T *gap, int i) { - char_u **other_paths = (char_u **)gap->ga_data; + char **other_paths = gap->ga_data; for (int j = 0; j < gap->ga_len; j++) { if (j == i) { @@ -810,8 +816,8 @@ static bool is_unique(char_u *maybe_unique, garray_T *gap, int i) if (other_path_len < candidate_len) { continue; // it's different when it's shorter } - char_u *rival = other_paths[j] + other_path_len - candidate_len; - if (FNAMECMP(maybe_unique, rival) == 0 + char *rival = other_paths[j] + other_path_len - candidate_len; + if (path_fnamecmp(maybe_unique, rival) == 0 && (rival == other_paths[j] || vim_ispathsep(*(rival - 1)))) { return false; // match } @@ -950,9 +956,9 @@ static void uniquefy_paths(garray_T *gap, char_u *pattern) return; } - char_u *curdir = xmalloc(MAXPATHL); - os_dirname(curdir, MAXPATHL); - expand_path_option(curdir, &path_ga); + char *curdir = xmalloc(MAXPATHL); + os_dirname((char_u *)curdir, MAXPATHL); + expand_path_option((char_u *)curdir, &path_ga); in_curdir = xcalloc((size_t)gap->ga_len, sizeof(char_u *)); @@ -964,7 +970,7 @@ static void uniquefy_paths(garray_T *gap, char_u *pattern) char *path_cutoff; len = STRLEN(path); - is_in_curdir = FNAMENCMP(curdir, path, dir_end - path) == 0 + is_in_curdir = path_fnamencmp(curdir, path, (size_t)(dir_end - path)) == 0 && curdir[dir_end - path] == NUL; if (is_in_curdir) { in_curdir[i] = xstrdup(path); @@ -980,7 +986,7 @@ static void uniquefy_paths(garray_T *gap, char_u *pattern) && vim_ispathsep_nocolon(pattern[2]) && path_cutoff != NULL && vim_regexec(®match, path_cutoff, (colnr_T)0) - && is_unique((char_u *)path_cutoff, gap, i)) { + && is_unique(path_cutoff, gap, i)) { sort_again = true; memmove(path, path_cutoff, STRLEN(path_cutoff) + 1); } else { @@ -989,7 +995,7 @@ static void uniquefy_paths(garray_T *gap, char_u *pattern) pathsep_p = path + len - 1; while (find_previous_pathsep((char_u *)path, (char_u **)&pathsep_p)) { if (vim_regexec(®match, pathsep_p + 1, (colnr_T)0) - && is_unique((char_u *)pathsep_p + 1, gap, i) + && is_unique(pathsep_p + 1, gap, i) && path_cutoff != NULL && pathsep_p + 1 >= path_cutoff) { sort_again = true; memmove(path, pathsep_p + 1, STRLEN(pathsep_p)); @@ -1009,7 +1015,7 @@ static void uniquefy_paths(garray_T *gap, char_u *pattern) // c:\foo\bar\file.txt c:\foo\bar .\file.txt // /file.txt / /file.txt // c:\file.txt c:\ .\file.txt - short_name = (char *)path_shorten_fname((char_u *)path, curdir); + short_name = path_shorten_fname(path, curdir); if (short_name != NULL && short_name > path + 1) { STRCPY(path, "."); add_pathsep(path); @@ -1030,11 +1036,11 @@ static void uniquefy_paths(garray_T *gap, char_u *pattern) // If the {filename} is not unique, change it to ./{filename}. // Else reduce it to {filename} - short_name = (char *)path_shorten_fname((char_u *)path, curdir); + short_name = path_shorten_fname(path, curdir); if (short_name == NULL) { short_name = path; } - if (is_unique((char_u *)short_name, gap, i)) { + if (is_unique(short_name, gap, i)) { STRCPY(fnames[i], short_name); continue; } @@ -2037,7 +2043,7 @@ char_u *path_try_shorten_fname(char_u *full_path) char_u *p = full_path; if (os_dirname(dirname, MAXPATHL) == OK) { - p = path_shorten_fname(full_path, dirname); + p = (char_u *)path_shorten_fname((char *)full_path, (char *)dirname); if (p == NULL || *p == NUL) { p = full_path; } @@ -2053,7 +2059,7 @@ char_u *path_try_shorten_fname(char_u *full_path) /// @return /// - Pointer into `full_path` if shortened. /// - NULL if no shorter name is possible. -char_u *path_shorten_fname(char_u *full_path, char_u *dir_name) +char *path_shorten_fname(char *full_path, char *dir_name) { if (full_path == NULL) { return NULL; @@ -2063,17 +2069,17 @@ char_u *path_shorten_fname(char_u *full_path, char_u *dir_name) size_t len = STRLEN(dir_name); // If dir_name is a path head, full_path can always be made relative. - if (len == (size_t)path_head_length() && is_path_head(dir_name)) { + if (len == (size_t)path_head_length() && is_path_head((char_u *)dir_name)) { return full_path + len; } // If full_path and dir_name do not match, it's impossible to make one // relative to the other. - if (FNAMENCMP(dir_name, full_path, len) != 0) { + if (path_fnamencmp(dir_name, full_path, len) != 0) { return NULL; } - char_u *p = full_path + len; + char_u *p = (char_u *)full_path + len; // If *p is not pointing to a path separator, this means that full_path's // last directory name is longer than *dir_name's last directory, so they @@ -2082,7 +2088,7 @@ char_u *path_shorten_fname(char_u *full_path, char_u *dir_name) return NULL; } - return p + 1; + return (char *)p + 1; } /// Invoke expand_wildcards() for one pattern @@ -2200,7 +2206,7 @@ int expand_wildcards(int num_pat, char **pat, int *num_files, char ***files, int if (*num_files > 1 && !got_int) { non_suf_match = 0; for (i = 0; i < *num_files; i++) { - if (!match_suffix((char_u *)(*files)[i])) { + if (!match_suffix((*files)[i])) { // Move the name without matching suffix to the front of the list. p = (char_u *)(*files)[i]; for (j = i; j > non_suf_match; j--) { @@ -2220,27 +2226,27 @@ int expand_wildcards(int num_pat, char **pat, int *num_files, char ***files, int return retval; } -/// Return true if "fname" matches with an entry in 'suffixes'. -int match_suffix(char_u *fname) +/// @return true if "fname" matches with an entry in 'suffixes'. +int match_suffix(char *fname) { #define MAXSUFLEN 30 // maximum length of a file suffix - char_u suf_buf[MAXSUFLEN]; + char suf_buf[MAXSUFLEN]; size_t fnamelen = STRLEN(fname); size_t setsuflen = 0; for (char_u *setsuf = p_su; *setsuf;) { setsuflen = copy_option_part((char **)&setsuf, (char *)suf_buf, MAXSUFLEN, ".,"); if (setsuflen == 0) { - char_u *tail = (char_u *)path_tail((char *)fname); + char *tail = path_tail(fname); // empty entry: match name without a '.' - if (vim_strchr((char *)tail, '.') == NULL) { + if (vim_strchr(tail, '.') == NULL) { setsuflen = 1; break; } } else { if (fnamelen >= setsuflen - && FNAMENCMP(suf_buf, fname + fnamelen - setsuflen, setsuflen) == 0) { + && path_fnamencmp(suf_buf, fname + fnamelen - setsuflen, setsuflen) == 0) { break; } setsuflen = 0; @@ -2434,8 +2440,8 @@ void path_guess_exepath(const char *argv0, char *buf, size_t bufsize) continue; } STRLCPY(NameBuff, dir, dir_len + 1); - STRLCAT(NameBuff, PATHSEPSTR, sizeof(NameBuff)); - STRLCAT(NameBuff, argv0, sizeof(NameBuff)); + xstrlcat(NameBuff, PATHSEPSTR, sizeof(NameBuff)); + xstrlcat(NameBuff, argv0, sizeof(NameBuff)); if (os_can_exe((char *)NameBuff, NULL, false)) { xstrlcpy(buf, (char *)NameBuff, bufsize); return; diff --git a/src/nvim/profile.c b/src/nvim/profile.c index 9957224351..50a8a371f5 100644 --- a/src/nvim/profile.c +++ b/src/nvim/profile.c @@ -728,7 +728,7 @@ static void script_dump_profile(FILE *fd) // Keep going till the end of file, so that trailing // continuation lines are listed. for (int i = 0;; i++) { - if (vim_fgets(IObuff, IOSIZE, sfd)) { + if (vim_fgets((char_u *)IObuff, IOSIZE, sfd)) { break; } // When a line has been truncated, append NL, taking care diff --git a/src/nvim/quickfix.c b/src/nvim/quickfix.c index 0dcbcf56b1..9494308ef0 100644 --- a/src/nvim/quickfix.c +++ b/src/nvim/quickfix.c @@ -1242,10 +1242,10 @@ static int qf_parse_fmt_f(regmatch_T *rmp, int midx, qffields_T *fields, int pre } // Expand ~/file and $HOME/file to full path. - char c = (char)(*rmp->endp[midx]); + char c = *rmp->endp[midx]; *rmp->endp[midx] = NUL; - expand_env((char *)rmp->startp[midx], fields->namebuf, CMDBUFFSIZE); - *rmp->endp[midx] = (char_u)c; + expand_env(rmp->startp[midx], fields->namebuf, CMDBUFFSIZE); + *rmp->endp[midx] = c; // For separate filename patterns (%O, %P and %Q), the specified file // should exist. @@ -1264,7 +1264,7 @@ static int qf_parse_fmt_n(regmatch_T *rmp, int midx, qffields_T *fields) if (rmp->startp[midx] == NULL) { return QF_FAIL; } - fields->enr = (int)atol((char *)rmp->startp[midx]); + fields->enr = (int)atol(rmp->startp[midx]); return QF_OK; } @@ -1275,7 +1275,7 @@ static int qf_parse_fmt_l(regmatch_T *rmp, int midx, qffields_T *fields) if (rmp->startp[midx] == NULL) { return QF_FAIL; } - fields->lnum = (linenr_T)atol((char *)rmp->startp[midx]); + fields->lnum = (linenr_T)atol(rmp->startp[midx]); return QF_OK; } @@ -1286,7 +1286,7 @@ static int qf_parse_fmt_e(regmatch_T *rmp, int midx, qffields_T *fields) if (rmp->startp[midx] == NULL) { return QF_FAIL; } - fields->end_lnum = (linenr_T)atol((char *)rmp->startp[midx]); + fields->end_lnum = (linenr_T)atol(rmp->startp[midx]); return QF_OK; } @@ -1297,7 +1297,7 @@ static int qf_parse_fmt_c(regmatch_T *rmp, int midx, qffields_T *fields) if (rmp->startp[midx] == NULL) { return QF_FAIL; } - fields->col = (int)atol((char *)rmp->startp[midx]); + fields->col = (int)atol(rmp->startp[midx]); return QF_OK; } @@ -1308,7 +1308,7 @@ static int qf_parse_fmt_k(regmatch_T *rmp, int midx, qffields_T *fields) if (rmp->startp[midx] == NULL) { return QF_FAIL; } - fields->end_col = (int)atol((char *)rmp->startp[midx]); + fields->end_col = (int)atol(rmp->startp[midx]); return QF_OK; } @@ -1319,7 +1319,7 @@ static int qf_parse_fmt_t(regmatch_T *rmp, int midx, qffields_T *fields) if (rmp->startp[midx] == NULL) { return QF_FAIL; } - fields->type = (char)(*rmp->startp[midx]); + fields->type = *rmp->startp[midx]; return QF_OK; } @@ -1360,7 +1360,7 @@ static int qf_parse_fmt_r(regmatch_T *rmp, int midx, char **tail) if (rmp->startp[midx] == NULL) { return QF_FAIL; } - *tail = (char *)rmp->startp[midx]; + *tail = rmp->startp[midx]; return QF_OK; } @@ -1372,7 +1372,7 @@ static int qf_parse_fmt_p(regmatch_T *rmp, int midx, qffields_T *fields) return QF_FAIL; } fields->col = 0; - for (char *match_ptr = (char *)rmp->startp[midx]; (char_u *)match_ptr != rmp->endp[midx]; + for (char *match_ptr = rmp->startp[midx]; match_ptr != rmp->endp[midx]; match_ptr++) { fields->col++; if (*match_ptr == TAB) { @@ -1392,7 +1392,7 @@ static int qf_parse_fmt_v(regmatch_T *rmp, int midx, qffields_T *fields) if (rmp->startp[midx] == NULL) { return QF_FAIL; } - fields->col = (int)atol((char *)rmp->startp[midx]); + fields->col = (int)atol(rmp->startp[midx]); fields->use_viscol = true; return QF_OK; } @@ -1409,7 +1409,7 @@ static int qf_parse_fmt_s(regmatch_T *rmp, int midx, qffields_T *fields) len = CMDBUFFSIZE - 5; } STRCPY(fields->pattern, "^\\V"); - STRLCAT(fields->pattern, rmp->startp[midx], len + 4); + xstrlcat(fields->pattern, rmp->startp[midx], len + 4); fields->pattern[len + 3] = '\\'; fields->pattern[len + 4] = '$'; fields->pattern[len + 5] = NUL; @@ -1428,7 +1428,7 @@ static int qf_parse_fmt_o(regmatch_T *rmp, int midx, qffields_T *fields) if (dsize > CMDBUFFSIZE) { dsize = CMDBUFFSIZE; } - STRLCAT(fields->module, rmp->startp[midx], dsize); + xstrlcat(fields->module, rmp->startp[midx], dsize); return QF_OK; } @@ -3074,7 +3074,7 @@ static void qf_list_entry(qfline_T *qfp, int qf_idx, bool cursel) } msg_puts(" "); - char_u *tbuf = IObuff; + char *tbuf = IObuff; size_t tbuflen = IOSIZE; size_t len = STRLEN(qfp->qf_text) + 3; @@ -3088,8 +3088,8 @@ static void qf_list_entry(qfline_T *qfp, int qf_idx, bool cursel) // with ^^^^. qf_fmt_text((fname != NULL || qfp->qf_lnum != 0) ? skipwhite(qfp->qf_text) : qfp->qf_text, - (char *)tbuf, (int)tbuflen); - msg_prt_line((char *)tbuf, false); + tbuf, (int)tbuflen); + msg_prt_line(tbuf, false); if (tbuf != IObuff) { xfree(tbuf); @@ -3236,7 +3236,7 @@ static void qf_msg(qf_info_T *qi, int which, char *lead) memset(buf + len, ' ', 34 - len); buf[34] = NUL; } - STRLCAT(buf, title, IOSIZE); + xstrlcat(buf, title, IOSIZE); } trunc_string(buf, buf, Columns - 1, IOSIZE); msg(buf); @@ -3965,7 +3965,7 @@ static int qf_buf_add_line(qf_list_T *qfl, buf_T *buf, linenr_T lnum, const qfli (char *)IObuff + len, IOSIZE - len); } - if (ml_append_buf(buf, lnum, IObuff, + if (ml_append_buf(buf, lnum, (char_u *)IObuff, (colnr_T)STRLEN(IObuff) + 1, false) == FAIL) { return FAIL; } @@ -6948,7 +6948,7 @@ static void hgr_search_file(qf_list_T *qfl, char *fname, regmatch_T *p_regmatch) } linenr_T lnum = 1; - while (!vim_fgets(IObuff, IOSIZE, fd) && !got_int) { + while (!vim_fgets((char_u *)IObuff, IOSIZE, fd) && !got_int) { char *line = (char *)IObuff; if (vim_regexec(p_regmatch, line, (colnr_T)0)) { @@ -6967,8 +6967,8 @@ static void hgr_search_file(qf_list_T *qfl, char *fname, regmatch_T *p_regmatch) line, lnum, 0, - (int)(p_regmatch->startp[0] - (char_u *)line) + 1, // col - (int)(p_regmatch->endp[0] - (char_u *)line) + (int)(p_regmatch->startp[0] - line) + 1, // col + (int)(p_regmatch->endp[0] - line) + 1, // end_col false, // vis_col NULL, // search pattern @@ -6977,13 +6977,13 @@ static void hgr_search_file(qf_list_T *qfl, char *fname, regmatch_T *p_regmatch) true) // valid == QF_FAIL) { got_int = true; - if ((char_u *)line != IObuff) { + if (line != IObuff) { xfree(line); } break; } } - if ((char_u *)line != IObuff) { + if (line != IObuff) { xfree(line); } lnum++; diff --git a/src/nvim/regexp.c b/src/nvim/regexp.c index a94f91d103..9a8890a28a 100644 --- a/src/nvim/regexp.c +++ b/src/nvim/regexp.c @@ -1621,11 +1621,11 @@ static int fill_submatch_list(int argc FUNC_ATTR_UNUSED, typval_T *argv, int arg // There are always 10 list items in staticList10_T. listitem_T *li = tv_list_first(listarg->vval.v_list); for (int i = 0; i < 10; i++) { - char *s = (char *)rsm.sm_match->startp[i]; + char *s = rsm.sm_match->startp[i]; if (s == NULL || rsm.sm_match->endp[i] == NULL) { s = NULL; } else { - s = xstrnsave(s, (size_t)(rsm.sm_match->endp[i] - (char_u *)s)); + s = xstrnsave(s, (size_t)(rsm.sm_match->endp[i] - s)); } TV_LIST_ITEM_TV(li)->v_type = VAR_STRING; TV_LIST_ITEM_TV(li)->vval.v_string = s; @@ -2006,11 +2006,11 @@ static int vim_regsub_both(char_u *source, typval_T *expr, char_u *dest, int des } } } else { - s = rex.reg_match->startp[no]; + s = (char_u *)rex.reg_match->startp[no]; if (rex.reg_match->endp[no] == NULL) { s = NULL; } else { - len = (int)(rex.reg_match->endp[no] - s); + len = (int)(rex.reg_match->endp[no] - (char *)s); } } if (s != NULL) { @@ -2206,11 +2206,11 @@ char *reg_submatch(int no) } } } else { - s = (char *)rsm.sm_match->startp[no]; + s = rsm.sm_match->startp[no]; if (s == NULL || rsm.sm_match->endp[no] == NULL) { retval = NULL; } else { - retval = xstrnsave(s, (size_t)(rsm.sm_match->endp[no] - (char_u *)s)); + retval = xstrnsave(s, (size_t)(rsm.sm_match->endp[no] - s)); } } diff --git a/src/nvim/regexp_bt.c b/src/nvim/regexp_bt.c index 63e4dd5b7e..59a6ed28af 100644 --- a/src/nvim/regexp_bt.c +++ b/src/nvim/regexp_bt.c @@ -5028,8 +5028,8 @@ static long bt_regexec_both(char_u *line, colnr_T col, proftime_T *tm, int *time rex.reg_endpos = rex.reg_mmatch->endpos; } else { prog = (bt_regprog_T *)rex.reg_match->regprog; - rex.reg_startp = rex.reg_match->startp; - rex.reg_endp = rex.reg_match->endp; + rex.reg_startp = (char_u **)rex.reg_match->startp; + rex.reg_endp = (char_u **)rex.reg_match->endp; } // Be paranoid... diff --git a/src/nvim/regexp_defs.h b/src/nvim/regexp_defs.h index 5d7175b89a..b24ed350e8 100644 --- a/src/nvim/regexp_defs.h +++ b/src/nvim/regexp_defs.h @@ -140,8 +140,8 @@ typedef struct { */ typedef struct { regprog_T *regprog; - char_u *startp[NSUBEXP]; - char_u *endp[NSUBEXP]; + char *startp[NSUBEXP]; + char *endp[NSUBEXP]; bool rm_ic; } regmatch_T; diff --git a/src/nvim/regexp_nfa.c b/src/nvim/regexp_nfa.c index ea11398c30..fbd4e26c75 100644 --- a/src/nvim/regexp_nfa.c +++ b/src/nvim/regexp_nfa.c @@ -7402,8 +7402,8 @@ static long nfa_regexec_both(char_u *line, colnr_T startcol, proftime_T *tm, int rex.reg_endpos = rex.reg_mmatch->endpos; } else { prog = (nfa_regprog_T *)rex.reg_match->regprog; - rex.reg_startp = rex.reg_match->startp; - rex.reg_endp = rex.reg_match->endp; + rex.reg_startp = (char_u **)rex.reg_match->startp; + rex.reg_endp = (char_u **)rex.reg_match->endp; } // Be paranoid... diff --git a/src/nvim/runtime.c b/src/nvim/runtime.c index b43db2256f..78a157f9fb 100644 --- a/src/nvim/runtime.c +++ b/src/nvim/runtime.c @@ -1065,7 +1065,7 @@ static void add_pack_start_dir(char *fname, void *cookie) continue; } STRLCPY(buf, fname, MAXPATHL); - STRLCAT(buf, start_pat[i], sizeof buf); + xstrlcat(buf, start_pat[i], sizeof buf); if (pack_has_entries(buf)) { add_pack_dir_to_rtp(buf, true); } @@ -2121,7 +2121,7 @@ scriptitem_T *get_current_script_id(char **fnamep, sctx_T *ret_sctx) // - If a script is deleted and another script is written, with a // different name, the inode may be re-used. si = &SCRIPT_ITEM(script_sctx.sc_sid); - if (si->sn_name != NULL && FNAMECMP(si->sn_name, *fnamep) == 0) { + if (si->sn_name != NULL && path_fnamecmp(si->sn_name, *fnamep) == 0) { // Found it! break; } diff --git a/src/nvim/search.c b/src/nvim/search.c index e2df31c04f..8477efed92 100644 --- a/src/nvim/search.c +++ b/src/nvim/search.c @@ -3508,14 +3508,14 @@ void find_pattern_in_path(char_u *ptr, Direction dir, size_t len, bool whole, bo if (inc_opt != NULL && strstr(inc_opt, "\\zs") != NULL) { // Use text from '\zs' to '\ze' (or end) of 'include'. - new_fname = (char_u *)find_file_name_in_path((char *)incl_regmatch.startp[0], + new_fname = (char_u *)find_file_name_in_path(incl_regmatch.startp[0], (size_t)(incl_regmatch.endp[0] - incl_regmatch.startp[0]), FNAME_EXP|FNAME_INCL|FNAME_REL, 1L, (char *)p_fname); } else { // Use text after match with 'include'. - new_fname = file_name_in_line(incl_regmatch.endp[0], 0, + new_fname = file_name_in_line((char_u *)incl_regmatch.endp[0], 0, FNAME_EXP|FNAME_INCL|FNAME_REL, 1L, p_fname, NULL); } already_searched = false; @@ -3583,19 +3583,19 @@ void find_pattern_in_path(char_u *ptr, Direction dir, size_t len, bool whole, bo if (inc_opt != NULL && strstr(inc_opt, "\\zs") != NULL) { // pattern contains \zs, use the match - p = incl_regmatch.startp[0]; + p = (char_u *)incl_regmatch.startp[0]; i = (int)(incl_regmatch.endp[0] - incl_regmatch.startp[0]); } else { // find the file name after the end of the match - for (p = incl_regmatch.endp[0]; + for (p = (char_u *)incl_regmatch.endp[0]; *p && !vim_isfilec(*p); p++) {} for (i = 0; vim_isfilec(p[i]); i++) {} } if (i == 0) { // Nothing found, use the rest of the line. - p = incl_regmatch.endp[0]; + p = (char_u *)incl_regmatch.endp[0]; i = (int)STRLEN(p); } else if (p > line) { // Avoid checking before the start of the line, can @@ -3681,7 +3681,7 @@ search_line: // Pattern must be first identifier after 'define', so skip // to that position before checking for match of pattern. Also // don't let it match beyond the end of this identifier. - p = def_regmatch.endp[0]; + p = (char_u *)def_regmatch.endp[0]; while (*p && !vim_iswordc(*p)) { p++; } @@ -3706,7 +3706,7 @@ search_line: } else if (regmatch.regprog != NULL && vim_regexec(®match, (char *)line, (colnr_T)(p - line))) { matched = true; - startp = regmatch.startp[0]; + startp = (char_u *)regmatch.startp[0]; // Check if the line is not a comment line (unless we are // looking for a define). A line starting with "# define" // is not considered to be a comment line. @@ -3810,7 +3810,7 @@ search_line: cont_s_ipos = true; } IObuff[i] = NUL; - aux = IObuff; + aux = (char_u *)IObuff; if (i == ins_compl_len()) { goto exit_matched; diff --git a/src/nvim/shada.c b/src/nvim/shada.c index 1c29689487..74d8b30347 100644 --- a/src/nvim/shada.c +++ b/src/nvim/shada.c @@ -1053,7 +1053,7 @@ static buf_T *find_buffer(khash_t(fnamebufs) *const fname_bufs, const char *cons kh_key(fname_bufs, k) = xstrdup(fname); FOR_ALL_BUFFERS(buf) { if (buf->b_ffname != NULL) { - if (FNAMECMP(fname, buf->b_ffname) == 0) { + if (path_fnamecmp(fname, buf->b_ffname) == 0) { kh_val(fname_bufs, k) = buf; return buf; } @@ -3098,7 +3098,7 @@ shada_write_file_nomerge: {} } } #endif - if (vim_rename((char_u *)tempname, (char_u *)fname) == -1) { + if (vim_rename(tempname, fname) == -1) { semsg(_(RNERR "Can't rename ShaDa file from %s to %s!"), tempname, fname); } else { diff --git a/src/nvim/spell.c b/src/nvim/spell.c index 4acefd9d64..42891fd3fb 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -369,7 +369,7 @@ size_t spell_check(win_T *wp, char_u *ptr, hlf_T *attrp, int *capcol, bool docou int r = vim_regexec(®match, (char *)ptr, 0); wp->w_s->b_cap_prog = regmatch.regprog; if (r) { - *capcol = (int)(regmatch.endp[0] - ptr); + *capcol = (int)(regmatch.endp[0] - (char *)ptr); } } @@ -1902,7 +1902,7 @@ char *did_set_spelllang(win_T *wp) // If the name ends in ".spl" use it as the name of the spell file. // If there is a region name let "region" point to it and remove it // from the name. - if (len > 4 && FNAMECMP(lang + len - 4, ".spl") == 0) { + if (len > 4 && path_fnamecmp(lang + len - 4, ".spl") == 0) { filename = true; // Locate a region and remove it from the file name. @@ -2548,7 +2548,7 @@ bool check_need_cap(linenr_T lnum, colnr_T col) break; } if (vim_regexec(®match, (char *)p, 0) - && regmatch.endp[0] == line + endcol) { + && (char_u *)regmatch.endp[0] == line + endcol) { need_cap = true; break; } @@ -3407,7 +3407,7 @@ static void dump_word(slang_T *slang, char_u *word, char_u *pat, Direction *dir, if (!HASHITEM_EMPTY(hi)) { vim_snprintf((char *)IObuff, IOSIZE, "%s\t%d", tw, HI2WC(hi)->wc_count); - p = IObuff; + p = (char_u *)IObuff; } } diff --git a/src/nvim/spellfile.c b/src/nvim/spellfile.c index 2858942d0b..7da5a7ca4f 100644 --- a/src/nvim/spellfile.c +++ b/src/nvim/spellfile.c @@ -895,7 +895,7 @@ void suggest_load_files(void) slang->sl_sugloaded = true; dotp = strrchr(slang->sl_fname, '.'); - if (dotp == NULL || FNAMECMP(dotp, ".spl") != 0) { + if (dotp == NULL || path_fnamecmp(dotp, ".spl") != 0) { continue; } STRCPY(dotp, ".sug"); diff --git a/src/nvim/spellsuggest.c b/src/nvim/spellsuggest.c index 5f432f1c9a..16af1b72a3 100644 --- a/src/nvim/spellsuggest.c +++ b/src/nvim/spellsuggest.c @@ -533,7 +533,7 @@ void spell_suggest(int count) } vim_snprintf((char *)IObuff, IOSIZE, "%2d", i + 1); if (cmdmsg_rl) { - rl_mirror(IObuff); + rl_mirror((char_u *)IObuff); } msg_puts((const char *)IObuff); @@ -559,7 +559,7 @@ void spell_suggest(int count) } if (cmdmsg_rl) { // Mirror the numbers, but keep the leading space. - rl_mirror(IObuff + 1); + rl_mirror((char_u *)IObuff + 1); } msg_advance(30); msg_puts((const char *)IObuff); diff --git a/src/nvim/tag.c b/src/nvim/tag.c index b363dfc889..36f797da06 100644 --- a/src/nvim/tag.c +++ b/src/nvim/tag.c @@ -1971,7 +1971,7 @@ parse_line: *tagp.tagname_end = NUL; match = vim_regexec(&orgpat.regmatch, tagp.tagname, (colnr_T)0); if (match) { - matchoff = (int)(orgpat.regmatch.startp[0] - (char_u *)tagp.tagname); + matchoff = (int)(orgpat.regmatch.startp[0] - tagp.tagname); if (orgpat.regmatch.rm_ic) { orgpat.regmatch.rm_ic = false; match_no_ic = vim_regexec(&orgpat.regmatch, tagp.tagname, (colnr_T)0); diff --git a/src/nvim/undo.c b/src/nvim/undo.c index 8ee708aa4d..891a42380e 100644 --- a/src/nvim/undo.c +++ b/src/nvim/undo.c @@ -2636,7 +2636,7 @@ void ex_undolist(exarg_T *eap) if (uhp->uh_prev.ptr == NULL && uhp->uh_walk != nomark && uhp->uh_walk != mark) { vim_snprintf((char *)IObuff, IOSIZE, "%6ld %7d ", uhp->uh_seq, changes); - undo_fmt_time(IObuff + STRLEN(IObuff), IOSIZE - STRLEN(IObuff), uhp->uh_time); + undo_fmt_time((char_u *)IObuff + STRLEN(IObuff), IOSIZE - STRLEN(IObuff), uhp->uh_time); if (uhp->uh_save_nr > 0) { while (STRLEN(IObuff) < 33) { STRCAT(IObuff, " "); diff --git a/src/nvim/vim.h b/src/nvim/vim.h index 6c7bc05c82..af0f231b37 100644 --- a/src/nvim/vim.h +++ b/src/nvim/vim.h @@ -230,7 +230,6 @@ enum { FOLD_TEXT_LEN = 51, }; //!< buffer size for get_foldtext() #endif #define STRCAT(d, s) strcat((char *)(d), (char *)(s)) // NOLINT(runtime/printf) -#define STRLCAT(d, s, n) xstrlcat((char *)(d), (char *)(s), (size_t)(n)) // Character used as separated in autoload function/variable names. #define AUTOLOAD_CHAR '#' @@ -245,23 +244,6 @@ enum { FOLD_TEXT_LEN = 51, }; //!< buffer size for get_foldtext() #include "nvim/path.h" -/// Compare file names -/// -/// On some systems case in a file name does not matter, on others it does. -/// -/// @note Does not account for maximum name lengths and things like "../dir", -/// thus it is not 100% accurate. OS may also use different algorithm for -/// case-insensitive comparison. -/// -/// @param[in] x First file name to compare. -/// @param[in] y Second file name to compare. -/// -/// @return 0 for equal file names, non-zero otherwise. -#define FNAMECMP(x, y) path_fnamecmp((const char *)(x), (const char *)(y)) -#define FNAMENCMP(x, y, n) path_fnamencmp((const char *)(x), \ - (const char *)(y), \ - (size_t)(n)) - // Enums need a typecast to be used as array index. #define HL_ATTR(n) hl_attr_active[(int)(n)] |