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: UNLINK problem (again!!)


Martine Carannante wrote:

> $ ./testop
> Create file
> unlink file
> Create Again the file
> Error Create: : Permission denied

>        printf("Create file\n");
>        if((fp=fopen("toto","a+"))==NULL) {
>                perror("Error Create: ");
>                exit(255);
>        }
>        printf("unlink file\n");
>        ret=unlink("toto");
>        if (ret != 0) {
>                perror("Error Unlink: ");
>                exit(255);
>        }
>        printf("Create Again the file\n");
>        if((fp=fopen("toto","a+"))==NULL) {


  You didn't close the first filehandle.

  This is Cygwin correctly implementing the POSIX "can delete a file while
retaining a handle to its contents" semantic, followed by the known Cygwin
problem (a restiction of the underlying windows OS) that you can't (as you can
in POSIX) create a new file in place of the old one while you keep that handle
to the old one's contents.

  If you add an "fclose (fp)" before the unlink, or after the unlink but
before the second attempt to open, it works.

    cheers,
      DaveK

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


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