if (callbacks->writeready != NULL) { #if !TARGET_CARBON   numtowrite = CallNPP_WriteReadyProc(callbacks->writeready, npp, &mNPStream); #endif  if (numtowrite > amountRead) numtowrite = amountRead; } else numtowrite = length;
PRLibrary* lib = nsnull; lib = mInst->fLibrary;
ns4xPluginStreamListener::OnDataAvailable(nsIPluginStreamInfo* pluginInfo,										  nsIInputStream* input,                                          PRUint32 length){	const NPPluginFuncs *callbacks;    NPP                 npp;	PRUint32			numtowrite = 0;	PRUint32			amountRead = 0;	PRInt32				writeCount = 0;    pluginInfo->GetURL(&mNPStream.url);    pluginInfo->GetLastModified((PRUint32*)&(mNPStream.lastmodified));    mInst->GetCallbacks(&callbacks);    mInst->GetNPP(&npp);    if (callbacks->write == NULL || 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)		{#if !TARGET_CARBON// pinkerton// relies on routine descriptors, not present in carbon. We need to fix this.		numtowrite = CallNPP_WriteReadyProc(callbacks->writeready,                                            npp,                                            &mNPStream);#endif				if (numtowrite > amountRead)			numtowrite = amountRead;		}		else // if WriteReady is not supported by the plugin, just write the whole buffer			numtowrite = length;		// if WriteReady returned 0, the plugin is not ready to handle the data,		// so just skip the Write until WriteReady returns a >0 value		if(numtowrite > 0)		{#if !TARGET_CARBON// pinkerton// relies on routine descriptors, not present in carbon. We need to fix this.			writeCount = CallNPP_WriteProc(callbacks->write,                                       npp,                                       &mNPStream,                                        mPosition,                                       numtowrite,                                       (void *)buffer);			if(writeCount < 0)				return NS_ERROR_FAILURE;#endif			amountRead -= numtowrite;			mPosition += numtowrite;		}    }    return NS_OK;}