From: "Pavlos" Newsgroups: comp.os.msdos.djgpp Subject: Re: Bug in ftruncate or not? Date: Sat, 31 Jul 1999 12:07:39 +0300 Organization: An OTEnet S.A. customer Lines: 77 Message-ID: <7nueht$8rp$1@newssrv.otenet.gr> References: <7noh88$a01$1 AT newssrv DOT otenet DOT gr> <37a15d60 DOT 24986840 AT newsserver DOT cc DOT monash DOT edu DOT au> NNTP-Posting-Host: dram-a01.otenet.gr X-Trace: newssrv.otenet.gr 933412221 9081 195.167.113.224 (31 Jul 1999 09:10:21 GMT) X-Complaints-To: abuse AT otenet DOT gr NNTP-Posting-Date: 31 Jul 1999 09:10:21 GMT X-Newsreader: Microsoft Outlook Express 4.72.3110.1 X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Thank you for your answers, both of them fix the problem. Pavlos Davin McCall wrote in message <37a15d60 DOT 24986840 AT newsserver DOT cc DOT monash DOT edu DOT au>... >Inserting "fflush(f)" immediately after the "fwrite" line solves the >problem. >Davin. > fred smith wrote in message ... >If you add: >fseek (f, 0L, SEEK_CUR); >immediately before the ftruncate it works fine. >Fred >On Thu, 29 Jul 1999 06:18:21 +0300, "Pavlos" >wrote: > >>Hello, >>I know that most of 'bug' reports are actually a fault of the user... Do I >>do something wrong here? >> >>This simple program will truncate the file only if you comment out #define >>BUGGY. >>At least in my PC... >>If you don't comment #define BUGGY, it won't truncate the file. >>Here is the code. >>When you run it, press '1' the first time to create the file. Then run it >>again and press '2' to truncate it. >>Thank you. >> >>Pavlos >> >><--- cut here ---> >> >>#include >>#include >> >>#define BUGGY >> >>int main(int argc, char **argv) >>{ >> FILE *f; >> char buf[1000]; >> >> printf("1: Create file (1000 bytes), 2:Truncate file (to 500)\n"); >> printf("Your choice: "); >> >> switch(getch()) >> { >> case '1': >> f = fopen("TEST1234.$$$", "wb+"); >> fwrite(buf, 1000, 1, f); >> return(0); >> >> case '2': >> f = fopen("TEST1234.$$$", "rb+"); >> fread(buf, 1000, 1, f); >> #ifdef BUGGY >> fseek(f, 500, SEEK_SET); >> fwrite(buf, 500, 1, f); >> #endif >> ftruncate(fileno(f), 500); >> return(0); >> >> default: >> return(0); >> } >>} >> >><--- cut here ---> >>