// UNIX Part
//------------------------------------------------------------------------
-
-#ifndef WNT
+#ifndef _WIN32
#include <Standard_ProgramError.hxx>
#include <OSD_OSDError.hxx>
// Create an empty file object
// ---------------------------------------------------------------------
-OSD_File::OSD_File():OSD_FileNode() {
+OSD_File::OSD_File():OSD_FileNode()
+{
ImperativeFlag = Standard_False;
myLock = OSD_NoLock;
myIO = 0;
myMode = OSD_ReadWrite;
- myFileChannel = -1;
myFILE = (Standard_Address) NULL;
+ myFileChannel = -1;
+ myFileHandle = 0;
}
// ---------------------------------------------------------------------
// Create and initialize a file object
// ---------------------------------------------------------------------
-OSD_File::OSD_File(const OSD_Path& Name):OSD_FileNode(Name){
-
+OSD_File::OSD_File(const OSD_Path& Name):OSD_FileNode(Name)
+{
ImperativeFlag = Standard_False;
myLock = OSD_NoLock;
myIO = 0;
myMode = OSD_ReadWrite;
- myFileChannel = -1;
myFILE = (Standard_Address) NULL;
+ myFileChannel = -1;
+ myFileHandle = 0;
}
+// protect against occasional use of myFileHande in Linux code
+#define myFileHandle myFileHandle_is_only_for_Windows
// ---------------------------------------------------------------------
// Build a file if it doesn't exist or create again if it already exists
internal_prot = Protect.Internal();
- char CMode[5];
+ const char* CMode = "r";
switch (Mode){
case OSD_ReadOnly:
internal_mode |= O_RDONLY;
- strcpy (CMode,"r");
+ CMode = "r";
break;
case OSD_WriteOnly:
internal_mode |= O_WRONLY;
- strcpy (CMode,"w");
+ CMode = "w";
break;
case OSD_ReadWrite:
internal_mode |= O_RDWR;
- strcpy (CMode,"rw");
+ CMode = "w+";
break;
}
myPath.SystemName( aBuffer );
- myFileChannel = open (aBuffer.ToCString(),(int) internal_mode,(int) internal_prot);
+ myFileChannel = open (aBuffer.ToCString(), internal_mode, internal_prot);
if (myFileChannel >= 0) {
- myFILE = fdopen (myFileChannel,(const char*) CMode);
+ myFILE = fdopen (myFileChannel, CMode);
}
else
/* Handle OPEN errors */
Standard_ProgramError::Raise("OSD_File::Append : file is already open");
internal_prot = Protect.Internal();
-
-
myMode = Mode;
- char CMode[5];
+ const char* CMode = "r";
switch (Mode){
case OSD_ReadOnly:
internal_mode |= O_RDONLY;
- strcpy (CMode,"r");
+ CMode = "r";
break;
case OSD_WriteOnly:
internal_mode |= O_WRONLY;
- strcpy (CMode,"a");
+ CMode = "a";
break;
case OSD_ReadWrite:
internal_mode |= O_RDWR;
- strcpy (CMode,"a");
+ CMode = "a+";
break;
}
if (!Exists()) internal_mode |= O_CREAT;
myPath.SystemName ( aBuffer );
- myFileChannel = open (aBuffer.ToCString(),(int) internal_mode,(int) internal_prot);
+ myFileChannel = open (aBuffer.ToCString(), internal_mode, internal_prot);
if (myFileChannel >= 0)
- myFILE = fdopen (myFileChannel,(const char*) CMode);
+ myFILE = fdopen (myFileChannel, CMode);
else
/* Handle OPEN errors */
Standard_ProgramError::Raise("OSD_File::Open : file is already open");
internal_prot = Protect.Internal();
-
-
myMode = Mode;
- char CMode[5];
+ const char* CMode = "r";
switch (Mode){
case OSD_ReadOnly:
internal_mode |= O_RDONLY;
- strcpy (CMode,"r");
+ CMode = "r";
break;
case OSD_WriteOnly:
internal_mode |= O_WRONLY;
- strcpy (CMode,"w");
+ CMode = "w";
break;
case OSD_ReadWrite:
internal_mode |= O_RDWR;
- strcpy (CMode,"rw");
+ CMode = "w+";
break;
}
myPath.SystemName ( aBuffer );
- myFileChannel = open (aBuffer.ToCString(),(int) internal_mode,(int) internal_prot);
+ myFileChannel = open (aBuffer.ToCString(), internal_mode, internal_prot);
if (myFileChannel >= 0)
- myFILE = fdopen (myFileChannel,(const char*) CMode);
+ myFILE = fdopen (myFileChannel, CMode);
else
/* Handle OPEN errors */
int dummy;
fic = tmpfile();
- dummy = open("dummy", O_RDWR | O_CREAT); // Open a summy file
+ dummy = open("dummy", O_RDWR | O_CREAT); // Open a dummy file
result.myFileChannel = dummy - 1; // This is file channel of "fic" +1
close(dummy); // Close dummy file
unlink("dummy"); // Removes dummy file
TCollection_AsciiString transfert(Nbyte,' ');
readbuf = (Standard_PCharacter)transfert.ToCString();
- status = read( (int)myFileChannel, readbuf, Nbyte);
+ status = read (myFileChannel, readbuf, Nbyte);
//
Buffer = transfert; // Copy transfert to Buffer
}
}
else {
- NByteRead = strlen(abuffer);
+ NByteRead = (Standard_Integer)strlen(abuffer);
Buffer.SetValue(1,abuffer); // Copy transfert to Buffer
Buffer.Trunc(NByteRead);
}
if (Buffer == NULL)
Standard_ProgramError::Raise("OSD_File::Read : Buffer is null");
- status = read( (int)myFileChannel, (char*) Buffer, Nbyte);
+ status = read (myFileChannel, (char*) Buffer, Nbyte);
if (status == -1) myError.SetValue (errno, Iam, "Read");
else{
if ( status < Nbyte ) myIO = EOF;
- Readbyte = (Standard_Integer) status;
+ Readbyte = status;
}
}
writebuf = Buffer.ToCString();
- status = write( (int)myFileChannel, writebuf, Nbyte);
+ status = write (myFileChannel, writebuf, Nbyte);
if ( status == -1) myError.SetValue (errno, Iam, "Write");
else
if (Nbyte <= 0)
Standard_ProgramError::Raise("OSD_File::Write : Nbyte is null");
- status = write( (int)myFileChannel, (const char *)Buffer, Nbyte);
+ status = write (myFileChannel, (const char *)Buffer, Nbyte);
if ( status == -1) myError.SetValue (errno, Iam, "Write");
else
void OSD_File::Seek(const Standard_Integer Offset,
const OSD_FromWhere Whence){
- int status,where=0;
+ int iwhere=0;
if (myFileChannel == -1)
Standard_ProgramError::Raise("OSD_File::Seek : file is not open");
switch (Whence){
case OSD_FromBeginning :
- where = SEEK_SET;
+ iwhere = SEEK_SET;
break;
case OSD_FromHere:
- where = SEEK_CUR;
+ iwhere = SEEK_CUR;
break;
case OSD_FromEnd:
- where = SEEK_END;
+ iwhere = SEEK_END;
break;
default :
myError.SetValue (EINVAL, Iam, "Seek");
}
- status = (int) lseek( (int)myFileChannel, Offset, where );
+ off_t status = lseek (myFileChannel, Offset, iwhere);
if (status == -1) myError.SetValue (errno, Iam, "Seek");
}
if (Failed()) Perror();
- status = close ( (int) myFileChannel );
+ // note: it probably should be single call to fclose()...
+ status = close (myFileChannel);
if (status == -1) myError.SetValue (errno, Iam, "Close");
myFileChannel = -1;
if ( myFILE != NULL ) {
status = fclose ( (FILE*) myFILE );
- myFILE = (Standard_Address) NULL;
+ myFILE = NULL;
}
myIO = 0;
}
return;
}
- if (fstat((int)myFileChannel, &buf) == -1) {
+ if (fstat (myFileChannel, &buf) == -1) {
myError.SetValue (errno, Iam, "SetLock");
return;
}
key.l_start = 0;
key.l_len = 0;
- status = fcntl( (int) myFileChannel ,F_SETLKW,(long) &key);
+ status = fcntl (myFileChannel, F_SETLKW, &key);
if (status == -1) myError.SetValue (errno, Iam, "SetLock");
else myLock = Lock;
if (Lock == OSD_ExclusiveLock){
- fstat( (int) myFileChannel ,&buf);
+ fstat (myFileChannel, &buf);
TCollection_AsciiString aBuffer;
myPath.SystemName ( aBuffer );
chmod( aBuffer.ToCString() ,buf.st_mode | S_ISGID);
default : myError.SetValue (EINVAL, Iam, "SetLock");
}
- status = flock((int)myFileChannel,lock);
+ status = flock (myFileChannel, lock);
if (status == -1) myError.SetValue (errno, Iam, "SetLock");
else myLock = Lock;
#endif // SysV
struct flock key;
if (ImperativeFlag){
- fstat((int)myFileChannel,&buf);
+ fstat (myFileChannel, &buf);
TCollection_AsciiString aBuffer;
myPath.SystemName ( aBuffer );
chmod(aBuffer.ToCString(),buf.st_mode & ~S_ISGID);
ImperativeFlag = Standard_False;
}
key.l_type = F_UNLCK;
- status = fcntl((int)myFileChannel,F_SETLK,(long) &key);
+ status = fcntl (myFileChannel, F_SETLK, &key);
if (status == -1) myError.SetValue (errno, Iam, "UnSetLock");
#else
- status = flock((int)myFileChannel,LOCK_UN);
+ status = flock (myFileChannel, LOCK_UN);
if (status == -1) myError.SetValue (errno, Iam, "UnSetLock");
#endif
#endif // POSIX
// Return size of a file
// --------------------------------------------------------------------------
-Standard_Integer OSD_File::Size(){
+Standard_Size OSD_File::Size(){
struct stat buffer;
int status;
status = stat( aBuffer.ToCString() ,&buffer );
if (status == -1) {
myError.SetValue (errno, Iam, "Size");
- return (-1);
+ return 0;
}
- return ( buffer.st_size );
+ return (Standard_Size)buffer.st_size;
}
return Standard_True;
}
-#else //WNT
+#else /* _WIN32 */
//------------------------------------------------------------------------
//------------------- Windows NT sources for OSD_File -------------------
#define ACE_HEADER_SIZE ( sizeof ( ACCESS_ALLOWED_ACE ) - sizeof ( DWORD ) )
#define RAISE( arg ) Standard_ProgramError :: Raise ( ( arg ) )
-#define TEST_RAISE( arg ) _test_raise ( myFileChannel, ( arg ) )
+#define TEST_RAISE( arg ) _test_raise ( myFileHandle, ( arg ) )
#define OPEN_NEW 0
#define OPEN_OLD 1
);
BOOL __fastcall _osd_print (const Standard_PCharacter, Standard_CString );
-static void __fastcall _test_raise ( Standard_Integer, Standard_CString );
+static void __fastcall _test_raise ( HANDLE, Standard_CString );
static DWORDLONG __fastcall _get_line ( Standard_PCharacter&, DWORD );
static int __fastcall _get_buffer ( HANDLE, Standard_PCharacter&, DWORD, BOOL, BOOL );
static DWORD __fastcall _get_access_mask ( OSD_SingleProtection );
typedef OSD_SingleProtection ( __fastcall *GET_PROT_FUNC ) ( DWORD );
-Standard_Integer __fastcall _get_file_type ( Standard_CString, Standard_Integer );
+Standard_Integer __fastcall _get_file_type ( Standard_CString, HANDLE );
// ---------------------------------------------------------------------
// Create an empty file object
// ---------------------------------------------------------------------
-OSD_File :: OSD_File () {
-
+OSD_File :: OSD_File ()
+{
ImperativeFlag = Standard_False;
myLock = OSD_NoLock;
myIO = 0;
-
+ myFileChannel = -1;
+ myFileHandle = INVALID_HANDLE_VALUE;
} // end constructor ( 1 )
// ---------------------------------------------------------------------
// Create and initialize a file object
// ---------------------------------------------------------------------
-OSD_File :: OSD_File ( const OSD_Path& Name ) : OSD_FileNode ( Name ) {
-
+OSD_File :: OSD_File ( const OSD_Path& Name ) : OSD_FileNode ( Name )
+{
ImperativeFlag = Standard_False;
myLock = OSD_NoLock;
myIO = 0;
myPath = Name;
-
+ myFileChannel = -1;
+ myFileHandle = INVALID_HANDLE_VALUE;
} // end constructor ( 2 )
+// protect against occasional use of myFileHande in Windows code
+#define myFileChannel myFileChannel_is_only_for_Linux
+
// ---------------------------------------------------------------------
// Build a file if it doesn't exist or create again if it already exists
// ---------------------------------------------------------------------
Standard_ProgramError::Raise("OSD_File::Read : it is a directory");
}
- if ( ( HANDLE )myFileChannel != INVALID_HANDLE_VALUE )
+ if (myFileHandle != INVALID_HANDLE_VALUE)
RAISE( TEXT( "OSD_File :: Build (): incorrect call - file already opened" ) );
RAISE( TEXT( "OSD_File :: Build (): incorrent call - no filename given" ) );
- myFileChannel = ( Standard_Integer )_open_file ( fName.ToCString (), Mode, OPEN_NEW );
+ myFileHandle = _open_file ( fName.ToCString (), Mode, OPEN_NEW );
- if ( ( HANDLE )myFileChannel == INVALID_HANDLE_VALUE )
+ if (myFileHandle == INVALID_HANDLE_VALUE)
_osd_wnt_set_error ( myError, OSD_WFile );
TCollection_AsciiString fName;
- if ( ( HANDLE )myFileChannel != INVALID_HANDLE_VALUE )
+ if (myFileHandle != INVALID_HANDLE_VALUE)
RAISE( TEXT( "OSD_File :: Open (): incorrect call - file already opened" ) );
RAISE( TEXT( "OSD_File :: Open (): incorrent call - no filename given" ) );
- myFileChannel = ( Standard_Integer )_open_file ( fName.ToCString (), Mode, OPEN_OLD );
+ myFileHandle = _open_file ( fName.ToCString (), Mode, OPEN_OLD );
- if ( ( HANDLE )myFileChannel == INVALID_HANDLE_VALUE ) {
+ if (myFileHandle == INVALID_HANDLE_VALUE) {
_osd_wnt_set_error ( myError, OSD_WFile );
}
else
{
- myIO |= _get_file_type ( fName.ToCString (), myFileChannel );
+ myIO |= _get_file_type ( fName.ToCString (), myFileHandle );
}
} // end OSD_File :: Open
BOOL fNew = FALSE;
TCollection_AsciiString fName;
- if ( ( HANDLE )myFileChannel != INVALID_HANDLE_VALUE )
+ if (myFileHandle != INVALID_HANDLE_VALUE)
RAISE( TEXT( "OSD_File :: Append (): incorrect call - file already opened" ) );
RAISE( TEXT( "OSD_File :: Append (): incorrent call - no filename given" ) );
- myFileChannel = ( Standard_Integer )_open_file ( fName.ToCString (), Mode, OPEN_APPEND, &fNew );
+ myFileHandle = _open_file ( fName.ToCString (), Mode, OPEN_APPEND, &fNew );
- if ( ( HANDLE )myFileChannel == INVALID_HANDLE_VALUE )
+ if (myFileHandle == INVALID_HANDLE_VALUE)
_osd_wnt_set_error ( myError, OSD_WFile );
if ( !fNew ) {
- myIO |= _get_file_type ( fName.ToCString (), myFileChannel );
+ myIO |= _get_file_type ( fName.ToCString (), myFileHandle );
Seek ( 0, OSD_FromEnd );
} else {
} // end OSD_File :: Read
-#define PRO13471
-
// ---------------------------------------------------------------------
// Read a line from a file
// ---------------------------------------------------------------------
-#ifdef PRO13471
-
// Modified so that we have <nl> at end of line if we have read <nl> or <cr>
// in the file.
// by LD 17 dec 98 for B4.4
if ( myIO & FLAG_FILE ) {
- if ( !ReadFile (
- ( HANDLE )myFileChannel, cBuffer, ( DWORD )NByte, &dwBytesRead, NULL
- )
- ) { // an error occured
+ if (!ReadFile (myFileHandle, cBuffer, (DWORD)NByte, &dwBytesRead, NULL)) { // an error occured
_osd_wnt_set_error ( myError, OSD_WFile );
Buffer.Clear ();
if ( status == 0xFFFFFFFFFFFFFFFF ) { // last character in the buffer is <CR> -
// peek next character to see if it is a <LF>
#endif
- if ( !ReadFile (
- ( HANDLE )myFileChannel, ppeekChar, 1, &dwDummy, NULL
- )
- ) {
+ if (!ReadFile (myFileHandle, ppeekChar, 1, &dwDummy, NULL)) {
_osd_wnt_set_error ( myError, OSD_WFile );
// adjust file position
- SetFilePointer ( ( HANDLE )myFileChannel, -1, NULL, FILE_CURRENT );
+ SetFilePointer (myFileHandle, -1, NULL, FILE_CURRENT);
} else
myIO |= FLAG_EOF;
} else {
if ( dwSeekPos != 0 )
- SetFilePointer ( ( HANDLE )myFileChannel, ( LONG )dwSeekPos, NULL, FILE_CURRENT );
+ SetFilePointer (myFileHandle, (LONG)dwSeekPos, NULL, FILE_CURRENT);
NbyteRead = ( Standard_Integer )( eos - cBuffer );
} else if ( myIO & FLAG_SOCKET || myIO & FLAG_PIPE || myIO & FLAG_NAMED_PIPE ) {
- dwBytesRead = ( DWORD )_get_buffer (
- ( HANDLE )myFileChannel, cBuffer, ( DWORD )NByte,
- TRUE, myIO & FLAG_SOCKET
- );
+ dwBytesRead = (DWORD)_get_buffer (myFileHandle, cBuffer,
+ (DWORD)NByte, TRUE, myIO & FLAG_SOCKET);
if ( ( int )dwBytesRead == -1 ) { // an error occured
NbyteRead = dwBytesRead; // (LD) always fits this case.
- dwDummy = _get_buffer (
- ( HANDLE )myFileChannel, ppeekChar, 1, TRUE, myIO & FLAG_SOCKET
- );
+ dwDummy = _get_buffer (myFileHandle, ppeekChar, 1, TRUE, myIO & FLAG_SOCKET);
if ( ( int )dwDummy == -1 ) { // an error occured
_osd_wnt_set_error ( myError, OSD_WFile );
Standard_PCharacter cDummyBuffer = new Standard_Character[ NByte + 3 ];
- _get_buffer ( // remove pending input
- ( HANDLE )myFileChannel, cDummyBuffer, dwBytesRead, FALSE, myIO & FLAG_SOCKET
- );
+ // remove pending input
+ _get_buffer (myFileHandle, cDummyBuffer, dwBytesRead, FALSE, myIO & FLAG_SOCKET);
delete [] cDummyBuffer ;
} // end else
} // end OSD_File :: ReadLine
-#else // PRO13471
-
-void OSD_File :: ReadLine (
- TCollection_AsciiString& Buffer,
- const Standard_Integer NByte, Standard_Integer& NbyteRead
- ) {
-
- DWORDLONG status;
- DWORD dwBytesRead;
- DWORD dwDummy;
- Standard_Character peekChar;
- Standard_CString cBuffer;
- Standard_CString eos;
- DWORD dwSeekPos;
-
- if ( OSD_File::KindOfFile ( ) == OSD_DIRECTORY ) {
- Standard_ProgramError::Raise("OSD_File::Read : it is a directory");
- }
-
-
- TEST_RAISE( TEXT( "ReadLine" ) );
-
- if ( myIO & FLAG_PIPE && !( myIO & FLAG_READ_PIPE ) )
-
- RAISE( TEXT( "OSD_File :: ReadLine (): attempt to read from write only pipe" ) );
-
- // +----> leave space for end-of-string
- // | plus <CR><LF> sequence
- // |
- cBuffer = new Standard_Character[ NByte + 3 ];
-
- if ( myIO & FLAG_FILE ) {
-
- if ( !ReadFile (
- ( HANDLE )myFileChannel, cBuffer, ( DWORD )NByte, &dwBytesRead, NULL
- )
- ) { // an error occured
-
- _osd_wnt_set_error ( myError, OSD_WFile );
- Buffer.Clear ();
- NbyteRead = 0;
-
- } else if ( dwBytesRead == 0 ) { // end-of-file reached
-
- Buffer.Clear ();
- NbyteRead = 0;
- myIO |= FLAG_EOF;
-
- } else {
-
- status = _get_line ( cBuffer, dwBytesRead );
-
- dwSeekPos = LODWORD( status );
- eos = ( Standard_CString )HIDWORD( status );
-#ifdef VAC
- if ( (__int64) status == (__int64) -1 ) { // last character in the buffer is <CR> -
-#else
- if ( status == 0xFFFFFFFFFFFFFFFF ) { // last character in the buffer is <CR> -
- // peek next character to see if it is a <LF>
-#endif
- if ( !ReadFile (
- ( HANDLE )myFileChannel, &peekChar, 1, &dwDummy, NULL
- )
- ) {
-
- _osd_wnt_set_error ( myError, OSD_WFile );
- NbyteRead = dwBytesRead;
-
- } else if ( dwDummy != 0 ) { // end-of-file reached ?
-
- if ( peekChar == '\n' ) // we got a <CR><LF> sequence
-
- cBuffer[ --dwBytesRead ] = 0;
-
- else // adjust file position
-
- SetFilePointer ( ( HANDLE )myFileChannel, -1, NULL, FILE_CURRENT );
-
- } else
-
- myIO |= FLAG_EOF;
-
- NbyteRead = dwBytesRead;
-
- } else if ( dwSeekPos != 0 ) {
-
- SetFilePointer ( ( HANDLE )myFileChannel, ( LONG )dwSeekPos, NULL, FILE_CURRENT );
- NbyteRead = ( Standard_Integer )( eos - cBuffer );
-
- } else
-
- NbyteRead = eos - cBuffer;
-
- } // end else
-
- } else if ( myIO & FLAG_SOCKET || myIO & FLAG_PIPE || myIO & FLAG_NAMED_PIPE ) {
-
- dwBytesRead = ( DWORD )_get_buffer (
- ( HANDLE )myFileChannel, cBuffer, ( DWORD )NByte,
- TRUE, myIO & FLAG_SOCKET
- );
-
- if ( ( int )dwBytesRead == -1 ) // an error occured
-
- _osd_wnt_set_error ( myError, OSD_WFile );
-
- else if ( dwBytesRead == 0 ) { // connection closed - set end-of-file flag
-
- Buffer.Clear ();
- NbyteRead = 0;
- myIO |= FLAG_EOF;
-
- } else {
-
- status = _get_line ( cBuffer, dwBytesRead );
-
- dwSeekPos = LODWORD( status );
- eos = ( Standard_CString )HIDWORD( status );
-
-#ifdef VAC
- if ( (__int64) status == (__int64) -1 ) { // last character in the buffer is <CR> -
-#else
- if ( status == 0xFFFFFFFFFFFFFFFF ) { // last character in the buffer is <CR> -
- // peek next character to see if it is a <LF>
-#endif
- dwDummy = _get_buffer (
- ( HANDLE )myFileChannel, &peekChar, 1, TRUE, myIO & FLAG_SOCKET
- );
- eos = cBuffer + dwBytesRead;
-
- if ( ( int )dwDummy == -1 ) { // an error occured
-
- _osd_wnt_set_error ( myError, OSD_WFile );
- NbyteRead = dwBytesRead;
-
- } else if ( dwDummy != 0 ) { // connection closed ?
-
- if ( peekChar == '\n' ) // we got a <CR><LF> sequence
-
- cBuffer[ dwBytesRead - 1 ] = 0, eos = cBuffer + ( dwBytesRead++ - 1 );
-
- } else
-
- myIO |= FLAG_EOF;
-
- NbyteRead = dwBytesRead;
-
- } else if ( dwSeekPos != 0 ) {
-
- dwBytesRead = dwBytesRead + dwSeekPos;
- NbyteRead = ( Standard_Integer )( eos - cBuffer );
-
- } else
-
- NbyteRead = ( Standard_Integer )( eos - cBuffer );
-
- _get_buffer ( // remove pending input
- ( HANDLE )myFileChannel, cBuffer, dwBytesRead, FALSE, myIO & FLAG_SOCKET
- );
- *eos = 0;
-
- } // end else
-
- } else
-
- RAISE( TEXT( "OSD_File :: ReadLine (): incorrect call - file is a directory" ) );
-
- if ( !Failed () && !IsAtEnd () )
-
- Buffer = cBuffer;
-
- delete [] cBuffer;
-
-} // end OSD_File :: ReadLine
-
-#endif // PRO13471
-
// --------------------------------------------------------------------------
// Read content of a file
// --------------------------------------------------------------------------
RAISE( TEXT( "OSD_File :: Read (): attempt to read from write only pipe" ) );
- if ( !ReadFile (
- ( HANDLE )myFileChannel, Buffer, ( DWORD )Nbyte, &dwBytesRead, NULL
- )
- ) {
+ if (!ReadFile (myFileHandle, Buffer, (DWORD)Nbyte, &dwBytesRead, NULL)) {
_osd_wnt_set_error ( myError, OSD_WFile );
dwBytesRead = 0;
RAISE( TEXT( "OSD_File :: Write (): attempt to write to read only pipe" ) );
- if ( !WriteFile (
- ( HANDLE )myFileChannel, Buffer, ( DWORD )Nbyte, &dwBytesWritten, NULL
- ) || dwBytesWritten != ( DWORD )Nbyte
- )
+ if (!WriteFile (myFileHandle, Buffer, (DWORD)Nbyte, &dwBytesWritten, NULL) ||
+ dwBytesWritten != (DWORD)Nbyte)
_osd_wnt_set_error ( myError, OSD_WFile );
} // end switch
- if ( SetFilePointer (
- ( HANDLE )myFileChannel, ( LONG )Offset, NULL, dwMoveMethod
- ) == 0xFFFFFFFF
- )
+ if (SetFilePointer (myFileHandle, (LONG)Offset, NULL, dwMoveMethod) == 0xFFFFFFFF)
_osd_wnt_set_error ( myError, OSD_WFile );
TEST_RAISE( TEXT( "Close" ) );
- CloseHandle ( ( HANDLE )myFileChannel );
+ CloseHandle (myFileHandle);
- myFileChannel = ( Standard_Integer )INVALID_HANDLE_VALUE;
+ myFileHandle = INVALID_HANDLE_VALUE;
myIO = 0;
} // end OSD_File :: Close
OSD_KindFile retVal;
Standard_Integer flags;
- if ( ( HANDLE )myFileChannel == INVALID_HANDLE_VALUE ) {
+ if (myFileHandle == INVALID_HANDLE_VALUE) {
TCollection_AsciiString fName;
RAISE( TEXT( "OSD_File :: KindOfFile (): incorrent call - no filename given" ) );
- flags = _get_file_type (
- fName.ToCString (), ( Standard_Integer )INVALID_HANDLE_VALUE
- );
+ flags = _get_file_type (fName.ToCString(), INVALID_HANDLE_VALUE);
} else
dwFlags = 0;
- if ( !LockFileEx (
- ( HANDLE )myFileChannel, dwFlags, 0, Size (), 0, &ovlp
- )
- ) {
+ LARGE_INTEGER aSize;
+ aSize.QuadPart = Size();
+ if (!LockFileEx (myFileHandle, dwFlags, 0, aSize.LowPart, aSize.HighPart, &ovlp)) {
_osd_wnt_set_error ( myError, OSD_WFile );
__leave;
if ( ImperativeFlag ) {
- if ( !UnlockFile (
- ( HANDLE )myFileChannel, 0, 0, Size (), 0
- )
- )
+ LARGE_INTEGER aSize;
+ aSize.QuadPart = Size();
+ if (!UnlockFile (myFileHandle, 0, 0, aSize.LowPart, aSize.HighPart))
_osd_wnt_set_error ( myError, OSD_WFile );
// Return size of a file
// --------------------------------------------------------------------------
-Standard_Integer OSD_File :: Size () {
+Standard_Size OSD_File :: Size () {
Standard_Integer retVal;
TEST_RAISE( TEXT( "Size" ) );
- retVal = ( Standard_Integer )GetFileSize (
- ( HANDLE )myFileChannel, NULL
- );
+ LARGE_INTEGER aSize;
+ aSize.QuadPart = 0;
+ retVal = GetFileSizeEx (myFileHandle, &aSize);
- if ( retVal == ( Standard_Integer )0xFFFFFFFF )
+ if ( retVal == 0 )
_osd_wnt_set_error ( myError, OSD_WFile );
- return retVal;
+ return (Standard_Size)aSize.QuadPart;
} // end OSD_File :: Size
void OSD_File :: Print ( const OSD_Printer& WhichPrinter ) {
- if ( ( HANDLE )myFileChannel != INVALID_HANDLE_VALUE )
+ if (myFileHandle != INVALID_HANDLE_VALUE)
RAISE( TEXT( "OSD_File :: Print (): incorrect call - file opened" ) );
Standard_Boolean OSD_File :: IsOpen () const {
- return ( HANDLE )myFileChannel != INVALID_HANDLE_VALUE;
+ return myFileHandle != INVALID_HANDLE_VALUE;
} // end OSD_File :: IsOpen
#undef __leave
#endif
-static void __fastcall _test_raise ( Standard_Integer hFile, Standard_CString str ) {
+static void __fastcall _test_raise ( HANDLE hFile, Standard_CString str ) {
Standard_Character buff[ 64 ];
- if ( ( HANDLE )hFile == INVALID_HANDLE_VALUE ) {
+ if (hFile == INVALID_HANDLE_VALUE) {
_tcscpy ( buff, TEXT( "OSD_File :: " ) );
_tcscat ( buff, str );
} // end _test_raise
-#ifdef PRO13471
-
// Modified so that we have <nl> at end of line if we have read <nl> or <cr>
// by LD 17 dec 98 for B4.4
} // end _get_line
-#else // PRO13471
-
-static DWORDLONG __fastcall _get_line ( Standard_CString buffer, DWORD dwBuffSize ) {
-
- DWORDLONG retVal;
- Standard_CString ptr;
-
- buffer[ dwBuffSize ] = 0;
- ptr = buffer;
-
- while ( *ptr != 0 ) {
-
- if ( *ptr == TEXT( '\n' ) ) {
-
- retVal = buffer - ptr;
-#ifdef VAC
- buffer[ (__int64) -( LONGLONG )retVal ] = 0;
-#else
- buffer[ -( LONGLONG )retVal ] = 0;
-#endif
- retVal = ptr + 1 - buffer - dwBuffSize;
-#ifdef VAC
- retVal = (DWORDLONG) ( (unsigned __int64) retVal | (((unsigned __int64) ptr) << 32) );
-#else
- retVal |= ( ( ( DWORDLONG )( DWORD )ptr ) << 32 );
-#endif
- return retVal;
-
- } else if ( *ptr == TEXT( '\r' ) && ptr[ 1 ] == TEXT( '\n' ) ) {
-
- retVal = buffer - ptr;
-#ifdef VAC
- buffer[ (__int64) -( LONGLONG )retVal ] = 0;
-#else
- buffer[ -( LONGLONG )retVal ] = 0;
-#endif
- retVal = ptr + 2 - buffer - dwBuffSize;
-#ifdef VAC
- retVal = (DWORDLONG) ( (unsigned __int64) retVal | (((unsigned __int64) ptr) << 32) );
-#else
- retVal |= ( ( ( DWORDLONG )( DWORD )ptr ) << 32 );
-#endif
- return retVal;
-
- } else if ( *ptr == TEXT( '\r' ) && ptr[ 1 ] == 0 )
-
-#ifdef VAC
- return (DWORDLONG) (__int64) (-1);
-#else
- return 0xFFFFFFFFFFFFFFFF;
-#endif
-
- ++ptr;
-
- } // end while
-
-#ifdef VAC
- retVal = (DWORDLONG) ( ( (unsigned __int64) ((DWORD) buffer + dwBuffSize) ) << 32 );
- retVal = (DWORDLONG) ( (unsigned __int64) retVal & (((unsigned __int64) 0xFFFFFFFF) << 32) );
-#else
- retVal = ( ( ( DWORDLONG )( ( DWORD )buffer + dwBuffSize ) ) << 32 );
- retVal &= 0xFFFFFFFF00000000;
-#endif
-
- return retVal;
-
-} // end _get_line
-
-#endif // PRO13471
-
static int __fastcall _get_buffer (
HANDLE hChannel,
Standard_PCharacter& buffer,
} // end _open_file
Standard_Integer __fastcall _get_file_type (
- Standard_CString fName, Standard_Integer fileHandle
+ Standard_CString fName, HANDLE fileHandle
) {
Standard_Integer retVal = 0;
DWORD dwType;
int fileType;
- fileType = fileHandle == ( Standard_Integer )INVALID_HANDLE_VALUE ?
- FILE_TYPE_DISK :
- GetFileType ( ( HANDLE )fileHandle );
+ fileType = (fileHandle == INVALID_HANDLE_VALUE ?
+ FILE_TYPE_DISK : GetFileType (fileHandle));
switch ( fileType ) {
// if (_access(FileName.ToCString(),0))
}
-#endif // WNT
+#endif /* _WIN32 */
// ---------------------------------------------------------------------