mirror of
https://github.com/neovim/neovim.git
synced 2025-09-28 22:18:33 +00:00
implemented os_file_get_size()
This commit is contained in:
@@ -863,8 +863,6 @@ void ex_diffpatch(exarg_T *eap)
|
|||||||
char_u dirbuf[MAXPATHL];
|
char_u dirbuf[MAXPATHL];
|
||||||
char_u *fullname = NULL;
|
char_u *fullname = NULL;
|
||||||
#endif // ifdef UNIX
|
#endif // ifdef UNIX
|
||||||
struct stat st;
|
|
||||||
|
|
||||||
// We need two temp file names.
|
// We need two temp file names.
|
||||||
// Name of original temp file.
|
// Name of original temp file.
|
||||||
char_u *tmp_orig = vim_tempname('o');
|
char_u *tmp_orig = vim_tempname('o');
|
||||||
@@ -965,7 +963,9 @@ void ex_diffpatch(exarg_T *eap)
|
|||||||
os_remove((char *)buf);
|
os_remove((char *)buf);
|
||||||
|
|
||||||
// Only continue if the output file was created.
|
// Only continue if the output file was created.
|
||||||
if ((mch_stat((char *)tmp_new, &st) < 0) || (st.st_size == 0)) {
|
off_t file_size;
|
||||||
|
bool file_size_success = os_get_file_size((char *)tmp_new, &file_size);
|
||||||
|
if (!file_size_success || file_size == 0) {
|
||||||
EMSG(_("E816: Cannot read patch output"));
|
EMSG(_("E816: Cannot read patch output"));
|
||||||
} else {
|
} else {
|
||||||
if (curbuf->b_fname != NULL) {
|
if (curbuf->b_fname != NULL) {
|
||||||
|
18
src/eval.c
18
src/eval.c
@@ -9687,25 +9687,25 @@ static void f_getfperm(typval_T *argvars, typval_T *rettv)
|
|||||||
*/
|
*/
|
||||||
static void f_getfsize(typval_T *argvars, typval_T *rettv)
|
static void f_getfsize(typval_T *argvars, typval_T *rettv)
|
||||||
{
|
{
|
||||||
char_u *fname;
|
char *fname = (char *)get_tv_string(&argvars[0]);
|
||||||
struct stat st;
|
|
||||||
|
|
||||||
fname = get_tv_string(&argvars[0]);
|
|
||||||
|
|
||||||
rettv->v_type = VAR_NUMBER;
|
rettv->v_type = VAR_NUMBER;
|
||||||
|
|
||||||
if (mch_stat((char *)fname, &st) >= 0) {
|
off_t file_size;
|
||||||
if (os_isdir(fname))
|
if (os_get_file_size(fname, &file_size)) {
|
||||||
|
if (os_isdir((char_u *)fname))
|
||||||
rettv->vval.v_number = 0;
|
rettv->vval.v_number = 0;
|
||||||
else {
|
else {
|
||||||
rettv->vval.v_number = (varnumber_T)st.st_size;
|
rettv->vval.v_number = (varnumber_T)file_size;
|
||||||
|
|
||||||
/* non-perfect check for overflow */
|
/* non-perfect check for overflow */
|
||||||
if ((off_t)rettv->vval.v_number != (off_t)st.st_size)
|
if ((off_t)rettv->vval.v_number != file_size) {
|
||||||
rettv->vval.v_number = -2;
|
rettv->vval.v_number = -2;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else
|
} else {
|
||||||
rettv->vval.v_number = -1;
|
rettv->vval.v_number = -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
10
src/os/fs.c
10
src/os/fs.c
@@ -189,6 +189,16 @@ int os_file_is_writable(const char *name)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool os_get_file_size(const char *name, off_t *size)
|
||||||
|
{
|
||||||
|
uv_stat_t statbuf;
|
||||||
|
if (os_stat((char_u *)name, &statbuf) == OK) {
|
||||||
|
*size = statbuf.st_size;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
int os_rename(const char_u *path, const char_u *new_path)
|
int os_rename(const char_u *path, const char_u *new_path)
|
||||||
{
|
{
|
||||||
uv_fs_t request;
|
uv_fs_t request;
|
||||||
|
@@ -58,6 +58,12 @@ bool os_file_is_readonly(const char *name);
|
|||||||
/// @return `2` for a directory which we have rights to write into.
|
/// @return `2` for a directory which we have rights to write into.
|
||||||
int os_file_is_writable(const char *name);
|
int os_file_is_writable(const char *name);
|
||||||
|
|
||||||
|
/// 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);
|
||||||
|
|
||||||
/// Rename a file or directory.
|
/// Rename a file or directory.
|
||||||
///
|
///
|
||||||
/// @return `OK` for success, `FAIL` for failure.
|
/// @return `OK` for success, `FAIL` for failure.
|
||||||
|
Reference in New Issue
Block a user