delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/1997/06/13/03:19:30

From: Keetnet AT wilmington DOT net (Keet)
Subject: rename() in B18..
13 Jun 1997 03:19:30 -0700 :
Approved: cygnus DOT gnu-win32 AT cygnus DOT com
Distribution: cygnus
Message-ID: <2.2.32.19970613015953.00687970.cygnus.gnu-win32@wilmington.net>
Mime-Version: 1.0
X-Sender: keetnet AT wilmington DOT net
X-Mailer: Windows Eudora Pro Version 2.2 (32)
X-Priority: 1 (Highest)
Original-To: gnu-win32 AT cygnus DOT com
Original-Sender: owner-gnu-win32 AT cygnus DOT com

The following C code example, is proof that RENAME() or UNLINK() does not
work reliably. After being told so many times it's the source's fault, I'm
relieved to have found someone who knows what they're talking about and who
could help me with this. What's happening is that when a file is unlinked,
it isn't really unlinked. From what I'm told, there is no way to UNLINK an
open file under a FAT based system. This is because in a FAT based system,
the filename IS the file.. under UNIX, this is not the case. How you got
around that, is beyond me. From what I can tell, the file is NOT unlinked,
because when the following test program ends, test1 still exists. If this is
not the case, then it's still failing to rename, because I get an error, and
both test1 and test2 still exist. This isn't normal operation. Under 17.1
this worked lovely, no problem at all. It even worked in Linux.. but under
18.. it messes up completely. If anyone can offer any help to me.. please
reply ASAP.

==============================START TEST.C====================================

/* rename() and unlink() failure */
#include <stdio.h>

main()
{
    FILE *test1,*test2;
    
    if( (test1=fopen("test1","w")) == NULL) {
	printf("Unable to fopen() test1!\n");
	exit(1);
    }
    
    if( (test2=fopen("test2","w")) == NULL) {
	printf("Unable to fopen() test2!\n");
	exit(1);
    }
    
    if( fputs("This is test 1...\n",test1) < 0) {
	printf("Unable to write to test1!\n");
	exit(1);
    }
    
    if( fputs("This is test 2...\n",test2) < 0) {
	printf("Unable to write to test2!\n");
	exit(1);
    }
    
    if( unlink("test1") < 0) {
	printf("Unable to unlink test1!\n");
	exit(1);
    }
    
    if( rename("test2","test1") < 0 ) {
	printf("Unable to rename test2 to test1!\n");
	exit(1);
    }
    
    fclose(test1);
    fclose(test2);
}

==================================END TEST.C=================================

- Greg Neujahr
  Keet - Foxbird
  keetnet AT wilmington DOT net


-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request AT cygnus DOT com" with one line of text: "help".

- Raw text -


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