Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 11 Mar 2009 09:45:57 +0100
From:      =?UTF-8?B?VsOhY2xhdiBIYWlzbWFu?= <v.haisman@sh.cvut.cz>
Cc:        freebsd-hackers@freebsd.org
Subject:   Re: fgetc doubts
Message-ID:  <49B77A45.3000204@sh.cvut.cz>
In-Reply-To: <49B6DC95.9070607@FreeBSD.org>
References:  <49B6DC95.9070607@FreeBSD.org>

next in thread | previous in thread | raw e-mail | index | archive | help
Gábor Kövesdán wrote, On 10.3.2009 22:33:
> Hello,
> 
> I have a problem when reading files with fgetc when a 0xff character
> comes. In my code the reading stops at that point as if EOF had been
> reached, but that's not actually the case.
> The code is here:
> http://p4web.freebsd.org/@md=d&cd=//&c=Nsd@//depot/projects/soc2008/gabor_textproc/grep/file.c?ac=64&rev1=40
You have a bug in the grep_fgetc() function in the BZIP case. Char type is
signed on FreeBSD and you are sign extending the c variable in the "return
(c)" statement. The line should read "return ((unsigned char)c)", if you want
to model the function using the same semantics as C99 fgetc().

> 
> And the problem occurs in grep_fgetln() when the buffers is being filled
> in:
>            for (; i < bufsiz && !grep_feof(f); i++)
>                binbuf[i] = grep_fgetc(f);
> 
> Thanks in advance,
> 

--
VH



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?49B77A45.3000204>