err = ::SetEOF(refnum, 0);
err = SetEOF(refnum, 0);
NS_IMETHODIMP FileImpl::Open(    const nsFileSpec& inFile,    int nsprMode,    PRIntn accessMode)//----------------------------------------------------------------------------------------{    if (mFileDesc)        if ((nsprMode & mNSPRMode) == nsprMode)            return NS_OK;        else            return NS_FILE_RESULT(PR_ILLEGAL_ACCESS_ERROR);            const int nspr_modes[]={        PR_WRONLY | PR_CREATE_FILE,        PR_WRONLY | PR_CREATE_FILE | PR_APPEND,        PR_WRONLY | PR_CREATE_FILE | PR_TRUNCATE,        PR_RDONLY,        PR_RDONLY | PR_APPEND,        PR_RDWR | PR_CREATE_FILE,        PR_RDWR | PR_CREATE_FILE | PR_TRUNCATE,//      "wb",//      "ab", //      "wb",//      "rb",//      "r+b",//      "w+b",        0 };    const int* currentLegalMode = nspr_modes;    while (*currentLegalMode && nsprMode != *currentLegalMode)        ++currentLegalMode;    if (!*currentLegalMode)         return NS_FILE_RESULT(PR_ILLEGAL_ACCESS_ERROR);#ifdef XP_MAC     // Use the file spec to open the file, because one path can be common to     // several files on the Macintosh (you can have several volumes with the     // same name, see).    mFileDesc = 0;    OSErr err = inFile.Error();    if (err != noErr)      if (err != fnfErr || !(nsprMode & PR_CREATE_FILE))          return NS_FILE_RESULT(inFile.Error());    err = noErr;#if DEBUG    const OSType kCreator = 'CWIE';#else    const OSType kCreator = 'MOSS';#endif    // Resolve the alias to the original file.    nsFileSpec original = inFile;    PRBool ignoredResult;    original.ResolveSymlink(ignoredResult);    const FSSpec& spec = original.operator const FSSpec&();    if (nsprMode & PR_CREATE_FILE) {        // In order to get the right file type/creator, do it with an nsILocalFileMac        // Don't propagate any errors in doing this. If any error, just use FSpCreate.        FSSpec nonConstSpec = spec;        nsCOMPtr<nsILocalFileMac> macFile;        nsresult res = NS_NewLocalFileWithFSSpec(&nonConstSpec, PR_FALSE, getter_AddRefs(macFile));        if (NS_SUCCEEDED(res)) {            nsCOMPtr<nsIFile> asFile(do_QueryInterface(macFile, &res));            if (NS_SUCCEEDED(res)) {                res = asFile->Create(nsIFile::NORMAL_FILE_TYPE, 0);                if (res == NS_ERROR_FILE_ALREADY_EXISTS)                    res = NS_OK;            }        }        if (NS_FAILED(res))            err = FSpCreate(&spec, kCreator, 'TEXT', 0);    }    if (err == dupFNErr)        err = noErr;    if (err != noErr)        return NS_FILE_RESULT(err);        SInt8 perm;    if (nsprMode & PR_RDWR)       perm = fsRdWrPerm;    else if (nsprMode & PR_WRONLY)       perm = fsWrPerm;    else       perm = fsRdPerm;    short refnum;    err = FSpOpenDF(&spec, perm, &refnum);    if (err == noErr && (nsprMode & PR_TRUNCATE))        err = ::SetEOF(refnum, 0);    if (err == noErr && (nsprMode & PR_APPEND))        err = SetFPos(refnum, fsFromLEOF, 0);    if (err != noErr)        return NS_FILE_RESULT(err);    if ((mFileDesc = PR_ImportFile(refnum)) == 0)        return NS_FILE_RESULT(PR_GetError());#else    //    Platforms other than Macintosh...    //  Another bug in NSPR: Mac PR_Open assumes a unix style path, but Win PR_Open assumes    //  a windows path.    if ((mFileDesc = PR_Open((const char*)nsFileSpec(inFile), nsprMode, accessMode)) == 0)        return NS_FILE_RESULT(PR_GetError());#endif     mNSPRMode = nsprMode;     mLength = PR_Available(mFileDesc);     return NS_OK;} // FileImpl::Open