Mail Archives: djgpp/1999/07/30/23:23:10
From: | "Pavlos" <trash24379 AT usa DOT net>
|
Newsgroups: | comp.os.msdos.djgpp
|
Subject: | Bug in ftruncate or not?
|
Date: | Thu, 29 Jul 1999 06:18:21 +0300
|
Organization: | An OTEnet S.A. customer
|
Message-ID: | <7noh88$a01$1@newssrv.otenet.gr>
|
NNTP-Posting-Host: | dram-a05.otenet.gr
|
X-Trace: | newssrv.otenet.gr 933218376 10241 195.167.113.228 (29 Jul 1999 03:19:36 GMT)
|
X-Complaints-To: | abuse AT otenet DOT gr
|
NNTP-Posting-Date: | 29 Jul 1999 03:19:36 GMT
|
X-Newsreader: | Microsoft Outlook Express 4.72.3110.1
|
X-MimeOLE: | Produced By Microsoft MimeOLE V4.72.3110.3
|
Lines: | 56
|
To: | djgpp AT delorie DOT com
|
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp
|
Reply-To: | djgpp AT delorie DOT com
|
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 <stdio.h>
#include <stdlib.h>
#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 --->
- Raw text -