[En-Nut-Discussion] fread() on serial port 0 problem

Michel changes at home.nl
Fri Nov 21 09:13:48 CET 2003


Hi,

I'm not really an expert in NutOS, but I do see one thing in your readFull()
function. And what I see is that you do not return when fread returns 0 bytes, only
when a negative number is returned.

Don't know if it helps, but I think you should return on 0 bytes as well.

Greets

Kyle Rhodes said:
>
> size_t readFull(void *ptr, size_t size, FILE *fp)
> {
>   size_t retVal;
>   size_t numRead = 0;
>   unsigned char *cptr;
>
>   cptr = (unsigned char *) ptr;
>
>   while(numRead < size)
>   {
>     retVal = fread(&cptr[numRead], 1, size - numRead, fp);
>
>     if(retVal < 0)                                  <------- change this into <=
>       return(retVal);
>
>     numRead += retVal;
>   }
>
>   return(numRead);
> }






More information about the En-Nut-Discussion mailing list