rename() cannot replace the file which is opened with writable access
Masamichi Hosoda
trueroad@trueroad.jp
Thu Jan 12 00:07:00 GMT 2017
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
More information about the Cygwin
mailing list