diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/buffer.c | 12 | ||||
-rw-r--r-- | src/nvim/buffer_defs.h | 2 | ||||
-rw-r--r-- | src/nvim/diff.c | 7 | ||||
-rw-r--r-- | src/nvim/eval.c | 13 | ||||
-rw-r--r-- | src/nvim/ex_cmds.c | 2 | ||||
-rw-r--r-- | src/nvim/ex_cmds2.c | 4 | ||||
-rw-r--r-- | src/nvim/file_search.c | 4 | ||||
-rw-r--r-- | src/nvim/fileio.c | 53 | ||||
-rw-r--r-- | src/nvim/if_cscope.c | 8 | ||||
-rw-r--r-- | src/nvim/main.c | 4 | ||||
-rw-r--r-- | src/nvim/memfile.c | 12 | ||||
-rw-r--r-- | src/nvim/memline.c | 26 | ||||
-rw-r--r-- | src/nvim/os/fs.c | 59 | ||||
-rw-r--r-- | src/nvim/os_unix.c | 6 | ||||
-rw-r--r-- | src/nvim/path.c | 18 | ||||
-rw-r--r-- | src/nvim/quickfix.c | 2 | ||||
-rw-r--r-- | src/nvim/undo.c | 8 |
17 files changed, 128 insertions, 112 deletions
diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 77bed67d5f..3c7fd777bd 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -1314,7 +1314,7 @@ buflist_new ( * for hard links. */ FileID file_id; bool file_id_valid = (sfname != NULL && - os_get_file_id((char *)sfname, &file_id)); + os_fileid((char *)sfname, &file_id)); if (ffname != NULL && !(flags & BLN_DUMMY) && (buf = buflist_findname_file_id(ffname, &file_id, file_id_valid)) != NULL) { @@ -1671,7 +1671,7 @@ buf_T *buflist_findname_exp(char_u *fname) buf_T *buflist_findname(char_u *ffname) { FileID file_id; - bool file_id_valid = os_get_file_id((char *)ffname, &file_id); + bool file_id_valid = os_fileid((char *)ffname, &file_id); return buflist_findname_file_id(ffname, &file_id, file_id_valid); } @@ -2221,7 +2221,7 @@ setfname ( * - if the buffer is loaded, fail * - if the buffer is not loaded, delete it from the list */ - file_id_valid = os_get_file_id((char *)ffname, &file_id); + file_id_valid = os_fileid((char *)ffname, &file_id); if (!(buf->b_flags & BF_DUMMY)) { obuf = buflist_findname_file_id(ffname, &file_id, file_id_valid); } @@ -2399,7 +2399,7 @@ static int otherfile_buf(buf_T *buf, char_u *ffname, /* If no struct stat given, get it now */ if (file_id_p == NULL) { file_id_p = &file_id; - file_id_valid = os_get_file_id((char *)ffname, file_id_p); + file_id_valid = os_fileid((char *)ffname, file_id_p); } if (!file_id_valid) { // file_id not valid, assume files are different. @@ -2429,7 +2429,7 @@ void buf_set_file_id(buf_T *buf) { FileID file_id; if (buf->b_fname != NULL - && os_get_file_id((char *)buf->b_fname, &file_id)) { + && os_fileid((char *)buf->b_fname, &file_id)) { buf->file_id_valid = true; buf->file_id = file_id; } else { @@ -2441,7 +2441,7 @@ void buf_set_file_id(buf_T *buf) static bool buf_same_file_id(buf_T *buf, FileID *file_id) { return buf->file_id_valid - && os_file_id_equal(&(buf->file_id), file_id); + && os_fileid_equal(&(buf->file_id), file_id); } /* diff --git a/src/nvim/buffer_defs.h b/src/nvim/buffer_defs.h index 4162df63ab..3b12925119 100644 --- a/src/nvim/buffer_defs.h +++ b/src/nvim/buffer_defs.h @@ -512,7 +512,7 @@ struct file_buffer { long b_mtime; /* last change time of original file */ long b_mtime_read; /* last change time when reading */ - off_t b_orig_size; /* size of original file in bytes */ + uint64_t b_orig_size; /* size of original file in bytes */ int b_orig_mode; /* mode of original file */ pos_T b_namedm[NMARKS]; /* current named marks (mark.c) */ diff --git a/src/nvim/diff.c b/src/nvim/diff.c index ab0c80112f..73b5731ad0 100644 --- a/src/nvim/diff.c +++ b/src/nvim/diff.c @@ -947,9 +947,10 @@ void ex_diffpatch(exarg_T *eap) os_remove((char *)buf); // Only continue if the output file was created. - off_t file_size; - bool file_size_success = os_get_file_size((char *)tmp_new, &file_size); - if (!file_size_success || file_size == 0) { + FileInfo file_info; + bool info_ok = os_fileinfo((char *)tmp_new, &file_info); + uint64_t filesize = os_fileinfo_size(&file_info); + if (!info_ok || filesize == 0) { EMSG(_("E816: Cannot read patch output")); } else { if (curbuf->b_fname != NULL) { diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 34af143446..a9570ecc84 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -9165,15 +9165,16 @@ static void f_getfsize(typval_T *argvars, typval_T *rettv) rettv->v_type = VAR_NUMBER; - off_t file_size; - if (os_get_file_size(fname, &file_size)) { + FileInfo file_info; + if (os_fileinfo(fname, &file_info)) { + uint64_t filesize = os_fileinfo_size(&file_info); if (os_isdir((char_u *)fname)) rettv->vval.v_number = 0; else { - rettv->vval.v_number = (varnumber_T)file_size; + rettv->vval.v_number = (varnumber_T)filesize; /* non-perfect check for overflow */ - if ((off_t)rettv->vval.v_number != file_size) { + if ((uint64_t)rettv->vval.v_number != filesize) { rettv->vval.v_number = -2; } } @@ -9190,7 +9191,7 @@ static void f_getftime(typval_T *argvars, typval_T *rettv) char *fname = (char *)get_tv_string(&argvars[0]); FileInfo file_info; - if (os_get_file_info(fname, &file_info)) { + if (os_fileinfo(fname, &file_info)) { rettv->vval.v_number = (varnumber_T)file_info.stat.st_mtim.tv_sec; } else { rettv->vval.v_number = -1; @@ -9210,7 +9211,7 @@ static void f_getftype(typval_T *argvars, typval_T *rettv) rettv->v_type = VAR_STRING; FileInfo file_info; - if (os_get_file_info_link((char *)fname, &file_info)) { + if (os_fileinfo_link((char *)fname, &file_info)) { uint64_t mode = file_info.stat.st_mode; #ifdef S_ISREG if (S_ISREG(mode)) diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index 5b6604fc93..18216f6924 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -1533,7 +1533,7 @@ void write_viminfo(char_u *file, int forceit) */ FileInfo old_info; // FileInfo of existing viminfo file - if (os_get_file_info((char *)fname, &old_info) + if (os_fileinfo((char *)fname, &old_info) && getuid() != ROOT_UID && !(old_info.stat.st_uid == getuid() ? (old_info.stat.st_mode & 0200) diff --git a/src/nvim/ex_cmds2.c b/src/nvim/ex_cmds2.c index 3809858875..ac91b2a6ac 100644 --- a/src/nvim/ex_cmds2.c +++ b/src/nvim/ex_cmds2.c @@ -2417,13 +2417,13 @@ do_source ( */ save_current_SID = current_SID; FileID file_id; - bool file_id_ok = os_get_file_id((char *)fname_exp, &file_id); + bool file_id_ok = os_fileid((char *)fname_exp, &file_id); for (current_SID = script_items.ga_len; current_SID > 0; --current_SID) { si = &SCRIPT_ITEM(current_SID); // Compare dev/ino when possible, it catches symbolic links. // Also compare file names, the inode may change when the file was edited. bool file_id_equal = file_id_ok && si->file_id_valid - && os_file_id_equal(&(si->file_id), &file_id); + && os_fileid_equal(&(si->file_id), &file_id); if (si->sn_name != NULL && (file_id_equal || fnamecmp(si->sn_name, fname_exp) == 0)) { break; diff --git a/src/nvim/file_search.c b/src/nvim/file_search.c index c7e1f5cbbc..955b0b0a68 100644 --- a/src/nvim/file_search.c +++ b/src/nvim/file_search.c @@ -1097,7 +1097,7 @@ static int ff_check_visited(ff_visited_T **visited_list, char_u *fname, char_u * url = true; } else { ff_expand_buffer[0] = NUL; - if (!os_get_file_id((char *)fname, &file_id)) { + if (!os_fileid((char *)fname, &file_id)) { return FAIL; } } @@ -1106,7 +1106,7 @@ static int ff_check_visited(ff_visited_T **visited_list, char_u *fname, char_u * for (vp = *visited_list; vp != NULL; vp = vp->ffv_next) { if ((url && fnamecmp(vp->ffv_fname, ff_expand_buffer) == 0) || (!url && vp->file_id_valid - && os_file_id_equal(&(vp->file_id), &file_id))) { + && os_fileid_equal(&(vp->file_id), &file_id))) { /* are the wildcard parts equal */ if (ff_wc_equal(vp->ffv_wc_path, wc_path) == TRUE) /* already visited */ diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index 2e932e9695..0a05b2a4db 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -472,7 +472,7 @@ readfile ( if (newfile && !read_stdin && !read_buffer) { /* Remember time of file. */ FileInfo file_info; - if (os_get_file_info((char *)fname, &file_info)) { + if (os_fileinfo((char *)fname, &file_info)) { buf_store_file_info(curbuf, &file_info); curbuf->b_mtime_read = curbuf->b_mtime; #ifdef UNIX @@ -2583,7 +2583,7 @@ buf_write ( #if defined(UNIX) perm = -1; FileInfo file_info_old; - if (!os_get_file_info((char *)fname, &file_info_old)) { + if (!os_fileinfo((char *)fname, &file_info_old)) { newfile = TRUE; } else { perm = file_info_old.stat.st_mode; @@ -2629,7 +2629,7 @@ buf_write ( goto fail; } if (overwriting) { - os_get_file_info((char *)fname, &file_info_old); + os_fileinfo((char *)fname, &file_info_old); } } @@ -2712,9 +2712,9 @@ buf_write ( * - it's a symbolic link * - we don't have write permission in the directory */ - if (file_info_old.stat.st_nlink > 1 - || !os_get_file_info_link((char *)fname, &file_info) - || !os_file_info_id_equal(&file_info, &file_info_old)) { + if (os_fileinfo_hardlinks(&file_info_old) > 1 + || !os_fileinfo_link((char *)fname, &file_info) + || !os_fileinfo_id_equal(&file_info, &file_info_old)) { backup_copy = TRUE; } else # endif @@ -2728,7 +2728,7 @@ buf_write ( STRCPY(IObuff, fname); for (i = 4913;; i += 123) { sprintf((char *)path_tail(IObuff), "%d", i); - if (!os_get_file_info_link((char *)IObuff, &file_info)) { + if (!os_fileinfo_link((char *)IObuff, &file_info)) { break; } } @@ -2739,7 +2739,7 @@ buf_write ( else { # ifdef UNIX os_fchown(fd, file_info_old.stat.st_uid, file_info_old.stat.st_gid); - if (!os_get_file_info((char *)IObuff, &file_info) + if (!os_fileinfo((char *)IObuff, &file_info) || file_info.stat.st_uid != file_info_old.stat.st_uid || file_info.stat.st_gid != file_info_old.stat.st_gid || (long)file_info.stat.st_mode != perm) { @@ -2759,20 +2759,20 @@ buf_write ( */ if ((bkc_flags & BKC_BREAKSYMLINK) || (bkc_flags & BKC_BREAKHARDLINK)) { # ifdef UNIX - bool file_info_link_ok = os_get_file_info_link((char *)fname, &file_info); + bool file_info_link_ok = os_fileinfo_link((char *)fname, &file_info); /* Symlinks. */ if ((bkc_flags & BKC_BREAKSYMLINK) && file_info_link_ok - && !os_file_info_id_equal(&file_info, &file_info_old)) { + && !os_fileinfo_id_equal(&file_info, &file_info_old)) { backup_copy = FALSE; } /* Hardlinks. */ if ((bkc_flags & BKC_BREAKHARDLINK) - && file_info_old.stat.st_nlink > 1 + && os_fileinfo_hardlinks(&file_info_old) > 1 && (!file_info_link_ok - || os_file_info_id_equal(&file_info, &file_info_old))) { + || os_fileinfo_id_equal(&file_info, &file_info_old))) { backup_copy = FALSE; } # endif @@ -2837,14 +2837,14 @@ buf_write ( /* * Check if backup file already exists. */ - if (os_get_file_info((char *)backup, &file_info_new)) { + if (os_fileinfo((char *)backup, &file_info_new)) { /* * Check if backup file is same as original file. * May happen when modname() gave the same file back (e.g. silly * link). If we don't check here, we either ruin the file when * copying or erase it after writing. */ - if (os_file_info_id_equal(&file_info_new, &file_info_old)) { + if (os_fileinfo_id_equal(&file_info_new, &file_info_old)) { free(backup); backup = NULL; /* no backup file to delete */ } @@ -2861,7 +2861,7 @@ buf_write ( wp = backup; *wp = 'z'; while (*wp > 'a' - && os_get_file_info((char *)backup, &file_info_new)) { + && os_fileinfo((char *)backup, &file_info_new)) { --*wp; } /* They all exist??? Must be something wrong. */ @@ -3201,9 +3201,9 @@ nobackup: FileInfo file_info; /* Don't delete the file when it's a hard or symbolic link. */ - if ((!newfile && file_info_old.stat.st_nlink > 1) - || (os_get_file_info_link((char *)fname, &file_info) - && !os_file_info_id_equal(&file_info, &file_info_old))) { + if ((!newfile && os_fileinfo_hardlinks(&file_info) > 1) + || (os_fileinfo_link((char *)fname, &file_info) + && !os_fileinfo_id_equal(&file_info, &file_info_old))) { errmsg = (char_u *)_("E166: Can't open linked file for writing"); } else #endif @@ -3416,7 +3416,7 @@ restore_backup: /* don't change the owner when it's already OK, some systems remove * permission or ACL stuff */ FileInfo file_info; - if (!os_get_file_info((char *)wfname, &file_info) + if (!os_fileinfo((char *)wfname, &file_info) || file_info.stat.st_uid != file_info_old.stat.st_uid || file_info.stat.st_gid != file_info_old.stat.st_gid) { os_fchown(fd, file_info_old.stat.st_uid, file_info_old.stat.st_gid); @@ -3713,7 +3713,7 @@ nofail: /* Update the timestamp to avoid an "overwrite changed file" * prompt when writing again. */ - if (os_get_file_info((char *)fname, &file_info_old)) { + if (os_fileinfo((char *)fname, &file_info_old)) { buf_store_file_info(buf, &file_info_old); buf->b_mtime_read = buf->b_mtime; } @@ -4536,7 +4536,7 @@ int vim_rename(char_u *from, char_u *to) // Fail if the "from" file doesn't exist. Avoids that "to" is deleted. FileInfo from_info; - if (!os_get_file_info((char *)from, &from_info)) { + if (!os_fileinfo((char *)from, &from_info)) { return -1; } @@ -4544,8 +4544,8 @@ int vim_rename(char_u *from, char_u *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_get_file_info((char *)to, &to_info) - && os_file_info_id_equal(&from_info, &to_info)) { + if (os_fileinfo((char *)to, &to_info) + && os_fileinfo_id_equal(&from_info, &to_info)) { use_tmp_file = true; } @@ -4790,7 +4790,7 @@ buf_check_timestamp ( int helpmesg = FALSE; int reload = FALSE; int can_reload = FALSE; - off_t orig_size = buf->b_orig_size; + uint64_t orig_size = buf->b_orig_size; int orig_mode = buf->b_orig_mode; static int busy = FALSE; int n; @@ -4812,7 +4812,7 @@ buf_check_timestamp ( bool file_info_ok; if (!(buf->b_flags & BF_NOTEDITED) && buf->b_mtime != 0 - && (!(file_info_ok = os_get_file_info((char *)buf->b_ffname, &file_info)) + && (!(file_info_ok = os_fileinfo((char *)buf->b_ffname, &file_info)) || time_differs((long)file_info.stat.st_mtim.tv_sec, buf->b_mtime) || (int)file_info.stat.st_mode != buf->b_orig_mode )) { @@ -5127,9 +5127,10 @@ void buf_reload(buf_T *buf, int orig_mode) } void buf_store_file_info(buf_T *buf, FileInfo *file_info) + FUNC_ATTR_NONNULL_ALL { buf->b_mtime = (long)file_info->stat.st_mtim.tv_sec; - buf->b_orig_size = file_info->stat.st_size; + buf->b_orig_size = os_fileinfo_size(file_info); buf->b_orig_mode = (int)file_info->stat.st_mode; } diff --git a/src/nvim/if_cscope.c b/src/nvim/if_cscope.c index 9e07a60ee1..667e6512f3 100644 --- a/src/nvim/if_cscope.c +++ b/src/nvim/if_cscope.c @@ -473,7 +473,7 @@ cs_add_common ( fname = (char *)vim_strnsave((char_u *)fname, len); free(fbuf); FileInfo file_info; - bool file_info_ok = os_get_file_info(fname, &file_info); + bool file_info_ok = os_fileinfo(fname, &file_info); if (!file_info_ok) { staterr: if (p_csverbose) @@ -504,7 +504,7 @@ staterr: else (void)sprintf(fname2, "%s/%s", fname, CSCOPE_DBFILE); - file_info_ok = os_get_file_info(fname2, &file_info); + file_info_ok = os_fileinfo(fname2, &file_info); if (!file_info_ok) { if (p_csverbose) cs_stat_emsg(fname2); @@ -1181,7 +1181,7 @@ static int cs_insert_filelist(char *fname, char *ppath, char *flags, i = -1; /* can be set to the index of an empty item in csinfo */ for (j = 0; j < csinfo_size; j++) { if (csinfo[j].fname != NULL - && os_file_id_equal_file_info(&(csinfo[j].file_id), file_info)) { + && os_fileid_equal_fileinfo(&(csinfo[j].file_id), file_info)) { if (p_csverbose) (void)EMSG(_("E568: duplicate cscope database not added")); return -1; @@ -1224,7 +1224,7 @@ static int cs_insert_filelist(char *fname, char *ppath, char *flags, } else csinfo[i].flags = NULL; - os_file_info_get_id(file_info, &(csinfo[i].file_id)); + os_fileinfo_id(file_info, &(csinfo[i].file_id)); return i; } /* cs_insert_filelist */ diff --git a/src/nvim/main.c b/src/nvim/main.c index 2f06a2cbf2..9ab46b1ce2 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -2094,9 +2094,9 @@ static int file_owned(char *fname) { uid_t uid = getuid(); FileInfo file_info; - bool file_owned = os_get_file_info(fname, &file_info) + bool file_owned = os_fileinfo(fname, &file_info) && file_info.stat.st_uid == uid; - bool link_owned = os_get_file_info_link(fname, &file_info) + bool link_owned = os_fileinfo_link(fname, &file_info) && file_info.stat.st_uid == uid; return file_owned && link_owned; } diff --git a/src/nvim/memfile.c b/src/nvim/memfile.c index 82369b739a..827cff2299 100644 --- a/src/nvim/memfile.c +++ b/src/nvim/memfile.c @@ -122,11 +122,11 @@ memfile_T *mf_open(char_u *fname, int flags) * mf_blocknr_max must be rounded up. */ FileInfo file_info; - if (mfp->mf_fd >= 0 - && os_get_file_info_fd(mfp->mf_fd, &file_info) - && file_info.stat.st_blksize >= MIN_SWAP_PAGE_SIZE - && file_info.stat.st_blksize <= MAX_SWAP_PAGE_SIZE) { - mfp->mf_page_size = file_info.stat.st_blksize; + if (mfp->mf_fd >= 0 && os_fileinfo_fd(mfp->mf_fd, &file_info)) { + uint64_t blocksize = os_fileinfo_blocksize(&file_info); + if (blocksize >= MIN_SWAP_PAGE_SIZE && blocksize <= MAX_SWAP_PAGE_SIZE) { + mfp->mf_page_size = blocksize; + } } if (mfp->mf_fd < 0 || (flags & (O_TRUNC|O_EXCL)) @@ -1017,7 +1017,7 @@ mf_do_open ( */ FileInfo file_info; if ((flags & O_CREAT) - && os_get_file_info_link((char *)mfp->mf_fname, &file_info)) { + && os_fileinfo_link((char *)mfp->mf_fname, &file_info)) { mfp->mf_fd = -1; EMSG(_("E300: Swap file already exists (symlink attack?)")); } else { diff --git a/src/nvim/memline.c b/src/nvim/memline.c index 229de4ae1c..04ee0d7f55 100644 --- a/src/nvim/memline.c +++ b/src/nvim/memline.c @@ -686,9 +686,9 @@ static void set_b0_fname(ZERO_BL *b0p, buf_T *buf) } } FileInfo file_info; - if (os_get_file_info((char *)buf->b_ffname, &file_info)) { + if (os_fileinfo((char *)buf->b_ffname, &file_info)) { long_to_char((long)file_info.stat.st_mtim.tv_sec, b0p->b0_mtime); - long_to_char((long)os_file_info_get_inode(&file_info), b0p->b0_ino); + long_to_char((long)os_fileinfo_inode(&file_info), b0p->b0_ino); buf_store_file_info(buf, &file_info); buf->b_mtime_read = buf->b_mtime; } else { @@ -961,8 +961,8 @@ void ml_recover(void) FileInfo swp_file_info; mtime = char_to_long(b0p->b0_mtime); if (curbuf->b_ffname != NULL - && os_get_file_info((char *)curbuf->b_ffname, &org_file_info) - && ((os_get_file_info((char *)mfp->mf_fname, &swp_file_info) + && os_fileinfo((char *)curbuf->b_ffname, &org_file_info) + && ((os_fileinfo((char *)mfp->mf_fname, &swp_file_info) && org_file_info.stat.st_mtim.tv_sec > swp_file_info.stat.st_mtim.tv_sec) || org_file_info.stat.st_mtim.tv_sec != mtime)) { @@ -1494,7 +1494,7 @@ static time_t swapfile_info(char_u *fname) /* print the swap file date */ FileInfo file_info; - if (os_get_file_info((char *)fname, &file_info)) { + if (os_fileinfo((char *)fname, &file_info)) { #ifdef UNIX /* print name of owner of the file */ if (os_get_uname(file_info.stat.st_uid, uname, B0_UNAME_SIZE) == OK) { @@ -1630,9 +1630,9 @@ void ml_sync_all(int check_file, int check_char) * call ml_preserve() to get rid of all negative numbered blocks. */ FileInfo file_info; - if (!os_get_file_info((char *)buf->b_ffname, &file_info) + if (!os_fileinfo((char *)buf->b_ffname, &file_info) || file_info.stat.st_mtim.tv_sec != buf->b_mtime_read - || (off_t)file_info.stat.st_size != buf->b_orig_size) { + || os_fileinfo_size(&file_info) != buf->b_orig_size) { ml_preserve(buf, FALSE); did_check_timestamps = FALSE; need_check_timestamps = TRUE; /* give message later */ @@ -3180,7 +3180,7 @@ attention_message ( msg_outtrans(buf->b_fname); MSG_PUTS("\"\n"); FileInfo file_info; - if (os_get_file_info((char *)buf->b_fname, &file_info)) { + if (os_fileinfo((char *)buf->b_fname, &file_info)) { MSG_PUTS(_(" dated: ")); x = file_info.stat.st_mtim.tv_sec; p = ctime(&x); // includes '\n' @@ -3294,7 +3294,7 @@ findswapname ( // Extra security check: When a swap file is a symbolic link, this // is most likely a symlink attack. FileInfo file_info; - bool file_or_link_found = os_get_file_info_link((char *)fname, &file_info); + bool file_or_link_found = os_fileinfo_link((char *)fname, &file_info); if (!file_or_link_found) { break; } @@ -3558,8 +3558,8 @@ fnamecmp_ino ( int retval_s; /* flag: buf_s valid */ FileInfo file_info; - if (os_get_file_info((char *)fname_c, &file_info)) { - ino_c = os_file_info_get_inode(&file_info); + if (os_fileinfo((char *)fname_c, &file_info)) { + ino_c = os_fileinfo_inode(&file_info); } /* @@ -3567,8 +3567,8 @@ fnamecmp_ino ( * the swap file may be outdated. If that fails (e.g. this path is not * valid on this machine), use the inode from block 0. */ - if (os_get_file_info((char *)fname_s, &file_info)) { - ino_s = os_file_info_get_inode(&file_info); + if (os_fileinfo((char *)fname_s, &file_info)) { + ino_s = os_fileinfo_inode(&file_info); } else { ino_s = (uint64_t)ino_block0; } diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c index aca7005064..bb4e897887 100644 --- a/src/nvim/os/fs.c +++ b/src/nvim/os/fs.c @@ -258,20 +258,6 @@ int os_file_is_writable(const char *name) return 0; } -/// Get the size of a file in bytes. -/// -/// @param[out] size pointer to an off_t to put the size into. -/// @return `true` for success, `false` for failure. -bool os_get_file_size(const char *name, off_t *size) -{ - uv_stat_t statbuf; - if (os_stat(name, &statbuf)) { - *size = statbuf.st_size; - return true; - } - return false; -} - /// Rename a file or directory. /// /// @return `OK` for success, `FAIL` for failure. @@ -345,7 +331,7 @@ int os_remove(const char *path) /// @param path Path to the file. /// @param[out] file_info Pointer to a FileInfo to put the information in. /// @return `true` on success, `false` for failure. -bool os_get_file_info(const char *path, FileInfo *file_info) +bool os_fileinfo(const char *path, FileInfo *file_info) { return os_stat(path, &(file_info->stat)); } @@ -355,7 +341,7 @@ bool os_get_file_info(const char *path, FileInfo *file_info) /// @param path Path to the file. /// @param[out] file_info Pointer to a FileInfo to put the information in. /// @return `true` on success, `false` for failure. -bool os_get_file_info_link(const char *path, FileInfo *file_info) +bool os_fileinfo_link(const char *path, FileInfo *file_info) { uv_fs_t request; int result = uv_fs_lstat(uv_default_loop(), &request, path, NULL); @@ -369,7 +355,7 @@ bool os_get_file_info_link(const char *path, FileInfo *file_info) /// @param file_descriptor File descriptor of the file. /// @param[out] file_info Pointer to a FileInfo to put the information in. /// @return `true` on success, `false` for failure. -bool os_get_file_info_fd(int file_descriptor, FileInfo *file_info) +bool os_fileinfo_fd(int file_descriptor, FileInfo *file_info) { uv_fs_t request; int result = uv_fs_fstat(uv_default_loop(), &request, file_descriptor, NULL); @@ -381,7 +367,7 @@ bool os_get_file_info_fd(int file_descriptor, FileInfo *file_info) /// Compare the inodes of two FileInfos /// /// @return `true` if the two FileInfos represent the same file. -bool os_file_info_id_equal(const FileInfo *file_info_1, +bool os_fileinfo_id_equal(const FileInfo *file_info_1, const FileInfo *file_info_2) { return file_info_1->stat.st_ino == file_info_2->stat.st_ino @@ -392,7 +378,7 @@ bool os_file_info_id_equal(const FileInfo *file_info_1, /// /// @param file_info Pointer to the `FileInfo` /// @param[out] file_id Pointer to a `FileID` -void os_file_info_get_id(const FileInfo *file_info, FileID *file_id) +void os_fileinfo_id(const FileInfo *file_info, FileID *file_id) { file_id->inode = file_info->stat.st_ino; file_id->device_id = file_info->stat.st_dev; @@ -403,17 +389,44 @@ void os_file_info_get_id(const FileInfo *file_info, FileID *file_id) /// @deprecated Use `FileID` instead, this function is only needed in memline.c /// @param file_info Pointer to the `FileInfo` /// @return the inode number -uint64_t os_file_info_get_inode(const FileInfo *file_info) +uint64_t os_fileinfo_inode(const FileInfo *file_info) { return file_info->stat.st_ino; } +/// Get the size of a file from a `FileInfo`. +/// +/// @return filesize in bytes. +uint64_t os_fileinfo_size(const FileInfo *file_info) + FUNC_ATTR_NONNULL_ALL +{ + return file_info->stat.st_size; +} + +/// Get the number of hardlinks from a `FileInfo`. +/// +/// @return number of hardlinks. +uint64_t os_fileinfo_hardlinks(const FileInfo *file_info) + FUNC_ATTR_NONNULL_ALL +{ + return file_info->stat.st_nlink; +} + +/// Get the blocksize from a `FileInfo`. +/// +/// @return blocksize in bytes. +uint64_t os_fileinfo_blocksize(const FileInfo *file_info) + FUNC_ATTR_NONNULL_ALL +{ + return file_info->stat.st_blksize; +} + /// Get the `FileID` for a given path /// /// @param path Path to the file. /// @param[out] file_info Pointer to a `FileID` to fill in. /// @return `true` on sucess, `false` for failure. -bool os_get_file_id(const char *path, FileID *file_id) +bool os_fileid(const char *path, FileID *file_id) { uv_stat_t statbuf; if (os_stat(path, &statbuf)) { @@ -429,7 +442,7 @@ bool os_get_file_id(const char *path, FileID *file_id) /// @param file_id_1 Pointer to first `FileID` /// @param file_id_2 Pointer to second `FileID` /// @return `true` if the two `FileID`s represent te same file. -bool os_file_id_equal(const FileID *file_id_1, const FileID *file_id_2) +bool os_fileid_equal(const FileID *file_id_1, const FileID *file_id_2) { return file_id_1->inode == file_id_2->inode && file_id_1->device_id == file_id_2->device_id; @@ -440,7 +453,7 @@ bool os_file_id_equal(const FileID *file_id_1, const FileID *file_id_2) /// @param file_id Pointer to a `FileID` /// @param file_info Pointer to a `FileInfo` /// @return `true` if the `FileID` and the `FileInfo` represent te same file. -bool os_file_id_equal_file_info(const FileID *file_id, +bool os_fileid_equal_fileinfo(const FileID *file_id, const FileInfo *file_info) { return file_id->inode == file_info->stat.st_ino diff --git a/src/nvim/os_unix.c b/src/nvim/os_unix.c index 33b08d7df6..3fa8b803b2 100644 --- a/src/nvim/os_unix.c +++ b/src/nvim/os_unix.c @@ -328,7 +328,7 @@ int len /* buffer size, only used when name gets longer */ struct dirent *dp; FileInfo file_info; - if (os_get_file_info_link((char *)name, &file_info)) { + if (os_fileinfo_link((char *)name, &file_info)) { /* Open the directory where the file is located. */ slash = vim_strrchr(name, '/'); if (slash == NULL) { @@ -354,8 +354,8 @@ int len /* buffer size, only used when name gets longer */ STRLCPY(newname + (tail - name), dp->d_name, MAXPATHL - (tail - name) + 1); FileInfo file_info_new; - if (os_get_file_info_link((char *)newname, &file_info_new) - && os_file_info_id_equal(&file_info, &file_info_new)) { + if (os_fileinfo_link((char *)newname, &file_info_new) + && os_fileinfo_id_equal(&file_info, &file_info_new)) { STRCPY(tail, dp->d_name); break; } diff --git a/src/nvim/path.c b/src/nvim/path.c index 0c18ab7bd4..4e05c506f8 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -61,10 +61,10 @@ FileComparison path_full_compare(char_u *s1, char_u *s2, int checkname) FileID file_id_1, file_id_2; expand_env(s1, exp1, MAXPATHL); - bool id_ok_1 = os_get_file_id((char *)exp1, &file_id_1); - bool id_ok_2 = os_get_file_id((char *)s2, &file_id_2); + bool id_ok_1 = os_fileid((char *)exp1, &file_id_1); + bool id_ok_2 = os_fileid((char *)s2, &file_id_2); if (!id_ok_1 && !id_ok_2) { - // If os_get_file_id() doesn't work, may compare the names. + // If os_fileid() doesn't work, may compare the names. if (checkname) { vim_FullName(exp1, full1, MAXPATHL, FALSE); vim_FullName(s2, full2, MAXPATHL, FALSE); @@ -77,7 +77,7 @@ FileComparison path_full_compare(char_u *s1, char_u *s2, int checkname) if (!id_ok_1 || !id_ok_2) { return kOneFileMissing; } - if (os_file_id_equal(&file_id_1, &file_id_2)) { + if (os_fileid_equal(&file_id_1, &file_id_2)) { return kEqualFiles; } return kDifferentFiles; @@ -1304,7 +1304,7 @@ void simplify_filename(char_u *filename) saved_char = p[-1]; p[-1] = NUL; FileInfo file_info; - if (!os_get_file_info_link((char *)filename, &file_info)) { + if (!os_fileinfo_link((char *)filename, &file_info)) { do_strip = TRUE; } p[-1] = saved_char; @@ -1327,7 +1327,7 @@ void simplify_filename(char_u *filename) * components. */ saved_char = *tail; *tail = NUL; - if (os_get_file_info((char *)filename, &file_info)) { + if (os_fileinfo((char *)filename, &file_info)) { do_strip = TRUE; } else @@ -1343,15 +1343,15 @@ void simplify_filename(char_u *filename) * component's parent directory.) */ FileInfo new_file_info; if (p == start && relative) { - os_get_file_info(".", &new_file_info); + os_fileinfo(".", &new_file_info); } else { saved_char = *p; *p = NUL; - os_get_file_info((char *)filename, &new_file_info); + os_fileinfo((char *)filename, &new_file_info); *p = saved_char; } - if (!os_file_info_id_equal(&file_info, &new_file_info)) { + if (!os_fileinfo_id_equal(&file_info, &new_file_info)) { do_strip = FALSE; /* We don't disable stripping of later * components since the unstripped path name is diff --git a/src/nvim/quickfix.c b/src/nvim/quickfix.c index 2415858e0f..876d4e73d1 100644 --- a/src/nvim/quickfix.c +++ b/src/nvim/quickfix.c @@ -2564,7 +2564,7 @@ static char_u *get_mef_name(void) STRCAT(name, p + 2); // Don't accept a symbolic link, its a security risk. FileInfo file_info; - bool file_or_link_found = os_get_file_info_link((char *)name, &file_info); + bool file_or_link_found = os_fileinfo_link((char *)name, &file_info); if (!file_or_link_found) { break; } diff --git a/src/nvim/undo.c b/src/nvim/undo.c index 8c7b5b38e9..d7a691aa83 100644 --- a/src/nvim/undo.c +++ b/src/nvim/undo.c @@ -1116,8 +1116,8 @@ void u_write_undo(char_u *name, int forceit, buf_T *buf, char_u *hash) */ FileInfo file_info_old; FileInfo file_info_new; - if (os_get_file_info((char *)buf->b_ffname, &file_info_old) - && os_get_file_info((char *)file_name, &file_info_new) + if (os_fileinfo((char *)buf->b_ffname, &file_info_old) + && os_fileinfo((char *)file_name, &file_info_new) && file_info_old.stat.st_gid != file_info_new.stat.st_gid && os_fchown(fd, -1, file_info_old.stat.st_gid) != 0) { os_setperm(file_name, (perm & 0707) | ((perm & 07) << 3)); @@ -1249,8 +1249,8 @@ void u_read_undo(char_u *name, char_u *hash, char_u *orig_name) * owner of the text file or equal to the current user. */ FileInfo file_info_orig; FileInfo file_info_undo; - if (os_get_file_info((char *)orig_name, &file_info_orig) - && os_get_file_info((char *)file_name, &file_info_undo) + if (os_fileinfo((char *)orig_name, &file_info_orig) + && os_fileinfo((char *)file_name, &file_info_undo) && file_info_orig.stat.st_uid != file_info_undo.stat.st_uid && file_info_undo.stat.st_uid != getuid()) { if (p_verbose > 0) { |