From: dbe AT wgn DOT net ("$Bill Luebkert") Subject: Re: rename() in B18.. 13 Jun 1997 20:54:51 -0700 Approved: cygnus DOT gnu-win32 AT cygnus DOT com Distribution: cygnus Message-ID: <33A1EEEC.1243.cygnus.gnu-win32@wgn.net> References: <2 DOT 2 DOT 32 DOT 19970613015953 DOT 00687970 AT wilmington DOT net> Reply-To: dbe AT wgn DOT net Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Mailer: Mozilla 3.01Gold (Win95; I) Original-To: Keet Original-CC: gnu-win32 AT cygnus DOT com Original-Sender: owner-gnu-win32 AT cygnus DOT com Keet wrote: > > 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 > > 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); > } Try moving these to here: fclose(test1); fclose(test2); > 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); And delete from here. > } > > ==================================END TEST.C================================= -- ,-/- __ _ _ $Bill Luebkert (_/ / ) // // DBE Collectibles / ) /--< o // // http://www.wgn.net/~dbe/ -/-' /___/_<_