This is the mail archive of the
cygwin
mailing list for the Cygwin project.
rename() cannot replace the file which is opened with writable access
- From: Masamichi Hosoda <trueroad at trueroad dot jp>
- To: cygwin at cygwin dot com
- Cc: trueroad at trueroad dot jp
- Date: Thu, 12 Jan 2017 09:07:46 +0900 (JST)
- Subject: rename() cannot replace the file which is opened with writable access
- Authentication-results: sourceware.org; auth=none
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.
```
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#define OLDPATH "oldpath"
#define NEWPATH "newpath"
int main ()
{
int fd;
struct flock fl;
char buff[] = "test";
/* create oldpath file */
fd = open (OLDPATH, O_CREAT | O_RDWR | O_TRUNC, 0666);
close (fd);
/* create newpath file */
fd = open (NEWPATH, O_CREAT | O_RDWR | O_TRUNC, 0666);
/* rename *** FAILED on Cygwin *** */
if (rename (OLDPATH, NEWPATH) < 0)
perror ("rename");
close (fd);
return 0;
}
```
Thanks
--
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