/* Open with O_EXCL to avoid the file being created while
* we were sleeping (symlink hacker attack?) */
bfd = mch_open((char *)backup,
- O_WRONLY|O_CREAT|O_EXTRA|O_EXCL, 0666);
+ O_WRONLY|O_CREAT|O_EXTRA|O_EXCL, perm & 0777);
if (bfd < 0)
{
vim_free(backup);
while ((fd = mch_open((char *)wfname, O_WRONLY | O_EXTRA | (append
? (forceit ? (O_APPEND | O_CREAT) : O_APPEND)
: (O_CREAT | O_TRUNC))
- , 0666)) < 0)
+ , perm & 0777)) < 0)
{
/*
* A forced write will try to create a new file if the old one is
if ((fd = mch_open((char *)backup, O_RDONLY | O_EXTRA, 0)) >= 0)
{
if ((write_info.bw_fd = mch_open((char *)fname,
- O_WRONLY | O_CREAT | O_TRUNC | O_EXTRA, 0666)) >= 0)
+ O_WRONLY | O_CREAT | O_TRUNC | O_EXTRA,
+ perm & 0777)) >= 0)
{
/* copy the file. */
write_info.bw_buf = smallbuf;
if (org == NULL
|| (empty_fd = mch_open(org, O_CREAT | O_EXTRA | O_EXCL,
- 0666)) < 0)
+ perm & 0777)) < 0)
EMSG(_("E206: patchmode: can't touch empty original file"));
else
close(empty_fd);
BPTR flock;
#endif
struct stat st;
+ long perm;
/*
* When the names are identical, there is nothing to do.
/*
* Rename() failed, try copying the file.
*/
+ perm = mch_getperm(from);
fd_in = mch_open((char *)from, O_RDONLY|O_EXTRA, 0);
if (fd_in == -1)
return -1;
- fd_out = mch_open((char *)to, O_CREAT|O_EXCL|O_WRONLY|O_EXTRA, 0666);
+
+ /* Create the new file with same permissions as the original. */
+ fd_out = mch_open((char *)to, O_CREAT|O_EXCL|O_WRONLY|O_EXTRA, (int)perm);
if (fd_out == -1)
{
close(fd_in);
errmsg = _("E210: Error reading \"%s\"");
to = from;
}
+ mch_setperm(to, perm);
if (errmsg != NULL)
{
EMSG2(errmsg, to);