delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2009/03/20/13:35:41

X-Recipient: archive-cygwin AT delorie DOT com
X-SWARE-Spam-Status: No, hits=-2.4 required=5.0 tests=AWL,BAYES_00,SPF_PASS
X-Spam-Check-By: sourceware.org
Message-ID: <49C3E438.4070301@gmail.com>
Date: Fri, 20 Mar 2009 18:45:12 +0000
From: Dave Korn <dave DOT korn DOT cygwin AT googlemail DOT com>
User-Agent: Thunderbird 2.0.0.17 (Windows/20080914)
MIME-Version: 1.0
To: cygwin AT cygwin DOT com
Subject: Re: UNLINK problem (again!!)
References: <49C3BF14 DOT 5000602 AT bull DOT net>
In-Reply-To: <49C3BF14.5000602@bull.net>
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

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/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019