Subject: bug#22795: 25.0.91; Can't write read only file on w32

From: "Ota, Takaaki" <[email-masked]>
Date: Mon, 29 Feb 2016 09:53:54 -0800

Mon, 29 Feb 2016 19:13:43 +0200: Eli Zaretskii <[email-masked]> wrote:

> > Date: Mon, 29 Feb 2016 08:40:35 -0800
> > CC: <[email-masked]>
> > From: "Ota, Takaaki" <[email-masked]>
> > 
> > I am now very much puzzled.  Here is the trace up to _wopen().  I
> > printed parameters to _wopen() and they are identical yet one succeeds
> > and the other fails.
> 
> Hmm... strange, indeed.
> 
> Do you have a dependency walker program?  (If not, you can download it
> from http://www.dependencywalker.com/.)  Can you tell whether the two
> executables differ in the versions of msvcrt.dll they are linked
> against?  Or any other dynamic libraries, for that matter?
> 
> Also, what is the value of errno after the _wopen call that fails?

4303            res = _wopen (mpath_w, (oflag & ~_O_CREAT) | _O_NOINHERIT, mode);
(gdb) s
4304          if (res < 0)
(gdb) p res
$6 = -1
(gdb) p errno
$7 = 13

So it must be this.

#define	EACCES		13	/* Permission denied */

> 
> Finally, what about this part of my questions, did you look into this:
> 
> > Also, I think by the time this code is run, the original file should
> > have been renamed to the backup-file name, so the file you are saving
> > should not exist on disk by the time we open it.  If that is not the
> > case with 25.0.91, then perhaps what fails is not the open call, but
> > the rename call before that.
> 
> Does the file that Emacs tries to open here, c:\d\ota\memo, exist when
> _wopen is called, and if so, is it read-only?  Please check this with
> both versions of Emacs, and see if there's any differences in what
> happens.

In both cases the original file exists right before calling _wopen()
but there is a difference.  On 25.0.91 the file remains read-only but
on 24.5 the file is writable right before calling _open().  Now we
have some clue here.

-Tak