Quote Originally Posted by NooNoo View Post
[headache]pointers[/headache]
In all honesty, understanding them as "theory" in the absence of good examples is a headache that makes no sense, but when you start using them it all becomes clear...

Come on, what's not to love in such a code (part of an embedded webserver where saving memory and efficient use of the 12.5MHz clock is important)
PHP Code:
if(pSocket->step==1)
  {
    
maxBytes=sizeof(pSocket->outBuffer) - (pSocket->pData pSocket->outBuffer) - pSocket->nDataLeft 1;
    if(
maxBytes>1000)
    {
      
maxBytes=1000;
    }
    
fileBytes=fat_read_file(pSocket->filePtr, (unsigned char*)(pSocket->outBuffer pSocket->nDataLeft), maxBytes);
    if(
fileBytes>0)
    {
      *(
pSocket->outBuffer pSocket->nDataLeft fileBytes)='\0';
      
pSocket->step pSocket->step 1//to stay at the same step if more data exists
    
}
    else
    {
      
fileBytes=0//avoid issues when returned an error case
      
fat_close_file(pSocket->filePtr);
      *
pSocket->pData '\0';  //null terminate output data
      
pSocket->pageReady 1;
    }
    
newBytes fileBytes;
  }