> >From: "TsR" <[EMAIL PROTECTED]>
> >To: <[email protected]>
> >Subject: notice about fread_word buggy code
> >Date: Wed, 4 Jun 2003 14:37:07 +0300
> >
> >Hey list,
> >I was having a problem with fread_word function
> >[****] BUG: Fread_word: word too long.
> >
> >If anyone is having same problem and seems that everything is fine make
> >sure
> >That there IS NO EMPTY area/ban.txt file - because if it is empty them
> >fread_word tries
> >To read data from the file that is empty with no trailing ~ and
> >incorrect syntax (well
> >It is empty - what syntax can there be)
> >
> >444 load_bans();
> >(gdb) n
> >Wed Jun 4 14:09:24 2003 :: [*****] BUG: Fread_word: word too long.
> >---------------
> >
> >Just add this modification to your ban.c:load_bans()
> >void load_bans(void)
> >{
> > FILE *fp;
> > char buf[MSL];
> >+ int pos; /* Rand */
> >
> > if ( ( fp = fopen( BAN_FILE, "r" ) ) == NULL )
> > return;
> >
> >+ /* Rand */
> >+ fseek(fp, 0L, SEEK_END);
> >+ pos = ftell(fp);
> >+ if ( pos == 0 ) {
> >+ sprintf( buf, "Load_bans: size of %s = %i. Delete the
> >file!", BAN_FILE, pos);
> >+ bug( buf, 0);
> >+ return;
> >+ }
> > ...
You can also use fstat :
{
FILE * fp;
struct stat file_info;
if( !(fp = fopen(BAN_FILE, "r"))
|| fstat(fileno(fp), &file_info)
|| ( file_info.st_size == 0 ) )
{
bug("Error loading ban file", 0);
return;
}
}
~Kender
=====
-----BEGIN GEEK CODE BLOCK-----
Version 3.1
GCS/L/C/O d-(+) s++: a-- C+++$>++++ UBLS++++$
P+++(--)$ L+++>++++ E--- W+>++$ N !o K? w(--) !O
M- !V PS+ PE(++) Y+ PGP->+ t+ 5 X+() R(+) tv+@
b++(+++) !DI+++ D G(-) e>+++$ h---() r+++ y+++
------END GEEK CODE BLOCK------
__________________________________
Do you Yahoo!?
Yahoo! Calendar - Free online calendar with sync to Outlook(TM).
http://calendar.yahoo.com