if(numtowrite <= 0) return NS_ERROR_FAILURE;
if (numtowrite <= 0) { rv = NS_ERROR_FAILURE; goto error; }
ns4xPluginStreamListener::OnDataAvailable(nsIPluginStreamInfo* pluginInfo,                                          nsIInputStream* input,                                          PRUint32 length){  if(!mInst)    return NS_ERROR_FAILURE;  const NPPluginFuncs *callbacks = nsnull;  NPP npp;  mInst->GetCallbacks(&callbacks);  mInst->GetNPP(&npp);  if(!callbacks || !npp->pdata)    return NS_ERROR_FAILURE;  PRUint32  numtowrite = 0;  PRUint32  amountRead = 0;  PRInt32   writeCount = 0;  pluginInfo->GetURL(&mNPStream.url);  pluginInfo->GetLastModified((PRUint32*)&(mNPStream.lastmodified));  if (callbacks->write == nsnull || length == 0)    return NS_OK; // XXX ?  // Get the data from the input stream  char* buffer = (char*) PR_Malloc(length);  if (buffer)     input->Read(buffer, length, &amountRead);  // amountRead tells us how many bytes were put in the buffer  // WriteReady returns to us how many bytes the plugin is   // ready to handle  - we have to keep calling WriteReady and  // Write until the buffer is empty  while (amountRead > 0)  {    if (callbacks->writeready != NULL)    {      PRLibrary* lib = nsnull;      PRBool started = PR_FALSE;      if(mInst)       {        lib = mInst->fLibrary;        started = mInst->IsStarted();      }      if (started)      {        NS_TRY_SAFE_CALL_RETURN(numtowrite, CallNPP_WriteReadyProc(callbacks->writeready,                                                                   npp,                                                                   &mNPStream), lib);      }      // if WriteReady returned 0, the plugin is not ready to handle       // the data, return FAILURE for now      if(numtowrite <= 0)        return NS_ERROR_FAILURE;      if (numtowrite > amountRead)        numtowrite = amountRead;    }    else     {      // if WriteReady is not supported by the plugin,       // just write the whole buffer      numtowrite = length;    }    if(numtowrite > 0)    {      PRLibrary* lib = mInst->fLibrary;      NS_TRY_SAFE_CALL_RETURN(writeCount, CallNPP_WriteProc(callbacks->write,                                                            npp,                                                            &mNPStream,                                                             mPosition,                                                            numtowrite,                                                            (void *)buffer), lib);      if(writeCount < 0)        return NS_ERROR_FAILURE;      amountRead -= numtowrite;      mPosition += numtowrite;    }  }  return NS_OK;}