This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

rename() cannot replace the file which is opened with writable access


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]