This is the mail archive of the newlib@sourceware.org mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: _REENT_SMALL IO broken


> > a) Every use of a file descriptor needs to check if it has the read FD,
> > or a dummy copy. In this case there's no point having the dummy
> > structure, we can just assign stdin/out/err magic values. As a bonus
> > _reent gets even smaller, at the expense of a small code size increase.

> IMO, the right solution is a) but not the 2nd part of your proposal.
> The reason we have the dummy structure is to handle the stdio macros
> (e.g. getc and putc).  For speed/compactness, we want them to think they
> are operating on a real FILE * and we set the values such that we always
> force a function call to occur based on their regular logic path.

I guess this is the only way to do it without slowing down the !_REENT_SMALL 
case. However consider:

#include <stdio.h>
int main()
{
  FILE *foo = stdout;
  fprintf(foo, "Hello World\n");
  if (foo != stdout)
    abort();
  return 0;
}

I find it surprising for this program to abort.

There are also more subtle bugs that can occur when using the dummy FILE* with 
the feof, ferror, and clearerr macros.

Paul


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]