home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-17 | 23.6 KB | 908 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: SLFilRep.cpp
- // Release Version: $ ODF 2 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWOS.hpp"
-
- #ifndef FWEXCDEF_H
- #include "FWExcDef.h"
- #endif
-
- #ifndef FWFILE_H
- #include "FWFileSy.h"
- #endif
-
- #ifndef FWFILESP_H
- #include "FWFileSp.h"
- #endif
-
- #ifndef FWSOMENV_H
- #include "FWSOMEnv.h"
- #endif
-
- #if defined(FW_BUILD_WIN) && !defined(__WINDOWS_H)
- #include <windows.h>
- #endif
-
- #include <Limits.h>
-
- #ifndef FWPRIDEB_H
- #include "FWPriDeb.h"
- #endif
-
- #ifndef FWEXCDEF_H
- #include "FWExcDef.h"
- #endif
-
- #ifndef FWEXCEPT_H
- #include "FWExcept.h"
- #endif
-
- #if defined(FW_BUILD_MAC) && !defined(__FILES__)
- #include "Files.h"
- #endif
-
- #if defined(FW_BUILD_WIN) && !defined(IO_H)
- #include "io.h"
- #endif
-
- /*
- * This file was generated by the SOM Compiler.
- * Generated using:
- * SOM Emitter emitxtm.dll: 2.33
- */
-
- #define FW_OFile_Class_Source
- #include "SLFilRep.xih"
-
- #ifdef FW_BUILD_MAC
- #pragma segment File
- #endif
-
- #ifdef FW_BUILD_WIN16
- extern "C" void FAR PASCAL DOS3Call(); // We use this instead of calling "Int 21h"
- #endif
-
-
- //----------------------------------------------------------------------------------------
- // Forward definitions
- //----------------------------------------------------------------------------------------
-
- static void privOpenFile(FW_OFile *somSelf, Environment *ev, FW_Boolean allowCreate);
- static void privCloseFile(FW_OFile *somSelf, Environment *ev);
- static void privDoRead(FW_OFile *somSelf, Environment *ev, void* destination, long count);
- static void privDoWrite(FW_OFile *somSelf, Environment *ev, const void* source, long count);
-
- #ifdef FW_BUILD_WIN
- static short privWinGetIOBufferSize(long bytesDesired, const void* buffer);
- static FW_PlatformError privWinPrimitiveRead(FW_PlatformFileHandle handle,
- short bytesToRead,
- void* buffer,
- short& bytesActuallyRead);
- static FW_PlatformError privWinPrimitiveWrite(FW_PlatformFileHandle handle,
- short bytesToWrite,
- const void* buffer,
- short& bytesActuallyWritten);
-
- static FW_PlatformError privWinMoveFilePointer(FW_OFile *somSelf,
- Environment *ev,
- long markOffset,
- FW_EFS_MoveMethods positioningMode,
- long& newPosition);
- #endif
-
-
- //========================================================================================
- // struct FW_CPrivFileRep
- // This struct contains the body of the file representation
- //========================================================================================
-
- class FW_CPrivFileRep
- {
- public:
- FW_DECLARE_AUTO(FW_CPrivFileRep)
-
- FW_CPrivFileRep(Environment *ev,
- FW_OFileSpecification* fileSpecification);
- FW_CPrivFileRep(Environment *ev,
- FW_OFileSpecification* fileSpecification,
- FW_SAccessPermission* permission);
-
- ~FW_CPrivFileRep();
-
- FW_OFileSpecification* fFileSpec;
- FW_SAccessPermission fPermission;
- FW_PlatformFileHandle fFileHandle;
- };
-
-
- FW_DEFINE_AUTO(FW_CPrivFileRep)
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivFileRep::FW_CPrivFileRep
- //----------------------------------------------------------------------------------------
-
- inline FW_CPrivFileRep::FW_CPrivFileRep(Environment *ev,
- FW_OFileSpecification* fileSpecification) :
- fFileHandle(0)
- {
- fPermission.fAccess = FW_kReadWrite;
- fPermission.fDeny = FW_kDenyReadWrite;
- fFileSpec = new FW_OFileSpecification;
- fFileSpec->AssignOFileSpecification(ev, fileSpecification);
-
- FW_END_CONSTRUCTOR
- }
-
-
- inline FW_CPrivFileRep::FW_CPrivFileRep(Environment *ev,
- FW_OFileSpecification* fileSpecification,
- FW_SAccessPermission* permission) :
- fPermission(*permission),
- fFileHandle(0)
- {
- fFileSpec = new FW_OFileSpecification;
- fFileSpec->AssignOFileSpecification(ev, fileSpecification);
-
- FW_END_CONSTRUCTOR
- }
-
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivFileRep::~FW_CPrivFileRep
- //----------------------------------------------------------------------------------------
-
- inline FW_CPrivFileRep::~FW_CPrivFileRep()
- {
- FW_START_DESTRUCTOR
- delete fFileSpec;
- }
-
-
-
- //----------------------------------------------------------------------------------------
- // FW_OFile__InitWithExclusiveAccess
- // Open with exclusive access
- //----------------------------------------------------------------------------------------
-
- SOM_Scope void SOMLINK FW_OFile__InitWithExclusiveAccess(FW_OFile *somSelf, Environment *ev,
- FW_OFileSpecification* fileSpecification,
- FW_Boolean allowCreate)
- {
- FW_OFileData *somThis = FW_OFileGetData(somSelf);
-
- FW_SOM_TRY
- {
- somThis->fRep = FW_NEW(FW_CPrivFileRep, (ev, fileSpecification));
- privOpenFile(somSelf, ev, allowCreate);
- }
- FW_SOM_CATCH
- }
-
-
- //----------------------------------------------------------------------------------------
- // FW_OFile__InitWithPermissions
- // Open with specified permissions.
- //----------------------------------------------------------------------------------------
-
- SOM_Scope void SOMLINK FW_OFile__InitWithPermissions(FW_OFile *somSelf, Environment *ev,
- FW_OFileSpecification* fileSpecification,
- FW_SAccessPermission* permission,
- FW_Boolean allowCreate)
- {
- FW_OFileData *somThis = FW_OFileGetData(somSelf);
-
- FW_SOM_TRY
- {
- somThis->fRep = FW_NEW(FW_CPrivFileRep, (ev, fileSpecification, permission));
- privOpenFile(somSelf, ev, allowCreate);
- }
- FW_SOM_CATCH
- }
-
-
- //----------------------------------------------------------------------------------------
- // FW_OFile__Read
- // Read 'count' bytes from current position to 'destination' and
- // increment current position by 'count'.
- //----------------------------------------------------------------------------------------
-
- SOM_Scope void SOMLINK FW_OFile__Read(FW_OFile *somSelf, Environment *ev,
- void* destination,
- long count)
- {
- FW_SOM_TRY
- {
- privDoRead(somSelf, ev, destination, count);
- }
- FW_SOM_CATCH
- }
-
-
- //----------------------------------------------------------------------------------------
- // FW_OFile__Write
- // Write 'count' bytes from 'source' to current file position.
- //----------------------------------------------------------------------------------------
-
- SOM_Scope void SOMLINK FW_OFile__Write(FW_OFile *somSelf, Environment *ev,
- void* source,
- long count)
- {
- FW_SOM_TRY
- {
- privDoWrite(somSelf, ev, source, count);
- }
- FW_SOM_CATCH
- }
-
-
- //----------------------------------------------------------------------------------------
- // FW_OFile__GetLength
- // Return the logical size of the file.
- //----------------------------------------------------------------------------------------
-
- SOM_Scope long SOMLINK FW_OFile__GetLength(FW_OFile *somSelf, Environment *ev)
- {
- FW_OFileData *somThis = FW_OFileGetData(somSelf);
-
- FW_SOM_TRY
- {
- FW_CPrivFileRep& rep = *somThis->fRep;
- long length;
-
- #ifdef FW_BUILD_WIN
- // Since Windows does not support this feature directly, we have to reset the file
- // pointer to get the length and then restore the original position.
- long oldPosition = somSelf->GetPosition(ev);
- FW_FailOnError(privWinMoveFilePointer(somSelf, ev, 0, FW_kFromEnd, length));
- FW_FailOnError(privWinMoveFilePointer(somSelf, ev, oldPosition, FW_kFromStart, oldPosition));
- #endif
-
- #ifdef FW_BUILD_MAC
- long macEOF;
-
- FW_FailOnError(::GetEOF(rep.fFileHandle, &macEOF));
- length = macEOF;
- #endif
-
- return length;
- }
- FW_SOM_CATCH
- return 0;
- }
-
-
- //----------------------------------------------------------------------------------------
- // FW_OFile__SetLength
- // Return the logical size of the file.
- //----------------------------------------------------------------------------------------
-
- SOM_Scope void SOMLINK FW_OFile__SetLength(FW_OFile *somSelf, Environment *ev,
- long length)
- {
- FW_OFileData *somThis = FW_OFileGetData(somSelf);
-
- FW_SOM_TRY
- {
- FW_CPrivFileRep& rep = *somThis->fRep;
- FW_PlatformError theError = FW_xNoError;
- long currentLength = somSelf->GetLength(ev);
-
- #ifdef FW_BUILD_WIN16
- long oldPosition = somSelf->GetPosition(ev);
- FW_FailOnError(privWinMoveFilePointer(somSelf, ev, length, FW_kFromStart, length));
-
- // writing 0 bytes truncates the file at the current position
- char buf;
- short actualWritten;
- FW_PlatformError writeError = privWinPrimitiveWrite(rep.fFileHandle, 0, &buf, actualWritten);
-
- // move back to the old position, regardless of whether the write was successfull
- if (oldPosition > length)
- oldPosition = length;
- FW_PlatformError seekError = privWinMoveFilePointer(somSelf, ev, oldPosition, FW_kFromStart, oldPosition);
-
- if (writeError != FW_xNoError)
- FW_FailOnError(writeError);
- else
- FW_FailOnError(seekError);
- #endif
-
- #ifdef FW_BUILD_WIN32
- long oldPosition = somSelf->GetPosition(ev);
- somSelf->SetPosition(ev, FW_kFromStart, length);
- if (!::SetEndOfFile(rep.fFileHandle))
- theError = ::GetLastError();
- somSelf->SetPosition(ev, FW_kFromStart, oldPosition);
- #endif
-
- #ifdef FW_BUILD_MAC
- theError = ::SetEOF(rep.fFileHandle, length);
- #endif
-
- FW_FailOnError(theError);
- }
- FW_SOM_CATCH
- }
-
-
- //----------------------------------------------------------------------------------------
- // FW_OFile__GetPosition
- // Return current file position.
- //----------------------------------------------------------------------------------------
-
- SOM_Scope long SOMLINK FW_OFile__GetPosition(FW_OFile *somSelf, Environment *ev)
- {
- FW_OFileData *somThis = FW_OFileGetData(somSelf);
-
- FW_SOM_TRY
- {
- FW_CPrivFileRep& rep = *somThis->fRep;
- FW_PlatformError theError = FW_xNoError;
- long currentPosition;
-
- #ifdef FW_BUILD_WIN
- theError = privWinMoveFilePointer(somSelf, ev, 0, FW_kFromCurrent, currentPosition);
- #endif
-
- #ifdef FW_BUILD_MAC
- theError = ::GetFPos(rep.fFileHandle, ¤tPosition);
- #endif
-
- FW_FailOnError(theError);
- return currentPosition;
- }
- FW_SOM_CATCH
- return 0;
- }
-
-
- //----------------------------------------------------------------------------------------
- // FW_OFile__SetPosition
- // Set current file position using mode.
- //----------------------------------------------------------------------------------------
-
- SOM_Scope void SOMLINK FW_OFile__SetPosition(FW_OFile *somSelf, Environment *ev,
- long positioningMode,
- long markOffset)
- {
- FW_OFileData *somThis = FW_OFileGetData(somSelf);
-
- FW_SOM_TRY
- {
- FW_CPrivFileRep& rep = *somThis->fRep;
- FW_PlatformError theError = FW_xNoError;
-
- #ifdef FW_BUILD_WIN
- theError = privWinMoveFilePointer(somSelf, ev, markOffset, (FW_EFS_MoveMethods)positioningMode, markOffset);
- #endif
-
- #ifdef FW_BUILD_MAC
- long newLength = markOffset;
- theError = ::SetFPos(rep.fFileHandle, positioningMode, newLength);
- #endif
-
- #ifdef FW_BUILD_WIN16
- // Win16 returns this error to indicate an invalid positioningMode.
- if (theError == FW_kPermissionError)
- theError = FW_kParameterError;
- #endif
-
- FW_FailOnError(theError);
- }
- FW_SOM_CATCH
- }
-
-
- //----------------------------------------------------------------------------------------
- // FW_OFile__BytesToEndOfFile
- // Returns the number of bytes from the current position to the
- // end of the file.
- //----------------------------------------------------------------------------------------
-
- SOM_Scope long SOMLINK FW_OFile__BytesToEndOfFile(FW_OFile *somSelf, Environment *ev)
- {
- FW_SOM_TRY
- {
- return (somSelf->GetLength(ev) - somSelf->GetPosition(ev));
- }
- FW_SOM_CATCH
- return 0;
- }
-
-
- //----------------------------------------------------------------------------------------
- // FW_OFile__GetPermissions
- // Returns the permissions used to open this file.
- //----------------------------------------------------------------------------------------
-
- SOM_Scope void SOMLINK FW_OFile__GetPermissions(FW_OFile *somSelf, Environment *ev,
- FW_SAccessPermission* thePerms)
- {
- FW_UNUSED(ev);
- FW_OFileData *somThis = FW_OFileGetData(somSelf);
-
- *thePerms = somThis->fRep->fPermission;
- }
-
-
- //----------------------------------------------------------------------------------------
- // FW_OFile__GetFileSpecification
- // Returns a reference to the file. This routine is primarily used for
- // exception handling.
- //----------------------------------------------------------------------------------------
-
- SOM_Scope FW_OFileSpecification* SOMLINK FW_OFile__GetFileSpecification(FW_OFile *somSelf, Environment *ev)
- {
- FW_UNUSED(ev);
- FW_OFileData *somThis = FW_OFileGetData(somSelf);
-
- return somThis->fRep->fFileSpec;
- }
-
-
- //----------------------------------------------------------------------------------------
- // FW_OFile__GetFileHandle
- // Returns the native platform handle to the file.
- //----------------------------------------------------------------------------------------
-
- SOM_Scope FW_PlatformFileHandle* SOMLINK FW_OFile__GetFileHandle(FW_OFile *somSelf, Environment *ev)
- {
- FW_UNUSED(ev);
- FW_OFileData *somThis = FW_OFileGetData(somSelf);
-
- return &somThis->fRep->fFileHandle;
- }
-
-
- //----------------------------------------------------------------------------------------
- // FW_OFile__IsEqual
- // Equality operator.
- //----------------------------------------------------------------------------------------
-
- SOM_Scope FW_Boolean SOMLINK FW_OFile__IsEqual(FW_OFile *somSelf, Environment *ev,
- FW_OFile* theOtherFile)
- {
- FW_OFileData *somThis = FW_OFileGetData(somSelf);
-
- FW_SOM_TRY
- {
- FW_CPrivFileRep& rep = *somThis->fRep;
- return (rep.fFileHandle == *theOtherFile->GetFileHandle(ev))
- && (rep.fFileSpec->IsSameAs(ev, theOtherFile->GetFileSpecification(ev)));
- }
- FW_SOM_CATCH
- return FALSE;
- }
-
-
- //----------------------------------------------------------------------------------------
- // FW_OFile__somInit
- //----------------------------------------------------------------------------------------
-
- SOM_Scope void SOMLINK FW_OFile__somInit(FW_OFile *somSelf)
- {
- FW_OFileData *somThis = FW_OFileGetData(somSelf);
-
- // FW_OFile_parent_FW_ORefCount_somInit(somSelf);
-
- somThis->fRep = 0;
- }
-
-
- //----------------------------------------------------------------------------------------
- // FW_OFile__somUninit
- //----------------------------------------------------------------------------------------
-
- SOM_Scope void SOMLINK FW_OFile__somUninit(FW_OFile *somSelf)
- {
- FW_OFileData *somThis = FW_OFileGetData(somSelf);
-
- FW_SOM_UNINIT_TRY
- {
- FW_SOMEnvironment ev;
- privCloseFile(somSelf, ev);
-
- delete somThis->fRep;
-
- // FW_OFile_parent_FW_ORefCount_somUninit(somSelf);
- }
- FW_SOM_UNINIT_CATCH
- }
-
-
- //----------------------------------------------------------------------------------------
- // privOpenFile
- //
- // Opens the file using the permissions set with SetPermission. If no permissions were
- // set, it tries to open the file for exclusive access. If the file is already open,
- // nothing happens. If any other errors occur, they are thrown as exceptions.
- //----------------------------------------------------------------------------------------
- static void privOpenFile(FW_OFile *somSelf, Environment *ev, FW_Boolean allowCreate)
- {
- FW_OFileData *somThis = FW_OFileGetData(somSelf);
- FW_CPrivFileRep& rep = *somThis->fRep;
- FW_PlatformError theError = FW_xNoError;
- unsigned long accessMode = rep.fPermission.fAccess;
- unsigned long denyMode = rep.fPermission.fDeny;
-
- #ifdef FW_BUILD_WIN
- FW_CString fileName;
-
- rep.fFileSpec->GetFullPath(ev, fileName);
- #endif
-
- #ifdef FW_BUILD_WIN16
- OFSTRUCT Buffer;
- rep.fFileHandle = ::OpenFile((const FW_Char*)fileName, &Buffer, accessMode | denyMode);
- if (rep.fFileHandle == FW_kInvalidAccessHandle)
- theError = Buffer.nErrCode;
- #endif
-
- #ifdef FW_BUILD_WIN32
- // If we allowCreate, always open the file. Otherwise, open only if it
- // already exists.
- long openMode = (allowCreate ? OPEN_ALWAYS : OPEN_EXISTING);
-
- char szFileName[_MAX_PATH];
- fileName.ExportCString(szFileName);
-
- rep.fFileHandle = ::CreateFile(szFileName,
- accessMode,
- denyMode,
- NULL,
- openMode,
- FILE_ATTRIBUTE_NORMAL,
- (HANDLE)NULL);
-
- if (rep.fFileHandle == FW_kInvalidAccessHandle)
- theError = ::GetLastError();
- #endif
-
- #ifdef FW_BUILD_MAC
- // If we allowCreate, then try creating the file. If the file already
- // exists, we will FW_CATCH the attempt to re-create it and merrily roll
- // along. If the file does not exist, it will when we're done.
- if (allowCreate)
- {
- FW_TRY
- {
- FW_FileSystem_CreateFile(ev, rep.fFileSpec, FALSE);
- }
- FW_CATCH_BEGIN
- FW_CATCH(FW_XException, theException)
- {
- if (theException.GetPlatformError() != FW_xFileExists)
- FW_THROW_SAME();
- }
- FW_CATCH_END
-
- // At this point, the file exists (modulo another thread nuking it).
- }
-
- // Check to see if file sharing exists on this volume. If it does, open the file using
- // deny modes.
- FSSpec theMacSpec;
-
- rep.fFileSpec->MacGetFSSpec(ev, &theMacSpec);
-
- if (FW_FileSystem_MacIsVolumeShared(ev, theMacSpec.vRefNum))
- {
- HParamBlockRec paramBlock;
-
- paramBlock.fileParam.ioNamePtr = (StringPtr) & (theMacSpec.name);
- paramBlock.fileParam.ioVRefNum = theMacSpec.vRefNum;
- paramBlock.fileParam.ioDirID = theMacSpec.parID;
- paramBlock.accessParam.ioDenyModes = accessMode | denyMode;
-
- theError = ::PBHOpenDenySync(¶mBlock);
- rep.fFileHandle = paramBlock.fileParam.ioFRefNum;
- }
- else
- theError = ::FSpOpenDF(&(theMacSpec), accessMode, &rep.fFileHandle);
-
- #endif
-
- FW_FailOnError(theError);
- }
-
- //----------------------------------------------------------------------------------------
- // privCloseFile
- //----------------------------------------------------------------------------------------
- static void privCloseFile(FW_OFile *somSelf, Environment *ev)
- {
- FW_UNUSED(ev);
- FW_OFileData *somThis = FW_OFileGetData(somSelf);
- FW_CPrivFileRep& rep = *somThis->fRep;
- FW_PlatformError theError = FW_xNoError;
-
- #if 0
- //#ifdef FW_BUILD_WIN16
- FW_PlatformFileHandle handle = rep.fFileHandle;
-
- __asm {
- mov bx, [handle]
- mov ah, 03Eh
- }
-
- DOS3Call();
-
- __asm {
- jc _error
- xor ax, ax
- }
-
- _error:
-
- __asm {
- mov theError, ax
- }
- #endif
-
- #ifdef FW_BUILD_WIN32
- if(!::CloseHandle(rep.fFileHandle))
- theError = ::GetLastError();
- #endif
-
- #ifdef FW_BUILD_MAC
- theError = ::FSClose(rep.fFileHandle);
- #endif
-
- FW_FailOnError(theError);
-
- rep.fFileHandle = FW_kInvalidAccessHandle;
- }
-
-
- #ifdef FW_BUILD_WIN16
- //----------------------------------------------------------------------------------------
- // privWinGetIOBufferSize
- //----------------------------------------------------------------------------------------
- static short privWinGetIOBufferSize(long bytesDesired, const void* buffer)
- {
- short offset = (short)(long)buffer;
- long max = 0x10000L - offset;
- if(max > bytesDesired)
- max = bytesDesired;
- return max > 16384 ? 16384 : (short)max;
- }
-
-
- //----------------------------------------------------------------------------------------
- // privWinPrimitiveRead
- //----------------------------------------------------------------------------------------
- static FW_PlatformError privWinPrimitiveRead(FW_PlatformFileHandle handle,
- short bytesToRead,
- void* buffer,
- short& bytesActuallyRead)
- {
- FW_PlatformError theError;
-
- __asm {
- mov ah, 03Fh
- mov bx, [handle]
- mov cx, [bytesToRead]
- push ds
- lds dx, [buffer]
- }
-
- DOS3Call();
-
- __asm {
- pop ds
- jc _error
- les bx, [bytesActuallyRead]
- mov es:[bx], ax
- xor ax, ax
- }
-
- _error:
-
- __asm {
- mov theError, ax
- };
-
- return (theError);
- }
-
-
- //----------------------------------------------------------------------------------------
- // privWinPrimitiveWrite
- //----------------------------------------------------------------------------------------
- static FW_PlatformError privWinPrimitiveWrite(FW_PlatformFileHandle handle,
- short bytesToWrite,
- const void* buffer,
- short& bytesActuallyWritten)
- {
- FW_PlatformError theError;
-
- __asm {
- mov ah, 040h
- mov bx, [handle]
- mov cx, [bytesToWrite]
- push ds
- lds dx, [buffer]
- }
-
- DOS3Call();
-
- __asm {
- pop ds
- jc _error
- les bx, [bytesActuallyWritten]
- mov es:[bx], ax
- xor ax, ax
- }
-
- _error:
-
- _asm {
- mov theError, ax
- };
-
- return (theError);
- }
- #endif
-
- //----------------------------------------------------------------------------------------
- // privDoRead
- //----------------------------------------------------------------------------------------
- static void privDoRead(FW_OFile *somSelf, Environment *ev, void* destination, long count)
- {
- FW_UNUSED(ev);
-
- FW_ASSERT (count >= 0);
- if (count > 0)
- {
- FW_OFileData *somThis = FW_OFileGetData(somSelf);
- FW_CPrivFileRep& rep = *somThis->fRep;
- FW_PlatformError theError = FW_xNoError;
-
- #ifdef FW_BUILD_WIN16
- long toRead = count;
- while(toRead > 0)
- {
- short readNow = privWinGetIOBufferSize(toRead, destination);
- short actualRead;
- theError = privWinPrimitiveRead(rep.fFileHandle, readNow, destination, actualRead);
-
- if(theError != 0)
- break;
-
- toRead -= actualRead;
-
- if(actualRead < readNow)
- break;
-
- destination = ((char __huge*) destination) + toRead;
- }
-
- if (toRead != 0)
- theError = FW_kEndOfFileReached;
- #endif
-
- #ifdef FW_BUILD_WIN32
- DWORD actualRead;
- if(!::ReadFile(rep.fFileHandle, destination, count, &actualRead, NULL))
- theError = ::GetLastError();
- #endif
-
- #ifdef FW_BUILD_MAC
- theError = ::FSRead(rep.fFileHandle, &count, destination);
- #endif
-
- FW_FailOnError(theError);
- }
- }
-
-
- //----------------------------------------------------------------------------------------
- // privDoWrite
- //----------------------------------------------------------------------------------------
- static void privDoWrite(FW_OFile *somSelf, Environment *ev, const void* source, long count)
- {
- FW_UNUSED(ev);
- FW_ASSERT (count >= 0);
- if (count > 0)
- {
- FW_OFileData *somThis = FW_OFileGetData(somSelf);
- FW_CPrivFileRep& rep = *somThis->fRep;
- FW_PlatformError theError = FW_xNoError;
-
- #ifdef FW_BUILD_WIN16
- long toWrite = count;
- while(toWrite > 0)
- {
- short writeNow = privWinGetIOBufferSize(toWrite, source);
- short actualWritten;
- theError = privWinPrimitiveWrite(rep.fFileHandle, writeNow, source, actualWritten);
-
- if(theError != 0)
- break;
-
- toWrite -= actualWritten;
-
- if(actualWritten < writeNow)
- break;
-
- source = ((const char __huge*) source) + toWrite;
- }
-
- if (toWrite != 0)
- theError = FW_kDiskFull;
- #endif
-
- #ifdef FW_BUILD_WIN32
- DWORD actualWrite;
- if(!::WriteFile(rep.fFileHandle, source, count, &actualWrite, NULL))
- theError = ::GetLastError();
- #endif
-
- #ifdef FW_BUILD_MAC
- theError = ::FSWrite(rep.fFileHandle, &count, source);
- #endif
-
- FW_FailOnError(theError);
- }
- }
-
-
- #ifdef FW_BUILD_WIN
- //----------------------------------------------------------------------------------------
- // privWinMoveFilePointer
- //----------------------------------------------------------------------------------------
- static FW_PlatformError privWinMoveFilePointer(FW_OFile *somSelf,
- Environment *ev,
- long markOffset,
- FW_EFS_MoveMethods positioningMode,
- long& newPosition)
- {
- FW_OFileData *somThis = FW_OFileGetData(somSelf);
- FW_CPrivFileRep& rep = *somThis->fRep;
- FW_PlatformError theError = FW_xNoError;
-
- #ifdef FW_BUILD_WIN16
- FW_PlatformFileHandle handle = rep.fFileHandle;
-
- __asm {
- mov ax, [positioningMode]
- mov ah, 42h
- mov bx, [handle]
- mov dx, word ptr [markOffset]
- mov cx, word ptr [markOffset+2]
- }
-
- DOS3Call();
-
- __asm {
- jc _error
- les bx, [newPosition]
- mov word ptr es:[bx], ax
- mov word ptr es:[bx+2], dx
- xor ax, ax
- }
-
- _error:
-
- __asm {
- mov theError, ax
- }
- #endif
-
- #ifdef FW_BUILD_WIN32
- newPosition = ::SetFilePointer(rep.fFileHandle, markOffset, NULL, positioningMode);
- if (newPosition == FW_kInvalidSeek)
- theError = ::GetLastError();
- #endif
-
- return theError;
- }
- #endif
-
-
-