NS_IMETHOD                      Write(const char* aBuf, PRUint32 aCount, PRUint32 *aWriteCount) { NS_PRECONDITION(aBuf != nsnull, "null ptr"); NS_PRECONDITION(aWriteCount != nsnull, "null ptr");  *aWriteCount = 0;
NS_IMETHODIMP FileImpl::Write(const char* aBuf, PRUint32 aCount, PRUint32 *aWriteCount)  { NS_PRECONDITION(aBuf != nsnull, "null ptr"); NS_PRECONDITION(aWriteCount != nsnull, "null ptr");  *aWriteCount = 0;
		NS_IMETHOD                      Write(const char* aBuf,			                                PRUint32 aCount,					                        PRUint32 *aWriteCount)								        {								            NS_PRECONDITION(aBuf != nsnull, "null ptr");								            NS_PRECONDITION(aWriteCount != nsnull, "null ptr");                                                                                        *aWriteCount = 0;								#ifdef XP_MAC								            // Calling PR_Write on stdout is sure suicide.								            if (mFileDesc == PR_STDOUT || mFileDesc == PR_STDERR)								            {								                cout.write(aBuf, aCount);								                *aWriteCount = aCount;								                return NS_OK;								            }								#endif								            if (!mFileDesc)								                return NS_FILE_RESULT(PR_BAD_DESCRIPTOR_ERROR);								            if (mFailed)								               return NS_ERROR_FAILURE;                                            PRUint32 bufOffset = 0;                                            PRUint32 currentWrite = 0;                                            while (aCount > 0)                                             {                                                if (mWriteCursor == nsnull || mWriteCursor == mWriteLimit)                                                {                                                    char* seg = mOutBuffer.AppendNewSegment();                                                    if (seg == nsnull)                                                     {                                                        // buffer is full, try again                                                        Flush();                                                        seg = mOutBuffer.AppendNewSegment();                                                        if (seg == nsnull)                                                            return NS_ERROR_OUT_OF_MEMORY;                                                    }                                                    mWriteCursor = seg;                                                    mWriteLimit  = seg + mOutBuffer.GetSegmentSize();                                                }                                                                                                // move                                                                                                currentWrite = mWriteLimit - mWriteCursor;                                                                                                if (aCount < currentWrite)                                                    currentWrite = aCount;                                                memcpy(mWriteCursor, (aBuf + bufOffset), currentWrite);                                                                                                mWriteCursor += currentWrite;                                                                                                  aCount    -= currentWrite;                                                bufOffset += currentWrite;                                                *aWriteCount += currentWrite;                                            }									            return NS_OK;								        }