Subject: rename() in B18..
From: [email-masked] (Keet)

13 Jun 1997 03:19:30 -0700
Approved: [email-masked]
Distribution: cygnus
Message-ID: <[email-masked]>
Mime-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
X-Sender: [email-masked]
X-Mailer: Windows Eudora Pro Version 2.2 (32)
X-Priority: 1 (Highest)
Original-To: [email-masked]
Original-Sender: [email-masked]

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
  [email-masked]

-
For help on using this list (especially unsubscribing), send a message to
"[email-masked]" with one line of text: "help".