diff options
Diffstat (limited to 'src/nvim/fileio.c')
-rw-r--r-- | src/nvim/fileio.c | 58 |
1 files changed, 27 insertions, 31 deletions
diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index 684658b4e3..d4725ccd86 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -134,8 +134,8 @@ static char *err_readonly = "is read-only (cannot override: \"W\" in 'cpoptions' # include "fileio.c.generated.h" #endif -static char *e_auchangedbuf = N_("E812: Autocommands changed buffer or buffer name"); -static char e_no_matching_autocommands_for_buftype_str_buffer[] +static const char *e_auchangedbuf = N_("E812: Autocommands changed buffer or buffer name"); +static const char e_no_matching_autocommands_for_buftype_str_buffer[] = N_("E676: No matching autocommands for buftype=%s buffer"); void filemess(buf_T *buf, char *name, char *s, int attr) @@ -145,7 +145,7 @@ void filemess(buf_T *buf, char *name, char *s, int attr) if (msg_silent != 0) { return; } - add_quoted_fname(IObuff, IOSIZE - 100, buf, (const char *)name); + add_quoted_fname(IObuff, IOSIZE - 100, buf, name); // Avoid an over-long translation to cause trouble. xstrlcat(IObuff, s, IOSIZE); // For the first message may have to start a new line. @@ -576,7 +576,7 @@ int readfile(char *fname, char *sfname, linenr_T from, linenr_T lines_to_skip, // Set swap file protection bits after creating it. if (swap_mode > 0 && curbuf->b_ml.ml_mfp != NULL && curbuf->b_ml.ml_mfp->mf_fname != NULL) { - const char *swap_fname = (const char *)curbuf->b_ml.ml_mfp->mf_fname; + const char *swap_fname = curbuf->b_ml.ml_mfp->mf_fname; // If the group-read bit is set but not the world-read bit, then // the group must be equal to the group of the original file. If @@ -1732,7 +1732,7 @@ failed: } if (!filtering && !(flags & READ_DUMMY) && !silent) { - add_quoted_fname(IObuff, IOSIZE, curbuf, (const char *)sfname); + add_quoted_fname(IObuff, IOSIZE, curbuf, sfname); c = false; #ifdef UNIX @@ -2372,7 +2372,7 @@ static int get_fileinfo_os(char *fname, FileInfo *file_info_old, bool overwritin *newfile = true; *perm = -1; } else { - *perm = os_getperm((const char *)fname); + *perm = os_getperm(fname); if (*perm < 0) { *newfile = true; } else if (os_isdir(fname)) { @@ -2611,7 +2611,7 @@ static int buf_write_make_backup(char *fname, bool append, FileInfo *file_info_o // set file protection same as original file, but // strip s-bit. - (void)os_setperm((const char *)(*backupp), perm & 0777); + (void)os_setperm(*backupp, perm & 0777); #ifdef UNIX // @@ -2621,8 +2621,7 @@ static int buf_write_make_backup(char *fname, bool append, FileInfo *file_info_o // if (file_info_new.stat.st_gid != file_info_old->stat.st_gid && os_chown(*backupp, (uv_uid_t)-1, (uv_gid_t)file_info_old->stat.st_gid) != 0) { - os_setperm((const char *)(*backupp), - ((int)perm & 0707) | (((int)perm & 07) << 3)); + os_setperm(*backupp, ((int)perm & 0707) | (((int)perm & 07) << 3)); } #endif @@ -2960,7 +2959,7 @@ int buf_write(buf_T *buf, char *fname, char *sfname, linenr_T start, linenr_T en && file_info_old.stat.st_uid == getuid() && vim_strchr(p_cpo, CPO_FWRITE) == NULL) { perm |= 0200; - (void)os_setperm((const char *)fname, (int)perm); + (void)os_setperm(fname, (int)perm); made_writable = true; } #endif @@ -3378,7 +3377,7 @@ restore_backup: } #endif if (perm >= 0) { // Set perm. of new file same as old file. - (void)os_setperm((const char *)wfname, (int)perm); + (void)os_setperm(wfname, (int)perm); } // Probably need to set the ACL before changing the user (can't set the // ACL on a file the user doesn't own). @@ -3459,7 +3458,7 @@ restore_backup: fname = sfname; // use shortname now, for the messages #endif if (!filtering) { - add_quoted_fname(IObuff, IOSIZE, buf, (const char *)fname); + add_quoted_fname(IObuff, IOSIZE, buf, fname); bool insert_space = false; if (write_info.bw_conv_error) { STRCAT(IObuff, _(" CONVERSION ERROR")); @@ -3563,7 +3562,7 @@ restore_backup: } } if (org != NULL) { - os_setperm(org, os_getperm((const char *)fname) & 0777); + os_setperm(org, os_getperm(fname) & 0777); xfree(org); } } @@ -3600,9 +3599,9 @@ nofail: if (err.msg != NULL) { // - 100 to save some space for further error message #ifndef UNIX - add_quoted_fname(IObuff, IOSIZE - 100, buf, (const char *)sfname); + add_quoted_fname(IObuff, IOSIZE - 100, buf, sfname); #else - add_quoted_fname(IObuff, IOSIZE - 100, buf, (const char *)fname); + add_quoted_fname(IObuff, IOSIZE - 100, buf, fname); #endif emit_err(&err); @@ -4229,7 +4228,7 @@ void shorten_fnames(int force) os_dirname(dirname, MAXPATHL); FOR_ALL_BUFFERS(buf) { - shorten_buf_fname(buf, (char *)dirname, force); + shorten_buf_fname(buf, dirname, force); // Always make the swap file name a full path, a "nofile" buffer may // also have a swap file. @@ -4363,7 +4362,7 @@ bool vim_fgets(char *buf, int size, FILE *fp) do { tbuf[sizeof(tbuf) - 2] = NUL; errno = 0; - retval = fgets((char *)tbuf, sizeof(tbuf), fp); + retval = fgets(tbuf, sizeof(tbuf), fp); if (retval == NULL && (feof(fp) || errno != EINTR)) { break; } @@ -4545,8 +4544,7 @@ int vim_rename(const char *from, const char *to) // to the same file (ignoring case and slash/backslash differences) but // the file name differs we need to go through a temp file. if (path_fnamecmp(from, to) == 0) { - if (p_fic && (strcmp(path_tail((char *)from), path_tail((char *)to)) - != 0)) { + if (p_fic && (strcmp(path_tail(from), path_tail(to)) != 0)) { use_tmp_file = true; } else { return 0; @@ -4555,7 +4553,7 @@ int vim_rename(const char *from, const char *to) // Fail if the "from" file doesn't exist. Avoids that "to" is deleted. FileInfo from_info; - if (!os_fileinfo((char *)from, &from_info)) { + if (!os_fileinfo(from, &from_info)) { return -1; } @@ -4563,8 +4561,7 @@ int vim_rename(const char *from, const char *to) // This happens when "from" and "to" differ in case and are on a FAT32 // filesystem. In that case go through a temp file name. FileInfo to_info; - if (os_fileinfo((char *)to, &to_info) - && os_fileinfo_id_equal(&from_info, &to_info)) { + if (os_fileinfo(to, &to_info) && os_fileinfo_id_equal(&from_info, &to_info)) { use_tmp_file = true; } @@ -4576,7 +4573,7 @@ int vim_rename(const char *from, const char *to) // os_rename() work, on other systems it makes sure that we don't have // two files when the os_rename() fails. - os_remove((char *)to); + os_remove(to); // First try a normal rename, return if it works. if (os_rename(from, to) == OK) { @@ -4587,14 +4584,14 @@ int vim_rename(const char *from, const char *to) long perm = os_getperm(from); // For systems that support ACL: get the ACL from the original file. vim_acl_T acl = os_get_acl(from); - int fd_in = os_open((char *)from, O_RDONLY, 0); + int fd_in = os_open(from, O_RDONLY, 0); if (fd_in < 0) { os_free_acl(acl); return -1; } // Create the new file with same permissions as the original. - int fd_out = os_open((char *)to, O_CREAT|O_EXCL|O_WRONLY|O_NOFOLLOW, (int)perm); + int fd_out = os_open(to, O_CREAT|O_EXCL|O_WRONLY|O_NOFOLLOW, (int)perm); if (fd_out < 0) { close(fd_in); os_free_acl(acl); @@ -4637,7 +4634,7 @@ int vim_rename(const char *from, const char *to) semsg(errmsg, to); return -1; } - os_remove((char *)from); + os_remove(from); return 0; } @@ -5295,7 +5292,7 @@ int delete_recursive(const char *name) if (readdir_core(&ga, exp, NULL, NULL) == OK) { for (int i = 0; i < ga.ga_len; i++) { vim_snprintf(NameBuff, MAXPATHL, "%s/%s", exp, ((char **)ga.ga_data)[i]); - if (delete_recursive((const char *)NameBuff) != 0) { + if (delete_recursive(NameBuff) != 0) { // Remember the failure but continue deleting any further // entries. result = -1; @@ -5428,10 +5425,9 @@ char *vim_tempname(void) // There is no need to check if the file exists, because we own the directory // and nobody else creates a file in it. - char template[TEMP_FILE_PATH_MAXLEN]; - snprintf(template, TEMP_FILE_PATH_MAXLEN, - "%s%" PRIu64, tempdir, temp_count++); - return xstrdup(template); + char templ[TEMP_FILE_PATH_MAXLEN]; + snprintf(templ, TEMP_FILE_PATH_MAXLEN, "%s%" PRIu64, tempdir, temp_count++); + return xstrdup(templ); } /// Tries matching a filename with a "pattern" ("prog" is NULL), or use the |