NS_IMETHODIMP FileImpl::Seek(PRInt32 whence, PRInt32 offset)
NS_IMETHODIMP FileImpl::Seek(PRSeekWhence whence, PRInt32 offset)
NS_IMETHODIMP FileImpl::Seek(PRInt32 whence, PRInt32 offset)//----------------------------------------------------------------------------------------{    if (mFileDesc==PR_STDIN || mFileDesc==PR_STDOUT || mFileDesc==PR_STDERR || !mFileDesc)        return NS_FILE_RESULT(PR_BAD_DESCRIPTOR_ERROR);    mFailed = PR_FALSE; // reset on a seek.    mEOF = PR_FALSE; // reset on a seek.        // To avoid corruption, we flush during a seek. see bug number 18949    Flush();    PRInt32 position = PR_Seek(mFileDesc, 0, PR_SEEK_CUR);    PRInt32 available = PR_Available(mFileDesc);    PRInt32 fileSize = position + available;    PRInt32 newPosition = 0;    switch (whence)    {        case PR_SEEK_CUR: newPosition = position + offset; break;        case PR_SEEK_SET: newPosition = offset; break;        case PR_SEEK_END: newPosition = fileSize + offset; break;    }    if (newPosition < 0)    {        newPosition = 0;        mFailed = PR_TRUE;    }    if (newPosition >= fileSize) // nb: not "else if".    {        newPosition = fileSize;        mEOF = PR_TRUE;    }    if (PR_Seek(mFileDesc, newPosition, PR_SEEK_SET) < 0)        mFailed = PR_TRUE;    return NS_OK;} // FileImpl::Seek