This is the mail archive of the
cygwin
mailing list for the Cygwin project.
Re: rename() cannot replace the file which is opened with writable access
- From: "L. A. Walsh" <cygwin at tlinx dot org>
- To: cygwin at cygwin dot com
- Date: Thu, 12 Jan 2017 11:06:52 -0800
- Subject: Re: rename() cannot replace the file which is opened with writable access
- Authentication-results: sourceware.org; auth=none
- References: <20170112.090746.2056666314950620331.trueroad@trueroad.jp>
Masamichi Hosoda wrote:
Hello,
I've found that rename() cannot replace the file
which is opened with writable access on Cygwin.
On Linux, it works.
If I understand correctly, it should work under POSIX.
Here's sample code for reproduce.
---
#define OLDPATH "oldpath"
#define NEWPATH "newpath"
int main () {
int fd;
struct flock fl;
char buff[] = "test";
fd = open (OLDPATH, O_CREAT | O_RDWR | O_TRUNC, 0666);
close (fd);
fd = open (NEWPATH, O_CREAT | O_RDWR | O_TRUNC, 0666);
if (rename (OLDPATH, NEWPATH) < 0) perror ("rename");
----
What are you trying to do by renaming the oldfile
over the top of a still-open-for-write, "newfile".
Why rename over the top of another file? What are you trying
to do? Maybe there is a better way to do it? ;-).
--
Problem reports: http://cygwin.com/problems.html
FAQ: http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple