Mail Archives: djgpp-workers/2000/11/10/04:17:44
> Date: Thu, 09 Nov 2000 23:26:23 +0000
> From: Richard Dawe <richdawe AT bigfoot DOT com>
It's been a long time since that discussion, and I have a bad habit of
forgetting minor details, so please take what I say below with a grain
of salt.
> Richard Dawe wrote:
> > static __inline__ int __putc_raw(int const x,FILE *const p)
> > {
> > if(p->_cnt>0)
> > {
> > p->_cnt--;
> > return((unsigned char)(*(p->_ptr++)=(unsigned char)x));
> > } else if (p->_flag & _IOSTR)
> > {
> > /* For String stream never flush. And we also mimic the
> > * GNU libc by keep on counting.
> > */
> > p->cnt--;
> > return 0;
> > }
> > return(_flsbuf(x,p));
> > }
[snip]
> > Why do we need to get to negative values of _cnt at all? We could
> > simply leave alone the _cnt member of the FILE object for _IOSTRG
> > ``streams''.
>
> I have to admit, reading this again, I am confused by what you say, Eli.
> If you don't track the position in the buffer using _cnt, what do you use?
p->_cnt is not used for tracking the position, it is only used to know
how much more free space do we have in p->_buf. To track the buffer
position, we use p->_ptr; see the code above.
> Maybe I have an idea that will work. The intention of returning EOF is to
> stop _cnt wrapping round.
I think that returning EOF should be a sign of some error. What error
do we have here, that we need EOF?
> _cnt is an int, whereas snprintf()'s buffer size
> is a size_t. Firstly, change _cnt to a ssize_t. Then place a restriction
> on the maximum buffer size, namely the maximum (positive) number that can
> be stored in both a size_t and ssize_t. Now, what error to return, when
> the buffer size is bigger than this?
Are you trying to solve the problem of the argument n being too large?
If so, how does this relate to _cnt being negative?
- Raw text -