diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2014-05-09 15:33:00 -0400 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2014-05-09 15:33:00 -0400 |
commit | 1a3ee71de258b416ca6b80f0a9e3b91460df8dc7 (patch) | |
tree | a59167e50add55b51ed31c65944cfa78ddd1c290 /src/undo.c | |
parent | f3dda65de157f2d7c35286018c20cbc7597ed748 (diff) | |
parent | eae498c4c5d34c1d0af40ecb430cbbc23b0a8e97 (diff) | |
download | rneovim-1a3ee71de258b416ca6b80f0a9e3b91460df8dc7.tar.gz rneovim-1a3ee71de258b416ca6b80f0a9e3b91460df8dc7.tar.bz2 rneovim-1a3ee71de258b416ca6b80f0a9e3b91460df8dc7.zip |
Merge pull request #619 from stefan991/mch_stat-cleanup
Replace `struct stat` with `FileInfo`
Diffstat (limited to 'src/undo.c')
-rw-r--r-- | src/undo.c | 45 |
1 files changed, 17 insertions, 28 deletions
diff --git a/src/undo.c b/src/undo.c index a17ba50255..47ce8ee8da 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); @@ -1107,11 +1106,6 @@ void u_write_undo(char_u *name, int forceit, buf_T *buf, char_u *hash) FILE *fp = NULL; int perm; int write_ok = FALSE; -#ifdef UNIX - int st_old_valid = FALSE; - struct stat st_old; - struct stat st_new; -#endif int do_crypt = FALSE; if (name == NULL) { @@ -1135,16 +1129,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,14 +1211,17 @@ 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 - && mch_stat((char *)file_name, &st_new) >= 0 - && st_new.st_gid != st_old.st_gid + 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) + && file_info_old.stat.st_gid != file_info_new.stat.st_gid # ifdef HAVE_FCHOWN /* sequent-ptx lacks fchown() */ - && fchown(fd, (uid_t)-1, st_old.st_gid) != 0 + && fchown(fd, (uid_t)-1, file_info_old.stat.st_gid) != 0 # endif - ) + ) { os_setperm(file_name, (perm & 0707) | ((perm & 07) << 3)); + } # ifdef HAVE_SELINUX if (buf->b_ffname != NULL) mch_copy_sec(buf->b_ffname, file_name); @@ -1351,10 +1342,6 @@ void u_read_undo(char_u *name, char_u *hash, char_u *orig_name) #ifdef U_DEBUG int *uhp_table_used; #endif -#ifdef UNIX - struct stat st_orig; - struct stat st_undo; -#endif int do_decrypt = FALSE; if (name == NULL) { @@ -1365,10 +1352,12 @@ void u_read_undo(char_u *name, char_u *hash, char_u *orig_name) #ifdef UNIX /* For safety we only read an undo file if the owner is equal to the * owner of the text file or equal to the current user. */ - if (mch_stat((char *)orig_name, &st_orig) >= 0 - && mch_stat((char *)file_name, &st_undo) >= 0 - && st_orig.st_uid != st_undo.st_uid - && st_undo.st_uid != getuid()) { + 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) + && file_info_orig.stat.st_uid != file_info_undo.stat.st_uid + && file_info_undo.stat.st_uid != getuid()) { if (p_verbose > 0) { verbose_enter(); smsg((char_u *)_("Not reading undo file, owner differs: %s"), |