1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-10 18:51:21 +03:00

0024259: Clean up OSD_File implementation

Field myFileChannel removed from OSD_FileNode and introduced to OSD_File as Linux-only along with Windows-only myFileHandle.
Implementation of OSD_File cleaned from redundant type casts; some missing type cases added.
File mode passed to fdopen() corrected in read-write case ("rw" replaced by "w+").
Method OSD_File::Size() now returns Standard_Size to be able to return correct value for large files (on 64-bit platforms only).
This commit is contained in:
abv 2013-10-15 06:58:03 +04:00 committed by bugmaster
parent 8fa64b522f
commit 6ff736d802
5 changed files with 144 additions and 437 deletions

View File

@ -186,7 +186,7 @@ class File from OSD inherits FileNode
---Level: Public ---Level: Public
raises ProgramError is static; raises ProgramError is static;
Size (me: out) returns Integer Size (me: out) returns Size
---Purpose: Returns actual number of bytes of <me>. ---Purpose: Returns actual number of bytes of <me>.
---Level: Public ---Level: Public
raises ProgramError is static; raises ProgramError is static;
@ -232,9 +232,8 @@ class File from OSD inherits FileNode
myMode : OpenMode; myMode : OpenMode;
myIO : Integer is protected; -- Stores peculiar I/O informations myIO : Integer is protected; -- Stores peculiar I/O informations
myFILE : Address is protected; myFILE : Address is protected;
myBuffer : CString ; myFileChannel : Integer is protected; -- file descriptor, Unix/Linux only
myCurrPtr : CString ; myFileHandle : Address is protected; -- file handle, Windows only
myEndPtr : CString ;
end File from OSD; end File from OSD;

View File

@ -24,8 +24,7 @@
// UNIX Part // UNIX Part
//------------------------------------------------------------------------ //------------------------------------------------------------------------
#ifndef _WIN32
#ifndef WNT
#include <Standard_ProgramError.hxx> #include <Standard_ProgramError.hxx>
#include <OSD_OSDError.hxx> #include <OSD_OSDError.hxx>
@ -67,29 +66,34 @@ const OSD_WhoAmI Iam = OSD_WFile;
// Create an empty file object // Create an empty file object
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
OSD_File::OSD_File():OSD_FileNode() { OSD_File::OSD_File():OSD_FileNode()
{
ImperativeFlag = Standard_False; ImperativeFlag = Standard_False;
myLock = OSD_NoLock; myLock = OSD_NoLock;
myIO = 0; myIO = 0;
myMode = OSD_ReadWrite; myMode = OSD_ReadWrite;
myFileChannel = -1;
myFILE = (Standard_Address) NULL; myFILE = (Standard_Address) NULL;
myFileChannel = -1;
myFileHandle = 0;
} }
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
// Create and initialize a file object // 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; ImperativeFlag = Standard_False;
myLock = OSD_NoLock; myLock = OSD_NoLock;
myIO = 0; myIO = 0;
myMode = OSD_ReadWrite; myMode = OSD_ReadWrite;
myFileChannel = -1;
myFILE = (Standard_Address) NULL; 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 // Build a file if it doesn't exist or create again if it already exists
@ -113,27 +117,27 @@ void OSD_File::Build(const OSD_OpenMode Mode,
internal_prot = Protect.Internal(); internal_prot = Protect.Internal();
char CMode[5]; const char* CMode = "r";
switch (Mode){ switch (Mode){
case OSD_ReadOnly: case OSD_ReadOnly:
internal_mode |= O_RDONLY; internal_mode |= O_RDONLY;
strcpy (CMode,"r"); CMode = "r";
break; break;
case OSD_WriteOnly: case OSD_WriteOnly:
internal_mode |= O_WRONLY; internal_mode |= O_WRONLY;
strcpy (CMode,"w"); CMode = "w";
break; break;
case OSD_ReadWrite: case OSD_ReadWrite:
internal_mode |= O_RDWR; internal_mode |= O_RDWR;
strcpy (CMode,"rw"); CMode = "w+";
break; break;
} }
myPath.SystemName( aBuffer ); myPath.SystemName( aBuffer );
myFileChannel = open (aBuffer.ToCString(),(int) internal_mode,(int) internal_prot); myFileChannel = open (aBuffer.ToCString(), internal_mode, internal_prot);
if (myFileChannel >= 0) { if (myFileChannel >= 0) {
myFILE = fdopen (myFileChannel,(const char*) CMode); myFILE = fdopen (myFileChannel, CMode);
} }
else else
/* Handle OPEN errors */ /* Handle OPEN errors */
@ -166,23 +170,21 @@ void OSD_File::Append(const OSD_OpenMode Mode,
Standard_ProgramError::Raise("OSD_File::Append : file is already open"); Standard_ProgramError::Raise("OSD_File::Append : file is already open");
internal_prot = Protect.Internal(); internal_prot = Protect.Internal();
myMode = Mode; myMode = Mode;
char CMode[5]; const char* CMode = "r";
switch (Mode){ switch (Mode){
case OSD_ReadOnly: case OSD_ReadOnly:
internal_mode |= O_RDONLY; internal_mode |= O_RDONLY;
strcpy (CMode,"r"); CMode = "r";
break; break;
case OSD_WriteOnly: case OSD_WriteOnly:
internal_mode |= O_WRONLY; internal_mode |= O_WRONLY;
strcpy (CMode,"a"); CMode = "a";
break; break;
case OSD_ReadWrite: case OSD_ReadWrite:
internal_mode |= O_RDWR; internal_mode |= O_RDWR;
strcpy (CMode,"a"); CMode = "a+";
break; break;
} }
@ -191,9 +193,9 @@ void OSD_File::Append(const OSD_OpenMode Mode,
if (!Exists()) internal_mode |= O_CREAT; if (!Exists()) internal_mode |= O_CREAT;
myPath.SystemName ( aBuffer ); myPath.SystemName ( aBuffer );
myFileChannel = open (aBuffer.ToCString(),(int) internal_mode,(int) internal_prot); myFileChannel = open (aBuffer.ToCString(), internal_mode, internal_prot);
if (myFileChannel >= 0) if (myFileChannel >= 0)
myFILE = fdopen (myFileChannel,(const char*) CMode); myFILE = fdopen (myFileChannel, CMode);
else else
/* Handle OPEN errors */ /* Handle OPEN errors */
@ -222,30 +224,28 @@ void OSD_File::Open(const OSD_OpenMode Mode,
Standard_ProgramError::Raise("OSD_File::Open : file is already open"); Standard_ProgramError::Raise("OSD_File::Open : file is already open");
internal_prot = Protect.Internal(); internal_prot = Protect.Internal();
myMode = Mode; myMode = Mode;
char CMode[5]; const char* CMode = "r";
switch (Mode){ switch (Mode){
case OSD_ReadOnly: case OSD_ReadOnly:
internal_mode |= O_RDONLY; internal_mode |= O_RDONLY;
strcpy (CMode,"r"); CMode = "r";
break; break;
case OSD_WriteOnly: case OSD_WriteOnly:
internal_mode |= O_WRONLY; internal_mode |= O_WRONLY;
strcpy (CMode,"w"); CMode = "w";
break; break;
case OSD_ReadWrite: case OSD_ReadWrite:
internal_mode |= O_RDWR; internal_mode |= O_RDWR;
strcpy (CMode,"rw"); CMode = "w+";
break; break;
} }
myPath.SystemName ( aBuffer ); myPath.SystemName ( aBuffer );
myFileChannel = open (aBuffer.ToCString(),(int) internal_mode,(int) internal_prot); myFileChannel = open (aBuffer.ToCString(), internal_mode, internal_prot);
if (myFileChannel >= 0) if (myFileChannel >= 0)
myFILE = fdopen (myFileChannel,(const char*) CMode); myFILE = fdopen (myFileChannel, CMode);
else else
/* Handle OPEN errors */ /* Handle OPEN errors */
@ -264,7 +264,7 @@ OSD_File OSD_File::BuildTemporary(){
int dummy; int dummy;
fic = tmpfile(); 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 result.myFileChannel = dummy - 1; // This is file channel of "fic" +1
close(dummy); // Close dummy file close(dummy); // Close dummy file
unlink("dummy"); // Removes dummy file unlink("dummy"); // Removes dummy file
@ -319,7 +319,7 @@ void OSD_File::Read(TCollection_AsciiString& Buffer,
TCollection_AsciiString transfert(Nbyte,' '); TCollection_AsciiString transfert(Nbyte,' ');
readbuf = (Standard_PCharacter)transfert.ToCString(); readbuf = (Standard_PCharacter)transfert.ToCString();
status = read( (int)myFileChannel, readbuf, Nbyte); status = read (myFileChannel, readbuf, Nbyte);
// //
Buffer = transfert; // Copy transfert to Buffer Buffer = transfert; // Copy transfert to Buffer
@ -372,7 +372,7 @@ void OSD_File::ReadLine(TCollection_AsciiString& Buffer,
} }
} }
else { else {
NByteRead = strlen(abuffer); NByteRead = (Standard_Integer)strlen(abuffer);
Buffer.SetValue(1,abuffer); // Copy transfert to Buffer Buffer.SetValue(1,abuffer); // Copy transfert to Buffer
Buffer.Trunc(NByteRead); Buffer.Trunc(NByteRead);
} }
@ -427,12 +427,12 @@ void OSD_File::Read( Standard_Address& Buffer,
if (Buffer == NULL) if (Buffer == NULL)
Standard_ProgramError::Raise("OSD_File::Read : Buffer is 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"); if (status == -1) myError.SetValue (errno, Iam, "Read");
else{ else{
if ( status < Nbyte ) myIO = EOF; if ( status < Nbyte ) myIO = EOF;
Readbyte = (Standard_Integer) status; Readbyte = status;
} }
} }
@ -461,7 +461,7 @@ void OSD_File::Write(const TCollection_AsciiString &Buffer,
writebuf = Buffer.ToCString(); writebuf = Buffer.ToCString();
status = write( (int)myFileChannel, writebuf, Nbyte); status = write (myFileChannel, writebuf, Nbyte);
if ( status == -1) myError.SetValue (errno, Iam, "Write"); if ( status == -1) myError.SetValue (errno, Iam, "Write");
else else
@ -486,7 +486,7 @@ void OSD_File::Write(const Standard_Address Buffer,
if (Nbyte <= 0) if (Nbyte <= 0)
Standard_ProgramError::Raise("OSD_File::Write : Nbyte is null"); 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"); if ( status == -1) myError.SetValue (errno, Iam, "Write");
else else
@ -501,7 +501,7 @@ void OSD_File::Write(const Standard_Address Buffer,
void OSD_File::Seek(const Standard_Integer Offset, void OSD_File::Seek(const Standard_Integer Offset,
const OSD_FromWhere Whence){ const OSD_FromWhere Whence){
int status,where=0; int iwhere=0;
if (myFileChannel == -1) if (myFileChannel == -1)
Standard_ProgramError::Raise("OSD_File::Seek : file is not open"); Standard_ProgramError::Raise("OSD_File::Seek : file is not open");
@ -510,19 +510,19 @@ void OSD_File::Seek(const Standard_Integer Offset,
switch (Whence){ switch (Whence){
case OSD_FromBeginning : case OSD_FromBeginning :
where = SEEK_SET; iwhere = SEEK_SET;
break; break;
case OSD_FromHere: case OSD_FromHere:
where = SEEK_CUR; iwhere = SEEK_CUR;
break; break;
case OSD_FromEnd: case OSD_FromEnd:
where = SEEK_END; iwhere = SEEK_END;
break; break;
default : default :
myError.SetValue (EINVAL, Iam, "Seek"); 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 (status == -1) myError.SetValue (errno, Iam, "Seek");
} }
@ -541,13 +541,14 @@ void OSD_File::Close(){
if (Failed()) Perror(); 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"); if (status == -1) myError.SetValue (errno, Iam, "Close");
myFileChannel = -1; myFileChannel = -1;
if ( myFILE != NULL ) { if ( myFILE != NULL ) {
status = fclose ( (FILE*) myFILE ); status = fclose ( (FILE*) myFILE );
myFILE = (Standard_Address) NULL; myFILE = NULL;
} }
myIO = 0; myIO = 0;
} }
@ -602,7 +603,7 @@ int status;
return; return;
} }
if (fstat((int)myFileChannel, &buf) == -1) { if (fstat (myFileChannel, &buf) == -1) {
myError.SetValue (errno, Iam, "SetLock"); myError.SetValue (errno, Iam, "SetLock");
return; return;
} }
@ -630,12 +631,12 @@ int status;
key.l_start = 0; key.l_start = 0;
key.l_len = 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"); if (status == -1) myError.SetValue (errno, Iam, "SetLock");
else myLock = Lock; else myLock = Lock;
if (Lock == OSD_ExclusiveLock){ if (Lock == OSD_ExclusiveLock){
fstat( (int) myFileChannel ,&buf); fstat (myFileChannel, &buf);
TCollection_AsciiString aBuffer; TCollection_AsciiString aBuffer;
myPath.SystemName ( aBuffer ); myPath.SystemName ( aBuffer );
chmod( aBuffer.ToCString() ,buf.st_mode | S_ISGID); chmod( aBuffer.ToCString() ,buf.st_mode | S_ISGID);
@ -654,7 +655,7 @@ int status;
default : myError.SetValue (EINVAL, Iam, "SetLock"); default : myError.SetValue (EINVAL, Iam, "SetLock");
} }
status = flock((int)myFileChannel,lock); status = flock (myFileChannel, lock);
if (status == -1) myError.SetValue (errno, Iam, "SetLock"); if (status == -1) myError.SetValue (errno, Iam, "SetLock");
else myLock = Lock; else myLock = Lock;
#endif // SysV #endif // SysV
@ -689,18 +690,18 @@ int status;
struct flock key; struct flock key;
if (ImperativeFlag){ if (ImperativeFlag){
fstat((int)myFileChannel,&buf); fstat (myFileChannel, &buf);
TCollection_AsciiString aBuffer; TCollection_AsciiString aBuffer;
myPath.SystemName ( aBuffer ); myPath.SystemName ( aBuffer );
chmod(aBuffer.ToCString(),buf.st_mode & ~S_ISGID); chmod(aBuffer.ToCString(),buf.st_mode & ~S_ISGID);
ImperativeFlag = Standard_False; ImperativeFlag = Standard_False;
} }
key.l_type = F_UNLCK; 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"); if (status == -1) myError.SetValue (errno, Iam, "UnSetLock");
#else #else
status = flock((int)myFileChannel,LOCK_UN); status = flock (myFileChannel, LOCK_UN);
if (status == -1) myError.SetValue (errno, Iam, "UnSetLock"); if (status == -1) myError.SetValue (errno, Iam, "UnSetLock");
#endif #endif
#endif // POSIX #endif // POSIX
@ -727,7 +728,7 @@ OSD_LockType OSD_File::GetLock(){
// Return size of a file // Return size of a file
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
Standard_Integer OSD_File::Size(){ Standard_Size OSD_File::Size(){
struct stat buffer; struct stat buffer;
int status; int status;
@ -739,10 +740,10 @@ Standard_Integer OSD_File::Size(){
status = stat( aBuffer.ToCString() ,&buffer ); status = stat( aBuffer.ToCString() ,&buffer );
if (status == -1) { if (status == -1) {
myError.SetValue (errno, Iam, "Size"); myError.SetValue (errno, Iam, "Size");
return (-1); return 0;
} }
return ( buffer.st_size ); return (Standard_Size)buffer.st_size;
} }
@ -828,7 +829,7 @@ Standard_Boolean OSD_File::IsExecutable()
return Standard_True; return Standard_True;
} }
#else //WNT #else /* _WIN32 */
//------------------------------------------------------------------------ //------------------------------------------------------------------------
//------------------- Windows NT sources for OSD_File ------------------- //------------------- Windows NT sources for OSD_File -------------------
@ -862,7 +863,7 @@ Standard_Boolean OSD_File::IsExecutable()
#define ACE_HEADER_SIZE ( sizeof ( ACCESS_ALLOWED_ACE ) - sizeof ( DWORD ) ) #define ACE_HEADER_SIZE ( sizeof ( ACCESS_ALLOWED_ACE ) - sizeof ( DWORD ) )
#define RAISE( arg ) Standard_ProgramError :: Raise ( ( arg ) ) #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_NEW 0
#define OPEN_OLD 1 #define OPEN_OLD 1
@ -875,7 +876,7 @@ BOOL __fastcall _osd_wnt_sd_to_protection (
); );
BOOL __fastcall _osd_print (const Standard_PCharacter, Standard_CString ); 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 DWORDLONG __fastcall _get_line ( Standard_PCharacter&, DWORD );
static int __fastcall _get_buffer ( HANDLE, Standard_PCharacter&, DWORD, BOOL, BOOL ); static int __fastcall _get_buffer ( HANDLE, Standard_PCharacter&, DWORD, BOOL, BOOL );
static DWORD __fastcall _get_access_mask ( OSD_SingleProtection ); static DWORD __fastcall _get_access_mask ( OSD_SingleProtection );
@ -887,33 +888,38 @@ static OSD_SingleProtection __fastcall _get_protection_dir ( DWORD );
typedef OSD_SingleProtection ( __fastcall *GET_PROT_FUNC ) ( DWORD ); 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 // Create an empty file object
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
OSD_File :: OSD_File () { OSD_File :: OSD_File ()
{
ImperativeFlag = Standard_False; ImperativeFlag = Standard_False;
myLock = OSD_NoLock; myLock = OSD_NoLock;
myIO = 0; myIO = 0;
myFileChannel = -1;
myFileHandle = INVALID_HANDLE_VALUE;
} // end constructor ( 1 ) } // end constructor ( 1 )
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
// Create and initialize a file object // 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; ImperativeFlag = Standard_False;
myLock = OSD_NoLock; myLock = OSD_NoLock;
myIO = 0; myIO = 0;
myPath = Name; myPath = Name;
myFileChannel = -1;
myFileHandle = INVALID_HANDLE_VALUE;
} // end constructor ( 2 ) } // 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 // Build a file if it doesn't exist or create again if it already exists
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
@ -928,7 +934,7 @@ void OSD_File :: Build (
Standard_ProgramError::Raise("OSD_File::Read : it is a directory"); 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 (): incorrect call - file already opened" ) );
@ -939,9 +945,9 @@ void OSD_File :: Build (
RAISE( TEXT( "OSD_File :: Build (): incorrent call - no filename given" ) ); 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 ); _osd_wnt_set_error ( myError, OSD_WFile );
@ -966,7 +972,7 @@ void OSD_File :: Open (const OSD_OpenMode Mode, const OSD_Protection& /*Protect*
TCollection_AsciiString fName; 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 (): incorrect call - file already opened" ) );
@ -977,15 +983,15 @@ void OSD_File :: Open (const OSD_OpenMode Mode, const OSD_Protection& /*Protect*
RAISE( TEXT( "OSD_File :: Open (): incorrent call - no filename given" ) ); 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 ); _osd_wnt_set_error ( myError, OSD_WFile );
} }
else else
{ {
myIO |= _get_file_type ( fName.ToCString (), myFileChannel ); myIO |= _get_file_type ( fName.ToCString (), myFileHandle );
} }
} // end OSD_File :: Open } // end OSD_File :: Open
@ -1000,7 +1006,7 @@ void OSD_File :: Append (
BOOL fNew = FALSE; BOOL fNew = FALSE;
TCollection_AsciiString fName; 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 (): incorrect call - file already opened" ) );
@ -1011,9 +1017,9 @@ void OSD_File :: Append (
RAISE( TEXT( "OSD_File :: Append (): incorrent call - no filename given" ) ); 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 ); _osd_wnt_set_error ( myError, OSD_WFile );
@ -1021,7 +1027,7 @@ void OSD_File :: Append (
if ( !fNew ) { if ( !fNew ) {
myIO |= _get_file_type ( fName.ToCString (), myFileChannel ); myIO |= _get_file_type ( fName.ToCString (), myFileHandle );
Seek ( 0, OSD_FromEnd ); Seek ( 0, OSD_FromEnd );
} else { } else {
@ -1072,14 +1078,10 @@ void OSD_File :: Read (
} // end OSD_File :: Read } // end OSD_File :: Read
#define PRO13471
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
// Read a line from a file // 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> // Modified so that we have <nl> at end of line if we have read <nl> or <cr>
// in the file. // in the file.
// by LD 17 dec 98 for B4.4 // by LD 17 dec 98 for B4.4
@ -1117,10 +1119,7 @@ void OSD_File :: ReadLine (
if ( myIO & FLAG_FILE ) { if ( myIO & FLAG_FILE ) {
if ( !ReadFile ( if (!ReadFile (myFileHandle, cBuffer, (DWORD)NByte, &dwBytesRead, NULL)) { // an error occured
( HANDLE )myFileChannel, cBuffer, ( DWORD )NByte, &dwBytesRead, NULL
)
) { // an error occured
_osd_wnt_set_error ( myError, OSD_WFile ); _osd_wnt_set_error ( myError, OSD_WFile );
Buffer.Clear (); Buffer.Clear ();
@ -1144,10 +1143,7 @@ void OSD_File :: ReadLine (
if ( status == 0xFFFFFFFFFFFFFFFF ) { // last character in the buffer is <CR> - if ( status == 0xFFFFFFFFFFFFFFFF ) { // last character in the buffer is <CR> -
// peek next character to see if it is a <LF> // peek next character to see if it is a <LF>
#endif #endif
if ( !ReadFile ( if (!ReadFile (myFileHandle, ppeekChar, 1, &dwDummy, NULL)) {
( HANDLE )myFileChannel, ppeekChar, 1, &dwDummy, NULL
)
) {
_osd_wnt_set_error ( myError, OSD_WFile ); _osd_wnt_set_error ( myError, OSD_WFile );
@ -1157,7 +1153,7 @@ void OSD_File :: ReadLine (
// adjust file position // adjust file position
SetFilePointer ( ( HANDLE )myFileChannel, -1, NULL, FILE_CURRENT ); SetFilePointer (myFileHandle, -1, NULL, FILE_CURRENT);
} else } else
myIO |= FLAG_EOF; myIO |= FLAG_EOF;
@ -1167,7 +1163,7 @@ void OSD_File :: ReadLine (
} else { } else {
if ( dwSeekPos != 0 ) if ( dwSeekPos != 0 )
SetFilePointer ( ( HANDLE )myFileChannel, ( LONG )dwSeekPos, NULL, FILE_CURRENT ); SetFilePointer (myFileHandle, (LONG)dwSeekPos, NULL, FILE_CURRENT);
NbyteRead = ( Standard_Integer )( eos - cBuffer ); NbyteRead = ( Standard_Integer )( eos - cBuffer );
@ -1177,10 +1173,8 @@ void OSD_File :: ReadLine (
} else if ( myIO & FLAG_SOCKET || myIO & FLAG_PIPE || myIO & FLAG_NAMED_PIPE ) { } else if ( myIO & FLAG_SOCKET || myIO & FLAG_PIPE || myIO & FLAG_NAMED_PIPE ) {
dwBytesRead = ( DWORD )_get_buffer ( dwBytesRead = (DWORD)_get_buffer (myFileHandle, cBuffer,
( HANDLE )myFileChannel, cBuffer, ( DWORD )NByte, (DWORD)NByte, TRUE, myIO & FLAG_SOCKET);
TRUE, myIO & FLAG_SOCKET
);
if ( ( int )dwBytesRead == -1 ) { // an error occured if ( ( int )dwBytesRead == -1 ) { // an error occured
@ -1210,9 +1204,7 @@ void OSD_File :: ReadLine (
NbyteRead = dwBytesRead; // (LD) always fits this case. NbyteRead = dwBytesRead; // (LD) always fits this case.
dwDummy = _get_buffer ( dwDummy = _get_buffer (myFileHandle, ppeekChar, 1, TRUE, myIO & FLAG_SOCKET);
( HANDLE )myFileChannel, ppeekChar, 1, TRUE, myIO & FLAG_SOCKET
);
if ( ( int )dwDummy == -1 ) { // an error occured if ( ( int )dwDummy == -1 ) { // an error occured
_osd_wnt_set_error ( myError, OSD_WFile ); _osd_wnt_set_error ( myError, OSD_WFile );
@ -1239,9 +1231,8 @@ void OSD_File :: ReadLine (
Standard_PCharacter cDummyBuffer = new Standard_Character[ NByte + 3 ]; Standard_PCharacter cDummyBuffer = new Standard_Character[ NByte + 3 ];
_get_buffer ( // remove pending input // remove pending input
( HANDLE )myFileChannel, cDummyBuffer, dwBytesRead, FALSE, myIO & FLAG_SOCKET _get_buffer (myFileHandle, cDummyBuffer, dwBytesRead, FALSE, myIO & FLAG_SOCKET);
);
delete [] cDummyBuffer ; delete [] cDummyBuffer ;
} // end else } // end else
@ -1258,183 +1249,6 @@ void OSD_File :: ReadLine (
} // end OSD_File :: ReadLine } // 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 // Read content of a file
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
@ -1456,10 +1270,7 @@ void OSD_File :: Read (
RAISE( TEXT( "OSD_File :: Read (): attempt to read from write only pipe" ) ); RAISE( TEXT( "OSD_File :: Read (): attempt to read from write only pipe" ) );
if ( !ReadFile ( if (!ReadFile (myFileHandle, Buffer, (DWORD)Nbyte, &dwBytesRead, NULL)) {
( HANDLE )myFileChannel, Buffer, ( DWORD )Nbyte, &dwBytesRead, NULL
)
) {
_osd_wnt_set_error ( myError, OSD_WFile ); _osd_wnt_set_error ( myError, OSD_WFile );
dwBytesRead = 0; dwBytesRead = 0;
@ -1502,10 +1313,8 @@ void OSD_File :: Write (
RAISE( TEXT( "OSD_File :: Write (): attempt to write to read only pipe" ) ); RAISE( TEXT( "OSD_File :: Write (): attempt to write to read only pipe" ) );
if ( !WriteFile ( if (!WriteFile (myFileHandle, Buffer, (DWORD)Nbyte, &dwBytesWritten, NULL) ||
( HANDLE )myFileChannel, Buffer, ( DWORD )Nbyte, &dwBytesWritten, NULL dwBytesWritten != (DWORD)Nbyte)
) || dwBytesWritten != ( DWORD )Nbyte
)
_osd_wnt_set_error ( myError, OSD_WFile ); _osd_wnt_set_error ( myError, OSD_WFile );
@ -1547,10 +1356,7 @@ void OSD_File :: Seek (
} // end switch } // end switch
if ( SetFilePointer ( if (SetFilePointer (myFileHandle, (LONG)Offset, NULL, dwMoveMethod) == 0xFFFFFFFF)
( HANDLE )myFileChannel, ( LONG )Offset, NULL, dwMoveMethod
) == 0xFFFFFFFF
)
_osd_wnt_set_error ( myError, OSD_WFile ); _osd_wnt_set_error ( myError, OSD_WFile );
@ -1568,9 +1374,9 @@ void OSD_File :: Close () {
TEST_RAISE( TEXT( "Close" ) ); TEST_RAISE( TEXT( "Close" ) );
CloseHandle ( ( HANDLE )myFileChannel ); CloseHandle (myFileHandle);
myFileChannel = ( Standard_Integer )INVALID_HANDLE_VALUE; myFileHandle = INVALID_HANDLE_VALUE;
myIO = 0; myIO = 0;
} // end OSD_File :: Close } // end OSD_File :: Close
@ -1594,7 +1400,7 @@ OSD_KindFile OSD_File :: KindOfFile () const {
OSD_KindFile retVal; OSD_KindFile retVal;
Standard_Integer flags; Standard_Integer flags;
if ( ( HANDLE )myFileChannel == INVALID_HANDLE_VALUE ) { if (myFileHandle == INVALID_HANDLE_VALUE) {
TCollection_AsciiString fName; TCollection_AsciiString fName;
@ -1604,9 +1410,7 @@ OSD_KindFile OSD_File :: KindOfFile () const {
RAISE( TEXT( "OSD_File :: KindOfFile (): incorrent call - no filename given" ) ); RAISE( TEXT( "OSD_File :: KindOfFile (): incorrent call - no filename given" ) );
flags = _get_file_type ( flags = _get_file_type (fName.ToCString(), INVALID_HANDLE_VALUE);
fName.ToCString (), ( Standard_Integer )INVALID_HANDLE_VALUE
);
} else } else
@ -1794,10 +1598,9 @@ void OSD_File :: SetLock ( const OSD_LockType Lock ) {
dwFlags = 0; dwFlags = 0;
if ( !LockFileEx ( LARGE_INTEGER aSize;
( HANDLE )myFileChannel, dwFlags, 0, Size (), 0, &ovlp aSize.QuadPart = Size();
) if (!LockFileEx (myFileHandle, dwFlags, 0, aSize.LowPart, aSize.HighPart, &ovlp)) {
) {
_osd_wnt_set_error ( myError, OSD_WFile ); _osd_wnt_set_error ( myError, OSD_WFile );
__leave; __leave;
@ -1827,10 +1630,9 @@ void OSD_File :: UnLock () {
if ( ImperativeFlag ) { if ( ImperativeFlag ) {
if ( !UnlockFile ( LARGE_INTEGER aSize;
( HANDLE )myFileChannel, 0, 0, Size (), 0 aSize.QuadPart = Size();
) if (!UnlockFile (myFileHandle, 0, 0, aSize.LowPart, aSize.HighPart))
)
_osd_wnt_set_error ( myError, OSD_WFile ); _osd_wnt_set_error ( myError, OSD_WFile );
@ -1859,21 +1661,21 @@ Standard_Boolean OSD_File :: IsLocked () {
// Return size of a file // Return size of a file
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
Standard_Integer OSD_File :: Size () { Standard_Size OSD_File :: Size () {
Standard_Integer retVal; Standard_Integer retVal;
TEST_RAISE( TEXT( "Size" ) ); TEST_RAISE( TEXT( "Size" ) );
retVal = ( Standard_Integer )GetFileSize ( LARGE_INTEGER aSize;
( HANDLE )myFileChannel, NULL aSize.QuadPart = 0;
); retVal = GetFileSizeEx (myFileHandle, &aSize);
if ( retVal == ( Standard_Integer )0xFFFFFFFF ) if ( retVal == 0 )
_osd_wnt_set_error ( myError, OSD_WFile ); _osd_wnt_set_error ( myError, OSD_WFile );
return retVal; return (Standard_Size)aSize.QuadPart;
} // end OSD_File :: Size } // end OSD_File :: Size
@ -1883,7 +1685,7 @@ Standard_Integer OSD_File :: Size () {
void OSD_File :: Print ( const OSD_Printer& WhichPrinter ) { 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" ) ); RAISE( TEXT( "OSD_File :: Print (): incorrect call - file opened" ) );
@ -1904,7 +1706,7 @@ void OSD_File :: Print ( const OSD_Printer& WhichPrinter ) {
Standard_Boolean OSD_File :: IsOpen () const { Standard_Boolean OSD_File :: IsOpen () const {
return ( HANDLE )myFileChannel != INVALID_HANDLE_VALUE; return myFileHandle != INVALID_HANDLE_VALUE;
} // end OSD_File :: IsOpen } // end OSD_File :: IsOpen
@ -2179,11 +1981,11 @@ leave: ; // added for VisualAge
#undef __leave #undef __leave
#endif #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 ]; Standard_Character buff[ 64 ];
if ( ( HANDLE )hFile == INVALID_HANDLE_VALUE ) { if (hFile == INVALID_HANDLE_VALUE) {
_tcscpy ( buff, TEXT( "OSD_File :: " ) ); _tcscpy ( buff, TEXT( "OSD_File :: " ) );
_tcscat ( buff, str ); _tcscat ( buff, str );
@ -2195,8 +1997,6 @@ static void __fastcall _test_raise ( Standard_Integer hFile, Standard_CString st
} // end _test_raise } // end _test_raise
#ifdef PRO13471
// Modified so that we have <nl> at end of line if we have read <nl> or <cr> // 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 // by LD 17 dec 98 for B4.4
@ -2261,76 +2061,6 @@ static DWORDLONG __fastcall _get_line ( Standard_PCharacter& buffer, DWORD dwBuf
} // end _get_line } // 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 ( static int __fastcall _get_buffer (
HANDLE hChannel, HANDLE hChannel,
Standard_PCharacter& buffer, Standard_PCharacter& buffer,
@ -2676,16 +2406,15 @@ static HANDLE __fastcall _open_file (
} // end _open_file } // end _open_file
Standard_Integer __fastcall _get_file_type ( Standard_Integer __fastcall _get_file_type (
Standard_CString fName, Standard_Integer fileHandle Standard_CString fName, HANDLE fileHandle
) { ) {
Standard_Integer retVal = 0; Standard_Integer retVal = 0;
DWORD dwType; DWORD dwType;
int fileType; int fileType;
fileType = fileHandle == ( Standard_Integer )INVALID_HANDLE_VALUE ? fileType = (fileHandle == INVALID_HANDLE_VALUE ?
FILE_TYPE_DISK : FILE_TYPE_DISK : GetFileType (fileHandle));
GetFileType ( ( HANDLE )fileHandle );
switch ( fileType ) { switch ( fileType ) {
@ -3168,7 +2897,7 @@ Standard_Boolean OSD_File::IsExecutable()
// if (_access(FileName.ToCString(),0)) // if (_access(FileName.ToCString(),0))
} }
#endif // WNT #endif /* _WIN32 */
// --------------------------------------------------------------------- // ---------------------------------------------------------------------

View File

@ -130,7 +130,6 @@ is
fields fields
myPath : Path is protected; -- system independent path name myPath : Path is protected; -- system independent path name
myFileChannel : Integer is protected; -- file descriptor
myError : Error is protected; myError : Error is protected;
end FileNode from OSD; end FileNode from OSD;

View File

@ -20,7 +20,11 @@
# include <config.h> # include <config.h>
#endif #endif
#ifndef WNT #ifndef _WIN32
//----------------------------------------------------------------------------
//------------------- Linux Sources of OSD_FileNode --------------------------
//----------------------------------------------------------------------------
#include <unistd.h> #include <unistd.h>
#include <errno.h> #include <errno.h>
@ -66,15 +70,14 @@ const OSD_WhoAmI Iam = OSD_WFileNode;
// Create a file/directory object // Create a file/directory object
OSD_FileNode::OSD_FileNode (){ OSD_FileNode::OSD_FileNode ()
myFileChannel = -1; {
} }
// Create and initialize a file/directory object // Create and initialize a file/directory object
OSD_FileNode::OSD_FileNode (const OSD_Path& Name){ OSD_FileNode::OSD_FileNode (const OSD_Path& Name)
{
SetPath (Name); SetPath (Name);
} }
@ -191,15 +194,7 @@ TCollection_AsciiString thisPath;
if (status == -1) myError.SetValue (errno, Iam, "Move"); if (status == -1) myError.SetValue (errno, Iam, "Move");
} }
// Copy a file to another path and name // Copy a file to another path and name
#ifndef WNT
int static copy_file( const char* src, const char* trg ) int static copy_file( const char* src, const char* trg )
{ {
int err=0; int err=0;
@ -236,11 +231,6 @@ int static copy_file( const char* src, const char* trg )
return err; return err;
} }
#endif
void OSD_FileNode::Copy(const OSD_Path& ToPath) void OSD_FileNode::Copy(const OSD_Path& ToPath)
{ {
int status; int status;
@ -441,7 +431,7 @@ Standard_Integer OSD_FileNode::Error()const{
return( myError.Error()); return( myError.Error());
} }
#else #else /* _WIN32 */
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
//------------------- WNT Sources of OSD_FileNode --------------------------- //------------------- WNT Sources of OSD_FileNode ---------------------------
@ -466,7 +456,7 @@ PSECURITY_DESCRIPTOR __fastcall _osd_wnt_protection_to_sd ( const OSD_Protection
BOOL __fastcall _osd_wnt_sd_to_protection ( BOOL __fastcall _osd_wnt_sd_to_protection (
PSECURITY_DESCRIPTOR pSD, OSD_Protection& prot, BOOL PSECURITY_DESCRIPTOR pSD, OSD_Protection& prot, BOOL
); );
Standard_Integer __fastcall _get_file_type ( Standard_CString, Standard_Integer ); Standard_Integer __fastcall _get_file_type ( Standard_CString, HANDLE );
void _osd_wnt_set_error ( OSD_Error&, OSD_WhoAmI, ... ); void _osd_wnt_set_error ( OSD_Error&, OSD_WhoAmI, ... );
@ -478,22 +468,18 @@ static void __fastcall _test_raise ( TCollection_AsciiString, Standard_CString )
//purpose : Empty Constructor //purpose : Empty Constructor
//======================================================================= //=======================================================================
OSD_FileNode::OSD_FileNode () { OSD_FileNode::OSD_FileNode ()
{
myFileChannel = ( Standard_Integer )INVALID_HANDLE_VALUE; }
} // end constructor ( 1 )
//======================================================================= //=======================================================================
//function : OSD_FileNode //function : OSD_FileNode
//purpose : Constructor //purpose : Constructor
//======================================================================= //=======================================================================
OSD_FileNode::OSD_FileNode ( const OSD_Path& Name ) { OSD_FileNode::OSD_FileNode ( const OSD_Path& Name )
{
myFileChannel = ( Standard_Integer )INVALID_HANDLE_VALUE;
myPath = Name; myPath = Name;
} // end constructor ( 2 ) } // end constructor ( 2 )
//======================================================================= //=======================================================================
@ -560,8 +546,7 @@ void OSD_FileNode::Remove () {
TEST_RAISE( TEXT( "Remove" ) ); TEST_RAISE( TEXT( "Remove" ) );
switch ( _get_file_type ( fName.ToCString (), switch (_get_file_type (fName.ToCString(), INVALID_HANDLE_VALUE)) {
( Standard_Integer )INVALID_HANDLE_VALUE ) ) {
case FLAG_FILE: case FLAG_FILE:
@ -608,8 +593,7 @@ void OSD_FileNode::Move ( const OSD_Path& NewPath ) {
NewPath.SystemName ( fNameDst ); NewPath.SystemName ( fNameDst );
switch ( _get_file_type ( fName.ToCString (), switch (_get_file_type (fName.ToCString (), INVALID_HANDLE_VALUE)) {
( Standard_Integer )INVALID_HANDLE_VALUE ) ) {
case FLAG_FILE: case FLAG_FILE:
@ -659,8 +643,7 @@ void OSD_FileNode::Copy ( const OSD_Path& ToPath ) {
ToPath.SystemName ( fNameDst ); ToPath.SystemName ( fNameDst );
switch ( _get_file_type ( fName.ToCString (), switch (_get_file_type (fName.ToCString(), INVALID_HANDLE_VALUE)) {
( Standard_Integer )INVALID_HANDLE_VALUE ) ) {
case FLAG_FILE: case FLAG_FILE:
@ -713,9 +696,7 @@ OSD_Protection OSD_FileNode::Protection () {
) == NULL || ) == NULL ||
!_osd_wnt_sd_to_protection ( !_osd_wnt_sd_to_protection (
pSD, retVal, pSD, retVal,
_get_file_type ( fName.ToCString (), ( Standard_Integer )INVALID_HANDLE_VALUE ) == _get_file_type (fName.ToCString(), INVALID_HANDLE_VALUE) == FLAG_DIRECTORY)
FLAG_DIRECTORY
)
) )
_osd_wnt_set_error ( myError, OSD_WFileNode ); _osd_wnt_set_error ( myError, OSD_WFileNode );
@ -744,8 +725,7 @@ void OSD_FileNode::SetProtection ( const OSD_Protection& Prot ) {
pSD = _osd_wnt_protection_to_sd ( pSD = _osd_wnt_protection_to_sd (
Prot, Prot,
_get_file_type ( fName.ToCString (), _get_file_type (fName.ToCString(), INVALID_HANDLE_VALUE) ==
( Standard_Integer )INVALID_HANDLE_VALUE ) ==
FLAG_DIRECTORY, FLAG_DIRECTORY,
(char *)fName.ToCString () (char *)fName.ToCString ()
); );
@ -1060,4 +1040,4 @@ static void __fastcall _test_raise ( TCollection_AsciiString fName, Standard_CSt
} // end _test_raise } // end _test_raise
#endif #endif /* _WIN32 */

View File

@ -345,7 +345,7 @@ Handle_StlMesh_Mesh RWStl::ReadBinary (const OSD_Path& thePath,
// must be a multiple of SIZEOF_STL_FACET // must be a multiple of SIZEOF_STL_FACET
// compute file size // compute file size
Standard_Integer filesize = theFile.Size(); Standard_Size filesize = theFile.Size();
if ( (filesize - HEADER_SIZE) % SIZEOF_STL_FACET !=0 if ( (filesize - HEADER_SIZE) % SIZEOF_STL_FACET !=0
|| (filesize < STL_MIN_FILE_SIZE)) { || (filesize < STL_MIN_FILE_SIZE)) {
@ -354,7 +354,7 @@ Handle_StlMesh_Mesh RWStl::ReadBinary (const OSD_Path& thePath,
// don't trust the number of triangles which is coded in the file // don't trust the number of triangles which is coded in the file
// sometimes it is wrong, and with this technique we don't need to swap endians for integer // sometimes it is wrong, and with this technique we don't need to swap endians for integer
NBFACET = ((filesize - HEADER_SIZE) / SIZEOF_STL_FACET); NBFACET = (Standard_Integer)((filesize - HEADER_SIZE) / SIZEOF_STL_FACET);
// skip the header // skip the header
theFile.Seek(HEADER_SIZE,OSD_FromBeginning); theFile.Seek(HEADER_SIZE,OSD_FromBeginning);