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]

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


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


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