#ifndef _WIN32
-#include <Standard_ProgramError.hxx>
+
+#include <OSD_File.hxx>
+#include <OSD_FromWhere.hxx>
#include <OSD_OSDError.hxx>
+#include <OSD_Path.hxx>
+#include <OSD_Protection.hxx>
#include <OSD_WhoAmI.hxx>
-#include <OSD_FromWhere.hxx>
-#include <OSD_File.ixx>
-
#include <Standard_PCharacter.hxx>
+#include <Standard_ProgramError.hxx>
+#include <TCollection_AsciiString.hxx>
const OSD_WhoAmI Iam = OSD_WFile;
// ---------------------------------------------------------------------
// ---------------------------------------------------------------------
-OSD_File OSD_File::BuildTemporary(){
+void OSD_File::BuildTemporary(){
+
+ if ( IsOpen() )
+ Close();
#if defined(vax) || defined(__vms) || defined(VAXVMS)
FILE *fic;
- OSD_File result;
int dummy;
fic = tmpfile();
dummy = open("dummy", O_RDWR | O_CREAT); // Open a dummy file
- result.myFileChannel = dummy - 1; // This is file channel of "fic" +1
+ myFileChannel = dummy - 1; // This is file channel of "fic" +1
close(dummy); // Close dummy file
unlink("dummy"); // Removes dummy file
#else
- OSD_File result;
- char *name = tmpnam((char*) 0) ;
-
+ char name[] = "/tmp/CSFXXXXXX";
+ myFileChannel = mkstemp( name );
TCollection_AsciiString aName ( name ) ;
OSD_Path aPath( aName ) ;
- result.SetPath( aPath ) ;
+ SetPath( aPath ) ;
- result.myFILE = fopen( name, "w+" ) ;
-
- result.myFileChannel = fileno( (FILE*)result.myFILE );
+ myFILE = fdopen( myFileChannel, "w+" ) ;
#endif
- result.myMode = OSD_ReadWrite;
-
- return (result);
+ myMode = OSD_ReadWrite;
}
// --------------------------------------------------------------------------
// Read content of a file
// --------------------------------------------------------------------------
-void OSD_File::Read( Standard_Address& Buffer,
+void OSD_File::Read(const Standard_Address Buffer,
const Standard_Integer Nbyte,
Standard_Integer& Readbyte)
{
// Return lock of a file
OSD_LockType OSD_File::GetLock(){
- if (myFileChannel == -1)
- Standard_ProgramError::Raise("OSD_File::GetLock : file is not open");
-
return(myLock);
}
return (Standard_Size)buffer.st_size;
}
-
-// --------------------------------------------------------------------------
-// Print contains of a file
-// --------------------------------------------------------------------------
-
-void OSD_File::Print (const OSD_Printer &WhichPrinter ){
-char buffer[255];
-TCollection_AsciiString PrinterName;
-
- if (myPath.Name().Length()==0)
- Standard_ProgramError::Raise("OSD_File::Print : empty file name");
-
- WhichPrinter.Name(PrinterName);
-
- TCollection_AsciiString aBuffer;
- myPath.SystemName ( aBuffer );
-
- if (PrinterName.Length()==0)
- sprintf(buffer,"lp %s",aBuffer.ToCString());
- else
- sprintf(buffer,"lpr -P%s %s",PrinterName.ToCString(),aBuffer.ToCString());
-
- system(buffer);
-}
-
-
// --------------------------------------------------------------------------
// Test if a file is open
// --------------------------------------------------------------------------
Standard_Boolean OSD_File::IsOpen()const{
-
- if (myPath.Name().Length()==0)
- Standard_ProgramError::Raise("OSD_File::IsOpen : empty file name");
-
return (myFileChannel != -1);
}
Standard_Boolean OSD_File::IsLocked(){
-
- if (myPath.Name().Length()==0)
- Standard_ProgramError::Raise("OSD_File::IsLocked : empty file name");
-
return(myLock != OSD_NoLock);
}
return Standard_True;
}
+int OSD_File::Capture(int theDescr) {
+ // Duplicate an old file descriptor of the given one to be able to restore output to it later.
+ int oldDescr = dup(theDescr);
+ // Redirect the output to this file
+ dup2(myFileChannel, theDescr);
+
+ // Return the old descriptor
+ return oldDescr;
+}
+
+void OSD_File::Rewind() {
+ rewind((FILE*)myFILE);
+}
+
#else /* _WIN32 */
//------------------------------------------------------------------------
#include <OSD_File.hxx>
#include <OSD_Protection.hxx>
-#include <OSD_Printer.hxx>
#include <Standard_ProgramError.hxx>
#include <OSD_WNT_1.hxx>
#include <Standard_PCharacter.hxx>
#include <TCollection_ExtendedString.hxx>
-#ifndef _INC_TCHAR
-# include <tchar.h>
-#endif // _INC_TCHAR
+#include <Strsafe.h>
#if defined(__CYGWIN32__) || defined(__MINGW32__)
#define VAC
-#define _int64 int
#endif
-#pragma comment( lib, "WSOCK32.LIB" )
-#pragma comment( lib, "WINSPOOL.LIB" )
-
#define ACE_HEADER_SIZE ( sizeof ( ACCESS_ALLOWED_ACE ) - sizeof ( DWORD ) )
#define RAISE( arg ) Standard_ProgramError :: Raise ( ( arg ) )
#define OPEN_APPEND 2
void _osd_wnt_set_error ( OSD_Error&, OSD_WhoAmI, ... );
-PSECURITY_DESCRIPTOR __fastcall _osd_wnt_protection_to_sd ( const OSD_Protection&, BOOL, wchar_t* = NULL );
+#ifndef OCCT_UWP
+PSECURITY_DESCRIPTOR __fastcall _osd_wnt_protection_to_sd ( const OSD_Protection&, BOOL, const wchar_t* );
BOOL __fastcall _osd_wnt_sd_to_protection (
PSECURITY_DESCRIPTOR, OSD_Protection&, BOOL
);
-BOOL __fastcall _osd_print (const Standard_PCharacter, const wchar_t* );
-
+static int __fastcall _get_buffer(HANDLE, Standard_PCharacter&, DWORD, BOOL, BOOL);
+#endif
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 Standard_Integer __fastcall _get_line (Standard_PCharacter& buffer, DWORD dwBuffSize, LONG& theSeekPos);
static DWORD __fastcall _get_access_mask ( OSD_SingleProtection );
static DWORD __fastcall _get_dir_access_mask ( OSD_SingleProtection prt );
static HANDLE __fastcall _open_file ( Standard_CString, OSD_OpenMode, DWORD, LPBOOL = NULL );
myFileHandle = INVALID_HANDLE_VALUE;
} // end constructor ( 2 )
+// ---------------------------------------------------------------------
+// Redirect a standard handle (fileno(stdout), fileno(stdin) or
+// fileno(stderr) to this OSD_File and return the copy of the original
+// standard handle.
+// Example:
+// OSD_File aTmp;
+// aTmp.BuildTemporary();
+// int stdfd = _fileno(stdout);
+//
+// int oldout = aTmp.Capture(stdfd);
+// cout << "Some output to the file" << endl;
+// cout << flush;
+// fflush(stdout);
+//
+// _dup2(oldout, stdfd); // Restore standard output
+// aTmp.Close();
+// ---------------------------------------------------------------------
+int OSD_File::Capture(int theDescr) {
+ // Get POSIX file descriptor from this file handle
+ int dFile = _open_osfhandle(reinterpret_cast<intptr_t>(myFileHandle), myMode);
+
+ if (0 > dFile)
+ {
+ _osd_wnt_set_error ( myError, OSD_WFile, myFileHandle );
+ return -1;
+ }
+
+ // Duplicate an old file descriptor of the given one to be able to restore output to it later.
+ int oldDescr = _dup(theDescr);
+ // Redirect the output to this file
+ _dup2(dFile, theDescr);
+
+ // Return the old descriptor
+ return oldDescr;
+}
+
+void OSD_File::Rewind() {
+ LARGE_INTEGER aDistanceToMove;
+ aDistanceToMove.QuadPart = 0;
+ SetFilePointerEx(myFileHandle, aDistanceToMove, NULL, FILE_BEGIN);
+}
+
// 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
// ---------------------------------------------------------------------
-void OSD_File :: Build (
- const OSD_OpenMode Mode, const OSD_Protection& Protect
- ) {
+void OSD_File :: Build ( const OSD_OpenMode Mode, const OSD_Protection& Protect) {
TCollection_AsciiString fName;
_osd_wnt_set_error ( myError, OSD_WFile );
else {
-
+#ifndef OCCT_UWP
SetProtection ( Protect );
+#else
+ (void)Protect;
+#endif
myIO |= FLAG_FILE;
} // end else
// Append to an existing file
// ---------------------------------------------------------------------
-void OSD_File :: Append (
- const OSD_OpenMode Mode, const OSD_Protection& Protect
- ) {
+void OSD_File :: Append ( const OSD_OpenMode Mode, const OSD_Protection& Protect) {
BOOL fNew = FALSE;
TCollection_AsciiString fName;
Seek ( 0, OSD_FromEnd );
} else {
-
- SetProtection ( Protect );
+#ifndef OCCT_UWP
+ SetProtection ( Protect );
+#else
+ (void)Protect;
+#endif
myIO |= FLAG_FILE;
} // end else
) {
if ( OSD_File::KindOfFile ( ) == OSD_DIRECTORY ) {
-#ifdef OSD_DEB
+#ifdef OCCT_DEBUG
cout << " OSD_File::Read : it is a directory " << endl;
#endif
return ;
}
Standard_Integer NbyteRead;
- Standard_Address buff;
TEST_RAISE( "Read" );
- buff = ( Standard_Address )new Standard_Character[ Nbyte + 1 ];
+ char* buff = new Standard_Character[ Nbyte + 1 ];
Read ( buff, Nbyte, NbyteRead );
- ( ( Standard_PCharacter )buff )[ NbyteRead ] = 0;
+ buff[ NbyteRead ] = 0;
if ( NbyteRead != 0 )
- Buffer = ( Standard_PCharacter )buff;
+ Buffer = buff;
else
const Standard_Integer NByte, Standard_Integer& NbyteRead
) {
- DWORDLONG status;
DWORD dwBytesRead;
DWORD dwDummy;
Standard_Character peekChar;
Standard_PCharacter ppeekChar;
Standard_PCharacter cBuffer;
- Standard_CString eos;
- DWORD dwSeekPos;
+ LONG aSeekPos;
if ( OSD_File::KindOfFile ( ) == OSD_DIRECTORY ) {
Standard_ProgramError::Raise("OSD_File::Read : it is a directory");
if ( myIO & FLAG_FILE ) {
- if (!ReadFile (myFileHandle, cBuffer, (DWORD)NByte, &dwBytesRead, NULL)) { // an error occured
+ if (!ReadFile (myFileHandle, cBuffer, NByte, &dwBytesRead, NULL)) { // an error occured
_osd_wnt_set_error ( myError, OSD_WFile );
Buffer.Clear ();
} else {
myIO &= ~FLAG_EOF ; // if the file increased since last read (LD)
- status = _get_line ( cBuffer, dwBytesRead );
+ NbyteRead = _get_line (cBuffer, dwBytesRead, aSeekPos);
- 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 ( NbyteRead == -1 ) // last character in the buffer is <CR> -
+ { // peek next character to see if it is a <LF>
if (!ReadFile (myFileHandle, ppeekChar, 1, &dwDummy, NULL)) {
_osd_wnt_set_error ( myError, OSD_WFile );
} else if ( dwDummy != 0 ) { // end-of-file reached ?
- if ( peekChar != '\n' ) // if we did not get a <CR><LF> sequence
-
- // adjust file position
-
- SetFilePointer (myFileHandle, -1, NULL, FILE_CURRENT);
-
+ if (peekChar != '\n') // if we did not get a <CR><LF> sequence
+ {
+ // adjust file position
+ LARGE_INTEGER aDistanceToMove;
+ aDistanceToMove.QuadPart = -1;
+ SetFilePointerEx(myFileHandle, aDistanceToMove, NULL, FILE_CURRENT);
+ }
} else
myIO |= FLAG_EOF;
NbyteRead = dwBytesRead;
- } else {
-
- if ( dwSeekPos != 0 )
- SetFilePointer (myFileHandle, (LONG)dwSeekPos, NULL, FILE_CURRENT);
-
- NbyteRead = ( Standard_Integer )( eos - cBuffer );
-
+ } else if ( aSeekPos != 0 )
+ {
+ LARGE_INTEGER aDistanceToMove;
+ aDistanceToMove.QuadPart = aSeekPos;
+ SetFilePointerEx(myFileHandle, aDistanceToMove, NULL, FILE_CURRENT);
}
} // end else
} else if ( myIO & FLAG_SOCKET || myIO & FLAG_PIPE || myIO & FLAG_NAMED_PIPE ) {
-
+#ifndef OCCT_UWP
dwBytesRead = (DWORD)_get_buffer (myFileHandle, cBuffer,
(DWORD)NByte, TRUE, myIO & FLAG_SOCKET);
} 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
+ NbyteRead = _get_line (cBuffer, dwBytesRead, aSeekPos);
+ if (NbyteRead == -1) // last character in the buffer is <CR> -
+ { // peek next character to see if it is a <LF>
NbyteRead = dwBytesRead; // (LD) always fits this case.
dwDummy = _get_buffer (myFileHandle, ppeekChar, 1, TRUE, myIO & FLAG_SOCKET);
myIO |= FLAG_EOF;
- } else {
-
- if ( dwSeekPos != 0 )
- dwBytesRead = dwBytesRead + dwSeekPos;
-
- NbyteRead = ( Standard_Integer )( eos - cBuffer );
-
+ } else if (aSeekPos != 0)
+ {
+ dwBytesRead = dwBytesRead + aSeekPos;
}
// Don't rewrite datas in cBuffer.
delete [] cDummyBuffer ;
} // end else
-
+#endif
} else
RAISE( "OSD_File :: ReadLine (): incorrect call - file is a directory" );
// --------------------------------------------------------------------------
void OSD_File :: Read (
- Standard_Address& Buffer,
+ const Standard_Address Buffer,
const Standard_Integer Nbyte, Standard_Integer& Readbyte
) {
RAISE( "OSD_File :: Seek (): invalid parameter" );
} // end switch
+ LARGE_INTEGER aDistanceToMove, aNewFilePointer;
+ aNewFilePointer.QuadPart = 0;
+ aDistanceToMove.QuadPart = Offset;
- if (SetFilePointer (myFileHandle, (LONG)Offset, NULL, dwMoveMethod) == 0xFFFFFFFF)
+ if (!SetFilePointerEx(myFileHandle, aDistanceToMove, &aNewFilePointer, dwMoveMethod))
_osd_wnt_set_error ( myError, OSD_WFile );
return retVal;
} // end OSD_File :: KindOfFile
-#define PRO13792
-#ifndef PRO13792
-
-OSD_File OSD_File :: BuildTemporary () {
-
- OSD_Protection prt;
- OSD_File retVal;
-
-#ifdef VAC
- char tmpbuf [MAX_PATH];
- if (GetTempPath (MAX_PATH, tmpbuf) == 0)
- {
- perror ("ERROR in GetTempPath");
- exit (10);
- }
- char tmpbuf2 [MAX_PATH];
- if (GetTempFileName (tmpbuf, NULL, 0, tmpbuf2) == 0)
- {
- perror ("ERROR in GetTempFileName");
- exit (10);
- }
- TCollection_AsciiString fileName ( tmpbuf2 );
-#else
- TCollection_AsciiString fileName ( _ttmpnam ( NULL ) );
-#endif
-
- OSD_Path filePath ( fileName );
-
- retVal.SetPath ( filePath );
- retVal.Build ( OSD_ReadWrite, prt );
-
- return retVal;
-
-} // end OSD_File :: BuildTemporary
-
-#else // PRO13792
//-------------------------------------------------debutpri???980424
typedef struct _osd_wnt_key {
HKEY hKey;
- LPTSTR keyPath;
+ wchar_t* keyPath;
} OSD_WNT_KEY;
-OSD_File OSD_File :: BuildTemporary () {
+ void OSD_File::BuildTemporary () {
OSD_Protection prt;
- OSD_File retVal;
- HKEY hKey;
- TCHAR tmpPath[ MAX_PATH ];
+ wchar_t tmpPath[ MAX_PATH ];
BOOL fOK = FALSE;
+
+// Windows Registry not supported by UWP
+#ifndef OCCT_UWP
+ HKEY hKey;
+
OSD_WNT_KEY regKey[ 2 ] = {
{ HKEY_LOCAL_MACHINE,
- "SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment"
+ L"SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment"
},
{ HKEY_USERS,
- ".DEFAULT\\Environment"
+ L".DEFAULT\\Environment"
}
};
for ( int i = 0; i < 2; ++i ) {
- if ( RegOpenKeyEx (
+ if ( RegOpenKeyExW (
regKey[ i ].hKey, regKey[ i ].keyPath, 0, KEY_QUERY_VALUE, &hKey
) == ERROR_SUCCESS
) {
DWORD dwType;
DWORD dwSize = 0;
- if ( RegQueryValueEx (
- hKey, "TEMP", NULL, &dwType, NULL, &dwSize
+ if ( RegQueryValueExW (
+ hKey, L"TEMP", NULL, &dwType, NULL, &dwSize
) == ERROR_SUCCESS
) {
- LPTSTR kVal = ( LPTSTR )HeapAlloc (
+ wchar_t* kVal = (wchar_t*)HeapAlloc (
GetProcessHeap (), HEAP_ZERO_MEMORY | HEAP_GENERATE_EXCEPTIONS,
- dwSize + sizeof ( TCHAR )
+ dwSize + sizeof (wchar_t)
);
- RegQueryValueEx ( hKey, "TEMP", NULL, &dwType, ( LPBYTE )kVal, &dwSize );
+ RegQueryValueExW ( hKey, L"TEMP", NULL, &dwType, ( LPBYTE )kVal, &dwSize );
if ( dwType == REG_EXPAND_SZ )
- ExpandEnvironmentStrings ( kVal, tmpPath, MAX_PATH );
+ ExpandEnvironmentStringsW ( kVal, tmpPath, MAX_PATH );
else
- lstrcpy ( tmpPath, kVal );
+ StringCchCopyW (tmpPath, _countof(tmpPath), kVal);
HeapFree ( GetProcessHeap (), 0, ( LPVOID )kVal );
fOK = TRUE;
if ( fOK ) break;
} // end for
+#else
+ if (GetTempPathW(_countof(tmpPath), tmpPath))
+ fOK = TRUE;
+#endif
+ if ( !fOK ) StringCchCopyW(tmpPath, _countof(tmpPath), L"./");
- if ( !fOK ) lstrcpy ( tmpPath, "./" );
-
- GetTempFileName ( tmpPath, "CSF", 0, tmpPath );
+ GetTempFileNameW ( tmpPath, L"CSF", 0, tmpPath );
- retVal.SetPath ( OSD_Path ( tmpPath ) );
- retVal.Build ( OSD_ReadWrite, prt );
+ if ( IsOpen() )
+ Close();
- return retVal;
+ char tmpPathA[MAX_PATH];
+ WideCharToMultiByte(CP_UTF8, 0, tmpPath, -1, tmpPathA, sizeof(tmpPathA), NULL, NULL);
+ SetPath(OSD_Path(tmpPathA));
+ Build ( OSD_ReadWrite, prt );
} // end OSD_File :: BuildTemporary
-#endif // PRO13792
-
//-------------------------------------------------finpri???980424
#if defined(__CYGWIN32__) || defined(__MINGW32__)
LARGE_INTEGER aSize;
aSize.QuadPart = Size();
- if (!UnlockFile (myFileHandle, 0, 0, aSize.LowPart, aSize.HighPart))
-
+
+ OVERLAPPED anOverlappedArea;
+ anOverlappedArea.Offset = 0;
+ anOverlappedArea.OffsetHigh = 0;
+
+ if (!UnlockFileEx(myFileHandle, 0, aSize.LowPart, aSize.HighPart,&anOverlappedArea))
_osd_wnt_set_error ( myError, OSD_WFile );
ImperativeFlag = Standard_False;
// Return size of a file
// --------------------------------------------------------------------------
-Standard_Size OSD_File :: Size () {
-
- Standard_Integer retVal;
-
- TEST_RAISE( "Size" );
-
- LARGE_INTEGER aSize;
- aSize.QuadPart = 0;
- retVal = GetFileSizeEx (myFileHandle, &aSize);
-
- if ( retVal == 0 )
-
- _osd_wnt_set_error ( myError, OSD_WFile );
-
- return (Standard_Size)aSize.QuadPart;
-
-} // end OSD_File :: Size
-
-// --------------------------------------------------------------------------
-// Print contains of a file
-// --------------------------------------------------------------------------
-
-void OSD_File :: Print ( const OSD_Printer& WhichPrinter ) {
-
- if (myFileHandle != INVALID_HANDLE_VALUE)
-
- RAISE( "OSD_File :: Print (): incorrect call - file opened" );
-
- TCollection_AsciiString pName, fName;
-
- WhichPrinter.Name ( pName );
- myPath.SystemName ( fName );
- TCollection_ExtendedString fNameW(fName);
-
- if ( !_osd_print ( (Standard_PCharacter)pName.ToCString (),
- (const wchar_t*)fNameW.ToExtString () ) )
-
- _osd_wnt_set_error ( myError, OSD_WFile );
-
-} // end OSD_File :: Print
+Standard_Size OSD_File::Size()
+{
+ TEST_RAISE("Size");
+#if (_WIN32_WINNT >= 0x0500)
+ LARGE_INTEGER aSize;
+ aSize.QuadPart = 0;
+ if (GetFileSizeEx (myFileHandle, &aSize) == 0)
+ {
+ _osd_wnt_set_error (myError, OSD_WFile);
+ }
+ return (Standard_Size)aSize.QuadPart;
+#else
+ DWORD aSize = GetFileSize (myFileHandle, NULL);
+ if (aSize == INVALID_FILE_SIZE)
+ {
+ _osd_wnt_set_error (myError, OSD_WFile);
+ }
+ return aSize;
+#endif
+}
// --------------------------------------------------------------------------
// Test if a file is open
#define __leave return retVal
#endif
+#ifndef OCCT_UWP
PSECURITY_DESCRIPTOR __fastcall _osd_wnt_protection_to_sd (
- const OSD_Protection& prot, BOOL fDir, wchar_t* fName
+ const OSD_Protection& prot, BOOL fDir, const wchar_t* fName
) {
int i, j;
DWORD dwAccessOwner;
DWORD dwAccessWorld;
DWORD dwAccessAdminDir;
- DWORD dwAccessGroupDir;
+// DWORD dwAccessGroupDir;
DWORD dwAccessOwnerDir;
- DWORD dwAccessWorldDir;
+// DWORD dwAccessWorldDir;
DWORD dwACLsize = sizeof ( ACL );
DWORD dwIndex = 0;
PTOKEN_OWNER pTkOwner = NULL;
dwAccessWorld = _get_access_mask ( prot.World () );
dwAccessAdminDir = _get_dir_access_mask ( prot.System () );
- dwAccessGroupDir = _get_dir_access_mask ( prot.Group () );
+// dwAccessGroupDir = _get_dir_access_mask ( prot.Group () );
dwAccessOwnerDir = _get_dir_access_mask ( prot.User () );
- dwAccessWorldDir = _get_dir_access_mask ( prot.World () );
+// dwAccessWorldDir = _get_dir_access_mask ( prot.World () );
if ( dwAccessGroup != 0 ) {
return retVal;
} // end _osd_wnt_protection_to_sd */
+#endif
#if defined(__CYGWIN32__) || defined(__MINGW32__)
#undef __try
static void __fastcall _test_raise ( HANDLE hFile, Standard_CString str ) {
- Standard_Character buff[ 64 ];
+ if (hFile == INVALID_HANDLE_VALUE) {
+ TCollection_AsciiString buff = "OSD_File :: ";
+ buff += str;
+ buff += " (): wrong access";
- if (hFile == INVALID_HANDLE_VALUE) {
-
- strcpy ( buff, "OSD_File :: " );
- strcat ( buff, str );
- strcat ( buff, " (): wrong access" );
-
- Standard_ProgramError :: Raise ( buff );
-
- } // end if
+ Standard_ProgramError::Raise(buff.ToCString());
+ } // end if
} // end _test_raise
-// 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
-
-static DWORDLONG __fastcall _get_line ( Standard_PCharacter& buffer, DWORD dwBuffSize ) {
+// Returns number of bytes in the string (including end \n, but excluding \r);
+//
+static Standard_Integer __fastcall _get_line (Standard_PCharacter& buffer, DWORD dwBuffSize, LONG& theSeekPos)
+{
- DWORDLONG retVal;
Standard_PCharacter ptr;
buffer[ dwBuffSize ] = 0;
while ( *ptr != 0 ) {
- if ( *ptr == '\n' ) {
-
- ptr++ ; // jump newline char.
- *ptr = 0 ;
- retVal = ptr - buffer - dwBuffSize;
- retVal &= 0x0000000FFFFFFFF;// import 32-bit to 64-bit
-#ifdef VAC
- retVal = (DWORDLONG) ( (unsigned __int64) retVal | (((unsigned __int64) ptr) << 32) );
-#else
- retVal |= ( ( ( DWORDLONG )( DWORD )ptr ) << 32 );
-#endif
- return retVal;
-
- } else if ( *ptr == '\r' && ptr[ 1 ] == '\n' ) {
-
- *(ptr++) = '\n' ; // Substitue carriage return by newline.
- *ptr = 0 ;
- retVal = ptr + 1 - buffer - dwBuffSize;
- retVal &= 0x0000000FFFFFFFF;// import 32-bit to 64-bit
-#ifdef VAC
- retVal = (DWORDLONG) ( (unsigned __int64) retVal | (((unsigned __int64) ptr) << 32) );
-#else
- retVal |= ( ( ( DWORDLONG )( DWORD )ptr ) << 32 );
-#endif
- return retVal;
-
- } else if ( *ptr == '\r' && ptr[ 1 ] == 0 ) {
+ if ( *ptr == '\n' )
+ {
+ ptr++ ; // jump newline char.
+ *ptr = 0 ;
+ theSeekPos = (LONG)(ptr - buffer - dwBuffSize);
+ return (Standard_Integer)(ptr - buffer);
+ }
+ else if ( *ptr == '\r' && ptr[ 1 ] == '\n' )
+ {
+ *(ptr++) = '\n' ; // Substitue carriage return by newline.
+ *ptr = 0 ;
+ theSeekPos = (LONG)(ptr + 1 - buffer - dwBuffSize);
+ return (Standard_Integer)(ptr - buffer);
+ }
+ else if ( *ptr == '\r' && ptr[ 1 ] == 0 ) {
*ptr = '\n' ; // Substitue carriage return by newline
-
-#ifdef VAC
- return (DWORDLONG) (__int64) (-1);
-#else
- return 0xFFFFFFFFFFFFFFFF;
-#endif
+ return -1;
}
++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;
-
+ theSeekPos = 0;
+ return dwBuffSize;
} // end _get_line
+#ifndef OCCT_UWP
static int __fastcall _get_buffer (
HANDLE hChannel,
Standard_PCharacter& buffer,
return retVal;
} // end _get_dir_access_mask
-
+#endif
static HANDLE __fastcall _open_file (
Standard_CString fName,
OSD_OpenMode oMode,
// make wide character string from UTF-8
TCollection_ExtendedString fNameW(fName, Standard_True);
+#ifndef OCCT_UWP
retVal = CreateFileW (
- (const wchar_t*) fNameW.ToExtString(), dwDesiredAccess,
+ fNameW.ToWideString(), dwDesiredAccess,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL, dwCreationDistribution, FILE_ATTRIBUTE_NORMAL, NULL
);
-
+#else
+ CREATEFILE2_EXTENDED_PARAMETERS pCreateExParams = {};
+ pCreateExParams.dwSize = sizeof(CREATEFILE2_EXTENDED_PARAMETERS);
+ pCreateExParams.dwFileAttributes = FILE_ATTRIBUTE_NORMAL;
+ pCreateExParams.lpSecurityAttributes = NULL;
+ pCreateExParams.hTemplateFile = NULL;
+ retVal = CreateFile2 (
+ fNameW.ToWideString(), dwDesiredAccess,
+ FILE_SHARE_READ | FILE_SHARE_WRITE,
+ dwCreationDistribution, &pCreateExParams
+ );
+#endif
if ( retVal == INVALID_HANDLE_VALUE &&
dwOptions == OPEN_APPEND &&
GetLastError () == ERROR_FILE_NOT_FOUND
dwCreationDistribution = CREATE_ALWAYS;
-
+#ifndef OCCT_UWP
retVal = CreateFileW (
- (const wchar_t*) fNameW.ToExtString(), dwDesiredAccess,
+ fNameW.ToWideString(), dwDesiredAccess,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL, dwCreationDistribution, FILE_ATTRIBUTE_NORMAL, NULL
);
+#else
+ CREATEFILE2_EXTENDED_PARAMETERS pCreateExParams2 = {};
+ pCreateExParams2.dwSize = sizeof(CREATEFILE2_EXTENDED_PARAMETERS);
+ pCreateExParams2.dwFileAttributes = FILE_ATTRIBUTE_NORMAL;
+ pCreateExParams2.lpSecurityAttributes = NULL;
+ pCreateExParams2.hTemplateFile = NULL;
+ retVal = CreateFile2(
+ fNameW.ToWideString(), dwDesiredAccess,
+ FILE_SHARE_READ | FILE_SHARE_WRITE,
+ dwCreationDistribution, &pCreateExParams2
+ );
+#endif
*fNew = TRUE;
) {
Standard_Integer retVal = 0;
- DWORD dwType;
int fileType;
fileType = (fileHandle == INVALID_HANDLE_VALUE ?
{
// make wide character string from UTF-8
TCollection_ExtendedString fNameW(fName, Standard_True);
- dwType = GetFileAttributesW ( (const wchar_t*) fNameW.ToExtString() );
- if ( dwType != 0xFFFFFFFF )
- retVal = dwType & FILE_ATTRIBUTE_DIRECTORY ? FLAG_DIRECTORY : FLAG_FILE;
+ WIN32_FILE_ATTRIBUTE_DATA aFileInfo;
+ if (GetFileAttributesExW (fNameW.ToWideString(), GetFileExInfoStandard, &aFileInfo))
+
+ retVal = aFileInfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ? FLAG_DIRECTORY : FLAG_FILE;
else
#define __leave return retVal
#endif
+#ifndef OCCT_UWP
+// None of the existing security APIs are supported in a UWP applications
BOOL __fastcall _osd_wnt_sd_to_protection (
PSECURITY_DESCRIPTOR pSD, OSD_Protection& prot, BOOL fDir
) {
return retVal;
} // end _osd_wnt_sd_to_protection
+#endif
#if defined(__CYGWIN32__) || defined(__MINGW32__)
#undef __try
#undef __finally
#undef __leave
#endif
-
+#ifndef OCCT_UWP
static OSD_SingleProtection __fastcall _get_protection ( DWORD mask ) {
OSD_SingleProtection retVal;
return retVal;
} // end _get_protection_dir
-
-#if defined(__CYGWIN32__) || defined(__MINGW32__)
-#define __try
-#define __finally
-#define __leave return fOK
-#endif
-
-BOOL __fastcall _osd_print (const Standard_PCharacter pName, const wchar_t* fName ) {
-
- BOOL fOK, fJob;
- HANDLE hPrinter = NULL;
- BYTE jobInfo[ MAX_PATH + sizeof ( DWORD ) ];
- DWORD dwNeeded, dwCode = 0;
-
- fOK = fJob = FALSE;
-
- __try {
-
- if ( !OpenPrinter ( Standard_PCharacter(pName), &hPrinter, NULL ) ) {
-
- hPrinter = NULL;
- __leave;
-
- } // end if
-
- if ( !AddJobW (
- hPrinter, 1, jobInfo, MAX_PATH + sizeof ( DWORD ), &dwNeeded
- )
- ) __leave;
-
- fJob = TRUE;
-
- if ( !CopyFileW (
- fName, (LPWSTR) ( ( ADDJOB_INFO_1* )jobInfo ) -> Path, FALSE
- )
- ) __leave;
-
- if ( !ScheduleJob (
- hPrinter, ( ( ADDJOB_INFO_1* )jobInfo ) -> JobId
- )
- ) __leave;
-
- fOK = TRUE;
-
- } // end __try
-
- __finally {
-
- if ( !fOK ) {
-
- BYTE info[ 1024 ];
- DWORD dwBytesNeeded;
-
- dwCode = GetLastError ();
-
- if ( fJob && hPrinter != NULL ) {
-
- GetJob (
- hPrinter, ( ( ADDJOB_INFO_1* )jobInfo ) -> JobId, 1,
- info, 1024, &dwBytesNeeded
- );
-
- if ( fJob ) SetJob (
- hPrinter,
- ( ( ADDJOB_INFO_1* )jobInfo ) -> JobId,
- 1, info, JOB_CONTROL_CANCEL
- );
-
- } // end if
-
- } // end if
-
- if ( hPrinter != NULL ) ClosePrinter ( hPrinter );
-
- } // end __finally
-
-#ifdef VAC
-leave: ; // added for VisualAge
-#endif
-
- if ( !fOK ) SetLastError ( dwCode );
-
- return fOK;
-
-} // end _osd_print
-
-#if defined(__CYGWIN32__) || defined(__MINGW32__)
-#undef __try
-#undef __finally
-#undef __leave
#endif
Standard_Boolean OSD_File::IsReadable()
#endif /* _WIN32 */
+// ---------------------------------------------------------------------
+// Destructs a file object (unlocks and closes file if it is open)
+// ---------------------------------------------------------------------
+
+OSD_File::~OSD_File()
+{
+ if (IsOpen())
+ {
+ if (IsLocked())
+ UnLock();
+ Close();
+ }
+}
// ---------------------------------------------------------------------
// Read lines in a file while it is increasing.
-