aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorStefan Hoffmann <stefan991@gmail.com>2014-04-25 16:01:41 +0200
committerStefan Hoffmann <stefan991@gmail.com>2014-05-09 15:49:32 +0200
commitedbb687b73877d8db8b1c6e376e3422bb85a11a9 (patch)
treef4b6af6d46561876e3aa559ca75621a92f7bbe3f /src
parentf3dda65de157f2d7c35286018c20cbc7597ed748 (diff)
downloadrneovim-edbb687b73877d8db8b1c6e376e3422bb85a11a9.tar.gz
rneovim-edbb687b73877d8db8b1c6e376e3422bb85a11a9.tar.bz2
rneovim-edbb687b73877d8db8b1c6e376e3422bb85a11a9.zip
replaced some mch_stat() with os_file_exists()
Diffstat (limited to 'src')
-rw-r--r--src/ex_cmds.c8
-rw-r--r--src/fileio.c20
-rw-r--r--src/memline.c7
-rw-r--r--src/spell.c5
-rw-r--r--src/undo.c16
5 files changed, 19 insertions, 37 deletions
diff --git a/src/ex_cmds.c b/src/ex_cmds.c
index eb42acd93f..c2c3b6631d 100644
--- a/src/ex_cmds.c
+++ b/src/ex_cmds.c
@@ -1492,7 +1492,6 @@ void write_viminfo(char_u *file, int forceit)
FILE *fp_in = NULL; /* input viminfo file, if any */
FILE *fp_out = NULL; /* output viminfo file */
char_u *tempname = NULL; /* name of temp viminfo file */
- struct stat st_new; /* mch_stat() of potential new file */
char_u *wp;
#if defined(UNIX)
mode_t umask_save;
@@ -1511,7 +1510,7 @@ void write_viminfo(char_u *file, int forceit)
fp_in = mch_fopen((char *)fname, READBIN);
if (fp_in == NULL) {
/* if it does exist, but we can't read it, don't try writing */
- if (mch_stat((char *)fname, &st_new) == 0)
+ if (os_file_exists(fname))
goto end;
#if defined(UNIX)
/*
@@ -1563,7 +1562,7 @@ void write_viminfo(char_u *file, int forceit)
* Check if tempfile already exists. Never overwrite an
* existing file!
*/
- if (mch_stat((char *)tempname, &st_new) == 0) {
+ if (os_file_exists(tempname)) {
/*
* Try another name. Change one character, just before
* the extension.
@@ -1571,8 +1570,7 @@ void write_viminfo(char_u *file, int forceit)
wp = tempname + STRLEN(tempname) - 5;
if (wp < path_tail(tempname)) /* empty file name? */
wp = path_tail(tempname);
- for (*wp = 'z'; mch_stat((char *)tempname, &st_new) == 0;
- --*wp) {
+ for (*wp = 'z'; os_file_exists(tempname); --*wp) {
/*
* They all exist? Must be something wrong! Don't
* write the viminfo file then.
diff --git a/src/fileio.c b/src/fileio.c
index 8f2639064a..d7ee26297c 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -3444,8 +3444,6 @@ nobackup:
restore_backup:
{
- struct stat st;
-
/*
* If we failed to open the file, we don't need a backup. Throw it
* away. If we moved or removed the original file try to put the
@@ -3460,11 +3458,13 @@ restore_backup:
* In that case we leave the copy around.
*/
/* If file does not exist, put the copy in its place */
- if (mch_stat((char *)fname, &st) < 0)
+ if (!os_file_exists(fname)) {
vim_rename(backup, fname);
+ }
/* if original file does exist throw away the copy */
- if (mch_stat((char *)fname, &st) >= 0)
+ if (os_file_exists(fname)) {
os_remove((char *)backup);
+ }
} else {
/* try to put the original file back */
vim_rename(backup, fname);
@@ -3472,8 +3472,9 @@ restore_backup:
}
/* if original file no longer exists give an extra warning */
- if (!newfile && mch_stat((char *)fname, &st) < 0)
+ if (!newfile && !os_file_exists(fname)) {
end = 0;
+ }
}
if (wfname != fname)
@@ -3855,15 +3856,13 @@ restore_backup:
char *org = (char *)modname(fname, p_pm, FALSE);
if (backup != NULL) {
- struct stat st;
-
/*
* If the original file does not exist yet
* the current backup file becomes the original file
*/
if (org == NULL)
EMSG(_("E205: Patchmode: can't save original file"));
- else if (mch_stat(org, &st) < 0) {
+ else if (!os_file_exists((char_u *)org)) {
vim_rename(backup, (char_u *)org);
free(backup); /* don't delete the file */
backup = NULL;
@@ -5527,9 +5526,6 @@ vim_tempname (
#ifdef TEMPDIRNAMES
static char *(tempdirs[]) = {TEMPDIRNAMES};
int i;
-# ifndef EEXIST
- struct stat st;
-# endif
/*
* This will create a directory for private use by this instance of Vim.
@@ -5580,7 +5576,7 @@ vim_tempname (
/* If mkdir() does not set errno to EEXIST, check for
* existing file here. There is a race condition then,
* although it's fail-safe. */
- if (mch_stat((char *)itmp, &st) >= 0)
+ if (os_file_exists(itmp))
continue;
# endif
# if defined(UNIX)
diff --git a/src/memline.c b/src/memline.c
index 53864e6b5d..a78b84512b 100644
--- a/src/memline.c
+++ b/src/memline.c
@@ -1607,12 +1607,9 @@ recover_names (
* Try finding a swap file by simply adding ".swp" to the file name.
*/
if (*dirp == NUL && file_count + num_files == 0 && fname != NULL) {
- struct stat st;
- char_u *swapname;
-
- swapname = modname(fname_res, (char_u *)".swp", TRUE);
+ char_u *swapname = modname(fname_res, (char_u *)".swp", TRUE);
if (swapname != NULL) {
- if (mch_stat((char *)swapname, &st) != -1) { /* It exists! */
+ if (os_file_exists(swapname)) {
files = (char_u **)alloc((unsigned)sizeof(char_u *));
files[0] = swapname;
swapname = NULL;
diff --git a/src/spell.c b/src/spell.c
index 5ee799ebf1..5392fe4a70 100644
--- a/src/spell.c
+++ b/src/spell.c
@@ -7768,7 +7768,6 @@ mkspell (
afffile_T *(afile[8]);
int i;
int len;
- struct stat st;
int error = FALSE;
spellinfo_T spin;
@@ -7832,7 +7831,7 @@ mkspell (
else {
// Check for overwriting before doing things that may take a lot of
// time.
- if (!over_write && mch_stat((char *)wfname, &st) >= 0) {
+ if (!over_write && os_file_exists(wfname)) {
EMSG(_(e_exists));
goto theend;
}
@@ -7888,7 +7887,7 @@ mkspell (
spin.si_region = 1 << i;
vim_snprintf((char *)fname, MAXPATHL, "%s.aff", innames[i]);
- if (mch_stat((char *)fname, &st) >= 0) {
+ if (os_file_exists(fname)) {
// Read the .aff file. Will init "spin->si_conv" based on the
// "SET" line.
afile[i] = spell_read_aff(&spin, fname);
diff --git a/src/undo.c b/src/undo.c
index a17ba50255..b93a3e6e32 100644
--- a/src/undo.c
+++ b/src/undo.c
@@ -675,7 +675,6 @@ char_u *u_get_undo_file_name(char_u *buf_ffname, int reading)
char_u *undo_file_name = NULL;
int dir_len;
char_u *p;
- struct stat st;
char_u *ffname = buf_ffname;
#ifdef HAVE_READLINK
char_u fname_buf[MAXPATHL];
@@ -723,7 +722,7 @@ char_u *u_get_undo_file_name(char_u *buf_ffname, int reading)
// When reading check if the file exists.
if (undo_file_name != NULL &&
- (!reading || mch_stat((char *)undo_file_name, &st) >= 0)) {
+ (!reading || os_file_exists(undo_file_name))) {
break;
}
free(undo_file_name);
@@ -1108,7 +1107,6 @@ void u_write_undo(char_u *name, int forceit, buf_T *buf, char_u *hash)
int perm;
int write_ok = FALSE;
#ifdef UNIX
- int st_old_valid = FALSE;
struct stat st_old;
struct stat st_new;
#endif
@@ -1135,16 +1133,10 @@ void u_write_undo(char_u *name, int forceit, buf_T *buf, char_u *hash)
*/
perm = 0600;
if (buf->b_ffname != NULL) {
-#ifdef UNIX
- if (mch_stat((char *)buf->b_ffname, &st_old) >= 0) {
- perm = st_old.st_mode;
- st_old_valid = TRUE;
- }
-#else
perm = os_getperm(buf->b_ffname);
- if (perm < 0)
+ if (perm < 0) {
perm = 0600;
-#endif
+ }
}
/* strip any s-bit */
@@ -1223,7 +1215,7 @@ void u_write_undo(char_u *name, int forceit, buf_T *buf, char_u *hash)
* this fails, set the protection bits for the group same as the
* protection bits for others.
*/
- if (st_old_valid
+ if (mch_stat((char *)buf->b_ffname, &st_old) >= 0
&& mch_stat((char *)file_name, &st_new) >= 0
&& st_new.st_gid != st_old.st_gid
# ifdef HAVE_FCHOWN /* sequent-ptx lacks fchown() */