replaced some mch_stat() with os_file_exists()

This commit is contained in:
Stefan Hoffmann
2014-04-25 16:01:41 +02:00
parent f3dda65de1
commit edbb687b73
5 changed files with 19 additions and 37 deletions

View File

@@ -1492,7 +1492,6 @@ void write_viminfo(char_u *file, int forceit)
FILE *fp_in = NULL; /* input viminfo file, if any */ FILE *fp_in = NULL; /* input viminfo file, if any */
FILE *fp_out = NULL; /* output viminfo file */ FILE *fp_out = NULL; /* output viminfo file */
char_u *tempname = NULL; /* name of temp viminfo file */ char_u *tempname = NULL; /* name of temp viminfo file */
struct stat st_new; /* mch_stat() of potential new file */
char_u *wp; char_u *wp;
#if defined(UNIX) #if defined(UNIX)
mode_t umask_save; mode_t umask_save;
@@ -1511,7 +1510,7 @@ void write_viminfo(char_u *file, int forceit)
fp_in = mch_fopen((char *)fname, READBIN); fp_in = mch_fopen((char *)fname, READBIN);
if (fp_in == NULL) { if (fp_in == NULL) {
/* if it does exist, but we can't read it, don't try writing */ /* 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; goto end;
#if defined(UNIX) #if defined(UNIX)
/* /*
@@ -1563,7 +1562,7 @@ void write_viminfo(char_u *file, int forceit)
* Check if tempfile already exists. Never overwrite an * Check if tempfile already exists. Never overwrite an
* existing file! * existing file!
*/ */
if (mch_stat((char *)tempname, &st_new) == 0) { if (os_file_exists(tempname)) {
/* /*
* Try another name. Change one character, just before * Try another name. Change one character, just before
* the extension. * the extension.
@@ -1571,8 +1570,7 @@ void write_viminfo(char_u *file, int forceit)
wp = tempname + STRLEN(tempname) - 5; wp = tempname + STRLEN(tempname) - 5;
if (wp < path_tail(tempname)) /* empty file name? */ if (wp < path_tail(tempname)) /* empty file name? */
wp = path_tail(tempname); wp = path_tail(tempname);
for (*wp = 'z'; mch_stat((char *)tempname, &st_new) == 0; for (*wp = 'z'; os_file_exists(tempname); --*wp) {
--*wp) {
/* /*
* They all exist? Must be something wrong! Don't * They all exist? Must be something wrong! Don't
* write the viminfo file then. * write the viminfo file then.

View File

@@ -3444,8 +3444,6 @@ nobackup:
restore_backup: restore_backup:
{ {
struct stat st;
/* /*
* If we failed to open the file, we don't need a backup. Throw it * 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 * 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. * In that case we leave the copy around.
*/ */
/* If file does not exist, put the copy in its place */ /* 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); vim_rename(backup, fname);
}
/* if original file does exist throw away the copy */ /* 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); os_remove((char *)backup);
}
} else { } else {
/* try to put the original file back */ /* try to put the original file back */
vim_rename(backup, fname); vim_rename(backup, fname);
@@ -3472,8 +3472,9 @@ restore_backup:
} }
/* if original file no longer exists give an extra warning */ /* 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; end = 0;
}
} }
if (wfname != fname) if (wfname != fname)
@@ -3855,15 +3856,13 @@ restore_backup:
char *org = (char *)modname(fname, p_pm, FALSE); char *org = (char *)modname(fname, p_pm, FALSE);
if (backup != NULL) { if (backup != NULL) {
struct stat st;
/* /*
* If the original file does not exist yet * If the original file does not exist yet
* the current backup file becomes the original file * the current backup file becomes the original file
*/ */
if (org == NULL) if (org == NULL)
EMSG(_("E205: Patchmode: can't save original file")); 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); vim_rename(backup, (char_u *)org);
free(backup); /* don't delete the file */ free(backup); /* don't delete the file */
backup = NULL; backup = NULL;
@@ -5527,9 +5526,6 @@ vim_tempname (
#ifdef TEMPDIRNAMES #ifdef TEMPDIRNAMES
static char *(tempdirs[]) = {TEMPDIRNAMES}; static char *(tempdirs[]) = {TEMPDIRNAMES};
int i; int i;
# ifndef EEXIST
struct stat st;
# endif
/* /*
* This will create a directory for private use by this instance of Vim. * 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 /* If mkdir() does not set errno to EEXIST, check for
* existing file here. There is a race condition then, * existing file here. There is a race condition then,
* although it's fail-safe. */ * although it's fail-safe. */
if (mch_stat((char *)itmp, &st) >= 0) if (os_file_exists(itmp))
continue; continue;
# endif # endif
# if defined(UNIX) # if defined(UNIX)

View File

@@ -1607,12 +1607,9 @@ recover_names (
* Try finding a swap file by simply adding ".swp" to the file name. * Try finding a swap file by simply adding ".swp" to the file name.
*/ */
if (*dirp == NUL && file_count + num_files == 0 && fname != NULL) { if (*dirp == NUL && file_count + num_files == 0 && fname != NULL) {
struct stat st; char_u *swapname = modname(fname_res, (char_u *)".swp", TRUE);
char_u *swapname;
swapname = modname(fname_res, (char_u *)".swp", TRUE);
if (swapname != NULL) { 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 = (char_u **)alloc((unsigned)sizeof(char_u *));
files[0] = swapname; files[0] = swapname;
swapname = NULL; swapname = NULL;

View File

@@ -7768,7 +7768,6 @@ mkspell (
afffile_T *(afile[8]); afffile_T *(afile[8]);
int i; int i;
int len; int len;
struct stat st;
int error = FALSE; int error = FALSE;
spellinfo_T spin; spellinfo_T spin;
@@ -7832,7 +7831,7 @@ mkspell (
else { else {
// Check for overwriting before doing things that may take a lot of // Check for overwriting before doing things that may take a lot of
// time. // time.
if (!over_write && mch_stat((char *)wfname, &st) >= 0) { if (!over_write && os_file_exists(wfname)) {
EMSG(_(e_exists)); EMSG(_(e_exists));
goto theend; goto theend;
} }
@@ -7888,7 +7887,7 @@ mkspell (
spin.si_region = 1 << i; spin.si_region = 1 << i;
vim_snprintf((char *)fname, MAXPATHL, "%s.aff", innames[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 // Read the .aff file. Will init "spin->si_conv" based on the
// "SET" line. // "SET" line.
afile[i] = spell_read_aff(&spin, fname); afile[i] = spell_read_aff(&spin, fname);

View File

@@ -675,7 +675,6 @@ char_u *u_get_undo_file_name(char_u *buf_ffname, int reading)
char_u *undo_file_name = NULL; char_u *undo_file_name = NULL;
int dir_len; int dir_len;
char_u *p; char_u *p;
struct stat st;
char_u *ffname = buf_ffname; char_u *ffname = buf_ffname;
#ifdef HAVE_READLINK #ifdef HAVE_READLINK
char_u fname_buf[MAXPATHL]; 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. // When reading check if the file exists.
if (undo_file_name != NULL && if (undo_file_name != NULL &&
(!reading || mch_stat((char *)undo_file_name, &st) >= 0)) { (!reading || os_file_exists(undo_file_name))) {
break; break;
} }
free(undo_file_name); 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 perm;
int write_ok = FALSE; int write_ok = FALSE;
#ifdef UNIX #ifdef UNIX
int st_old_valid = FALSE;
struct stat st_old; struct stat st_old;
struct stat st_new; struct stat st_new;
#endif #endif
@@ -1135,16 +1133,10 @@ void u_write_undo(char_u *name, int forceit, buf_T *buf, char_u *hash)
*/ */
perm = 0600; perm = 0600;
if (buf->b_ffname != NULL) { 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); perm = os_getperm(buf->b_ffname);
if (perm < 0) if (perm < 0) {
perm = 0600; perm = 0600;
#endif }
} }
/* strip any s-bit */ /* 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 * this fails, set the protection bits for the group same as the
* protection bits for others. * 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 && mch_stat((char *)file_name, &st_new) >= 0
&& st_new.st_gid != st_old.st_gid && st_new.st_gid != st_old.st_gid
# ifdef HAVE_FCHOWN /* sequent-ptx lacks fchown() */ # ifdef HAVE_FCHOWN /* sequent-ptx lacks fchown() */