0028110: Configuration - specify Unicode charset instead of multibyte in project...
[occt.git] / src / OSD / OSD_File.cxx
old mode 100755 (executable)
new mode 100644 (file)
index 98b551d..61e9071
@@ -1,21 +1,33 @@
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
+// Copyright (c) 1998-1999 Matra Datavision
+// Copyright (c) 1999-2014 OPEN CASCADE SAS
+//
+// This file is part of Open CASCADE Technology software library.
+//
+// This library is free software; you can redistribute it and/or modify it under
+// the terms of the GNU Lesser General Public License version 2.1 as published
+// by the Free Software Foundation, with special exception defined in the file
+// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
+// distribution for complete text of the license and disclaimer of any warranty.
+//
+// Alternatively, this file may be used under the terms of Open CASCADE
+// commercial license or contractual agreement.
 
 //------------------------------------------------------------------------
 //                    UNIX Part
 //------------------------------------------------------------------------
 
+#ifndef _WIN32
 
-#ifndef WNT
 
-#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;
 
@@ -26,22 +38,11 @@ const OSD_WhoAmI Iam = OSD_WFile;
 #endif
 
 #include <errno.h>
-
-#ifdef HAVE_UNISTD_H
-# include <unistd.h>
-#endif
-
 #include <stdlib.h>
 #include <stdio.h>
 #include <fcntl.h>
-
-#ifdef HAVE_SYS_TYPES_H
-# include <sys/types.h>
-#endif
-
-#ifdef HAVE_SYS_STAT_H
-# include <sys/stat.h>
-#endif
+#include <unistd.h>
+#include <sys/stat.h>
 
 #define NEWLINE '\10';
 
@@ -49,29 +50,34 @@ const OSD_WhoAmI Iam = OSD_WFile;
 // 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
@@ -95,27 +101,27 @@ void OSD_File::Build(const OSD_OpenMode Mode,
 
  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 */
@@ -148,23 +154,21 @@ void  OSD_File::Append(const OSD_OpenMode Mode,
   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;
  }
 
@@ -173,9 +177,9 @@ void  OSD_File::Append(const OSD_OpenMode Mode,
  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 */
 
@@ -204,30 +208,28 @@ void  OSD_File::Open(const OSD_OpenMode Mode,
   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 */
 
@@ -238,38 +240,35 @@ void  OSD_File::Open(const OSD_OpenMode Mode,
 
 // ---------------------------------------------------------------------
 // ---------------------------------------------------------------------
-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 summy file
result.myFileChannel = dummy - 1;         // This is file channel of "fic" +1
+ dummy = open("dummy", O_RDWR | O_CREAT);  // Open a dummy file
+ 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;
 }
  
 
@@ -301,7 +300,7 @@ void  OSD_File::Read(TCollection_AsciiString& Buffer,
  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
 
@@ -354,7 +353,7 @@ void OSD_File::ReadLine(TCollection_AsciiString& Buffer,
     }
   }
   else   {
-    NByteRead = strlen(abuffer);
+    NByteRead = (Standard_Integer)strlen(abuffer);
     Buffer.SetValue(1,abuffer);  // Copy transfert to Buffer
     Buffer.Trunc(NByteRead);
   }
@@ -384,7 +383,7 @@ return OSD_UNKNOWN   ;
 // -------------------------------------------------------------------------- 
 // 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)
 {
@@ -409,12 +408,12 @@ void  OSD_File::Read(      Standard_Address&  Buffer,
   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;
   }
 }
 
@@ -443,7 +442,7 @@ void  OSD_File::Write(const TCollection_AsciiString &Buffer,
 
  writebuf = Buffer.ToCString();
 
- status = write( (int)myFileChannel, writebuf, Nbyte);
+ status = write (myFileChannel, writebuf, Nbyte);
 
  if ( status == -1) myError.SetValue (errno, Iam, "Write");
  else
@@ -468,7 +467,7 @@ void  OSD_File::Write(const Standard_Address   Buffer,
   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
@@ -483,7 +482,7 @@ void  OSD_File::Write(const Standard_Address   Buffer,
 
 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");
@@ -492,19 +491,19 @@ void  OSD_File::Seek(const Standard_Integer Offset,
 
  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");
 }
 
@@ -523,13 +522,14 @@ void  OSD_File::Close(){
 
  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;
 }
@@ -584,7 +584,7 @@ int status;
             return;
  }
 
- if (fstat((int)myFileChannel, &buf) == -1) {
+ if (fstat (myFileChannel, &buf) == -1) {
   myError.SetValue (errno, Iam, "SetLock");
   return;
  }
@@ -612,12 +612,12 @@ int status;
  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);
@@ -636,7 +636,7 @@ int status;
   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
@@ -671,18 +671,18 @@ int status;
  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
@@ -696,9 +696,6 @@ int status;
 // 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);
 }
 
@@ -709,7 +706,7 @@ OSD_LockType  OSD_File::GetLock(){
 // Return size of a file
 // -------------------------------------------------------------------------- 
 
-Standard_Integer  OSD_File::Size(){
+Standard_Size  OSD_File::Size(){
  struct stat buffer;
  int status;
 
@@ -721,56 +718,22 @@ Standard_Integer  OSD_File::Size(){
  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;
 }
 
-
-// -------------------------------------------------------------------------- 
-// 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); 
 }
 
@@ -810,7 +773,21 @@ Standard_Boolean OSD_File::IsExecutable()
     return Standard_True;
 }
 
-#else //WNT
+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 */
 
 //------------------------------------------------------------------------
 //-------------------  Windows NT sources for OSD_File -------------------
@@ -820,7 +797,6 @@ Standard_Boolean OSD_File::IsExecutable()
 
 #include <OSD_File.hxx>
 #include <OSD_Protection.hxx>
-#include <OSD_Printer.hxx>
 #include <Standard_ProgramError.hxx>
 
 #include <OSD_WNT_1.hxx>
@@ -828,38 +804,33 @@ Standard_Boolean OSD_File::IsExecutable()
 #include <stdio.h>
 #include <io.h>
 #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 TEST_RAISE( arg ) _test_raise (  myFileChannel, ( arg )  )
+#define TEST_RAISE( arg ) _test_raise (  myFileHandle, ( arg )  )
 
 #define OPEN_NEW    0
 #define OPEN_OLD    1
 #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, char* = 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, Standard_CString );
-
-static void      __fastcall _test_raise ( Standard_Integer, Standard_CString );
-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);
+#endif
+static void      __fastcall _test_raise ( HANDLE, Standard_CString );
+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 );
@@ -869,40 +840,85 @@ static OSD_SingleProtection __fastcall _get_protection_dir ( 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
 // ---------------------------------------------------------------------
 
-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 )
 
+// ---------------------------------------------------------------------
+// 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;
 
@@ -910,26 +926,29 @@ void OSD_File :: Build (
    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(  "OSD_File :: Build (): incorrect call - file already opened"  );
 
  myMode = Mode;
  myPath.SystemName ( fName );
 
  if (  fName.IsEmpty ()  )
 
-  RAISE(  TEXT( "OSD_File :: Build (): incorrent call - no filename given" )  );
+  RAISE(  "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 );
 
  else {
-
+#ifndef OCCT_UWP
   SetProtection ( Protect );
+#else
+  (void)Protect;
+#endif
   myIO |= FLAG_FILE;
 
  }  // end else
@@ -942,33 +961,32 @@ void OSD_File :: Build (
 // Open a file
 // ---------------------------------------------------------------------
 
-void OSD_File :: Open (
-                  const OSD_OpenMode Mode, const OSD_Protection& Protect
-                 ) {
+void OSD_File :: Open (const OSD_OpenMode Mode, const OSD_Protection& /*Protect*/)
+{
 
  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(  "OSD_File :: Open (): incorrect call - file already opened"  );
 
  myMode = Mode;
  myPath.SystemName ( fName );
 
  if (  fName.IsEmpty ()  )
 
-  RAISE(  TEXT( "OSD_File :: Open (): incorrent call - no filename given" )  );
+  RAISE(  "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
 
@@ -976,27 +994,25 @@ void OSD_File :: Open (
 // 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;
 
- if (  ( HANDLE )myFileChannel != INVALID_HANDLE_VALUE  )
+ if (myFileHandle != INVALID_HANDLE_VALUE)
 
-  RAISE(  TEXT( "OSD_File :: Append (): incorrect call - file already opened" )  );
+  RAISE(  "OSD_File :: Append (): incorrect call - file already opened"  );
 
  myMode = Mode;
  myPath.SystemName ( fName );
 
  if (  fName.IsEmpty ()  )
 
-  RAISE(  TEXT( "OSD_File :: Append (): incorrent call - no filename given" )  );
+  RAISE(  "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 );
 
@@ -1004,12 +1020,15 @@ void OSD_File :: Append (
 
   if ( !fNew ) {
 
-   myIO |= _get_file_type (  fName.ToCString (), myFileChannel  );
+   myIO |= _get_file_type (  fName.ToCString (), myFileHandle  );
    Seek ( 0, OSD_FromEnd );
 
   } else {
-  
-   SetProtection ( Protect );
+#ifndef OCCT_UWP
+    SetProtection ( Protect );
+#else
+    (void)Protect;
+#endif
    myIO |= FLAG_FILE;
   
   }  // end else
@@ -1027,25 +1046,26 @@ void OSD_File :: Read (
                  ) {
 
  if ( OSD_File::KindOfFile ( ) == OSD_DIRECTORY ) { 
+#ifdef OCCT_DEBUG
    cout << " OSD_File::Read : it is a directory " << endl;
+#endif
    return ;
 //   Standard_ProgramError::Raise("OSD_File::Read : it is a directory");
  }
                                         
  Standard_Integer NbyteRead;
- Standard_Address buff;
 
- TEST_RAISE(  TEXT( "Read" )  );
+ 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
 
@@ -1055,14 +1075,10 @@ void OSD_File :: Read (
 
 }  // 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
@@ -1072,24 +1088,22 @@ void OSD_File :: ReadLine (
                   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");
  }
                                         
- TEST_RAISE(  TEXT( "ReadLine" )  );              
+ TEST_RAISE(  "ReadLine"  );              
 
  if (  myIO & FLAG_PIPE && !( myIO & FLAG_READ_PIPE )  )
 
-  RAISE(  TEXT( "OSD_File :: ReadLine (): attempt to read from write only pipe" )  );
+  RAISE(  "OSD_File :: ReadLine (): attempt to read from write only pipe"  );
 
                                         // +----> leave space for end-of-string
                                         // |       plus <CR><LF> sequence      
@@ -1100,10 +1114,7 @@ void OSD_File :: ReadLine (
 
  if ( myIO & FLAG_FILE ) {
  
-  if (  !ReadFile (
-          ( HANDLE )myFileChannel, 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 ();
@@ -1117,53 +1128,41 @@ void OSD_File :: ReadLine (
    
   } 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 (  !ReadFile (
-            ( HANDLE )myFileChannel, ppeekChar, 1, &dwDummy, NULL
-           )
-    ) {
+   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 (  ( HANDLE )myFileChannel, -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 (  ( HANDLE )myFileChannel, ( 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 ) {
-
-  dwBytesRead = ( DWORD )_get_buffer (
-                          ( HANDLE )myFileChannel, cBuffer, ( DWORD )NByte,
-                          TRUE, myIO & FLAG_SOCKET
-                         );
+#ifndef OCCT_UWP
+  dwBytesRead = (DWORD)_get_buffer (myFileHandle, cBuffer, 
+                                    (DWORD)NByte, TRUE, myIO & FLAG_SOCKET);
 
   if (  ( int )dwBytesRead == -1  ) { // an error occured
 
@@ -1179,23 +1178,13 @@ void OSD_File :: ReadLine (
 
   } 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 (
-               ( 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 );
@@ -1209,221 +1198,39 @@ void OSD_File :: ReadLine (
 
      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.
 
    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
-   
- } else
-
-  RAISE(  TEXT( "OSD_File :: ReadLine (): incorrect call - file is a directory" )  );
-
- if (  !Failed () && !IsAtEnd ()  )
-
-  Buffer = cBuffer;
-
- delete [] (Standard_PCharacter)cBuffer;
-
-}  // 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" )  );
+  RAISE(  "OSD_File :: ReadLine (): incorrect call - file is a directory"  );
 
  if (  !Failed () && !IsAtEnd ()  )
 
   Buffer = cBuffer;
 
- delete [] cBuffer;
+ delete [] (Standard_PCharacter)cBuffer;
 
 }  // end OSD_File :: ReadLine
 
-#endif // PRO13471
-
 // -------------------------------------------------------------------------- 
 // Read content of a file
 // -------------------------------------------------------------------------- 
 
 void OSD_File :: Read (
-                  Standard_Address& Buffer,
+                  const Standard_Address Buffer,
                   const Standard_Integer Nbyte, Standard_Integer& Readbyte
                  ) {
 
@@ -1433,16 +1240,13 @@ void OSD_File :: Read (
    Standard_ProgramError::Raise("OSD_File::Read : it is a directory");
  }
                                         
- TEST_RAISE(  TEXT( "Read" )  );
+ TEST_RAISE(  "Read"  );
 
  if (  myIO & FLAG_PIPE && !( myIO & FLAG_READ_PIPE )  )
 
-  RAISE(  TEXT( "OSD_File :: Read (): attempt to read from write only pipe" )  );
+  RAISE(  "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;
@@ -1479,16 +1283,14 @@ void OSD_File :: Write (
 
  DWORD dwBytesWritten;
 
- TEST_RAISE(  TEXT( "Write" )  );
+ TEST_RAISE(  "Write"  );
 
  if ( myIO & FLAG_PIPE && myIO & FLAG_READ_PIPE )
 
-  RAISE(  TEXT( "OSD_File :: Write (): attempt to write to read only pipe" )  );
+  RAISE(  "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 );
 
@@ -1498,9 +1300,9 @@ void OSD_File :: Seek (
                   const Standard_Integer Offset, const OSD_FromWhere Whence
                  ) {
 
- DWORD dwMoveMethod;
+ DWORD dwMoveMethod = 0;
 
- TEST_RAISE(  TEXT( "Seek" )  );
+ TEST_RAISE(  "Seek"  );
 
  if ( myIO & FLAG_FILE || myIO & FLAG_DIRECTORY ) {
 
@@ -1526,14 +1328,14 @@ void OSD_File :: Seek (
 
    default:
 
-    RAISE(  TEXT( "OSD_File :: Seek (): invalid parameter" )  );
+    RAISE(  "OSD_File :: Seek (): invalid parameter"  );
   
   }  // end switch
+  LARGE_INTEGER aDistanceToMove, aNewFilePointer;
+  aNewFilePointer.QuadPart = 0;
+  aDistanceToMove.QuadPart = Offset;
 
-  if (  SetFilePointer (
-         ( HANDLE )myFileChannel, ( LONG )Offset, NULL, dwMoveMethod
-        ) == 0xFFFFFFFF
-  )
+  if (!SetFilePointerEx(myFileHandle, aDistanceToMove, &aNewFilePointer, dwMoveMethod))
 
    _osd_wnt_set_error ( myError, OSD_WFile );
   
@@ -1549,11 +1351,11 @@ void OSD_File :: Seek (
 
 void OSD_File :: Close () {
 
- TEST_RAISE(  TEXT( "Close" )  );
+ TEST_RAISE(  "Close"  );
 
- CloseHandle (  ( HANDLE )myFileChannel  );
+ CloseHandle (myFileHandle);
 
- myFileChannel = ( Standard_Integer )INVALID_HANDLE_VALUE;
+ myFileHandle = INVALID_HANDLE_VALUE;
  myIO          = 0;
 
 }  // end OSD_File :: Close
@@ -1564,7 +1366,7 @@ void OSD_File :: Close () {
 
 Standard_Boolean OSD_File :: IsAtEnd () {
 
- TEST_RAISE(  TEXT( "IsAtEnd" )  );
+ TEST_RAISE(  "IsAtEnd"  );
 
  if (myIO & FLAG_EOF)
    return Standard_True ;
@@ -1577,7 +1379,7 @@ OSD_KindFile OSD_File :: KindOfFile () const {
  OSD_KindFile     retVal;
  Standard_Integer flags;
 
- if (  ( HANDLE )myFileChannel == INVALID_HANDLE_VALUE  ) {
+ if (myFileHandle == INVALID_HANDLE_VALUE) {
 
   TCollection_AsciiString fName;
 
@@ -1585,11 +1387,9 @@ OSD_KindFile OSD_File :: KindOfFile () const {
 
   if (  fName.IsEmpty ()  )
 
-   RAISE(  TEXT( "OSD_File :: KindOfFile (): incorrent call - no filename given" )  );
+   RAISE(  "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
 
@@ -1624,74 +1424,41 @@ OSD_KindFile OSD_File :: KindOfFile () const {
  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,
-                   TEXT( "SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment" )
+                   L"SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment"
                  },
                  { HKEY_USERS,
-                   TEXT( ".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
   ) {
@@ -1699,25 +1466,25 @@ OSD_File OSD_File :: BuildTemporary () {
    DWORD dwType;
    DWORD dwSize = 0;
 
-   if (  RegQueryValueEx (
-          hKey, TEXT( "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, TEXT( "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;
@@ -1731,20 +1498,24 @@ OSD_File OSD_File :: BuildTemporary () {
   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, TEXT( "./" )  );
- 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__)
@@ -1758,7 +1529,7 @@ void OSD_File :: SetLock ( const OSD_LockType Lock ) {
  DWORD      dwFlags;
  OVERLAPPED ovlp;
 
- TEST_RAISE(  TEXT( "SetLock" )  );
+ TEST_RAISE(  "SetLock"  );
  
  ZeroMemory (  &ovlp, sizeof ( OVERLAPPED )  );
 
@@ -1777,10 +1548,9 @@ void OSD_File :: SetLock ( const OSD_LockType Lock ) {
 
    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;
@@ -1806,15 +1576,18 @@ leave: ;         // added for VisualAge
 
 void OSD_File :: UnLock () {
 
- TEST_RAISE(  TEXT( "Unlock" )  );
+ TEST_RAISE(  "Unlock"  );
 
  if ( ImperativeFlag ) {
  
-  if (  !UnlockFile (
-          ( HANDLE )myFileChannel, 0, 0, Size (), 0
-         )
-  )
-   
+  LARGE_INTEGER aSize;
+  aSize.QuadPart = Size();
+
+  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;
@@ -1831,7 +1604,7 @@ OSD_LockType OSD_File :: GetLock () {
 
 Standard_Boolean OSD_File :: IsLocked () {
 
- TEST_RAISE(  TEXT( "IsLocked" )  );
+ TEST_RAISE(  "IsLocked"  );
 
  return ImperativeFlag;
 
@@ -1842,44 +1615,26 @@ Standard_Boolean OSD_File :: IsLocked () {
 // Return size of a file
 // -------------------------------------------------------------------------- 
 
-Standard_Integer OSD_File :: Size () {
-
- Standard_Integer retVal;
-
- TEST_RAISE(  TEXT( "Size" )  );
-
- retVal = ( Standard_Integer )GetFileSize (
-                               ( HANDLE )myFileChannel, NULL
-                              );
-
- if (  retVal == ( Standard_Integer )0xFFFFFFFF  )
-
-  _osd_wnt_set_error ( myError, OSD_WFile );
-
- return retVal;
-
-}  // end OSD_File :: Size
-
-// -------------------------------------------------------------------------- 
-// Print contains of a file
-// -------------------------------------------------------------------------- 
-
-void OSD_File :: Print ( const OSD_Printer& WhichPrinter ) {
-
- if (  ( HANDLE )myFileChannel != INVALID_HANDLE_VALUE  )
-
-  RAISE(  TEXT( "OSD_File :: Print (): incorrect call - file opened" )  );
-
- TCollection_AsciiString pName, fName;
-
- WhichPrinter.Name ( pName );
- myPath.SystemName ( fName );
-
- if (   !_osd_print ( (Standard_PCharacter)pName.ToCString (), fName.ToCString ()  )   )
-
-  _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
@@ -1887,7 +1642,7 @@ void OSD_File :: Print ( const OSD_Printer& WhichPrinter ) {
 
 Standard_Boolean OSD_File :: IsOpen () const {
 
- return ( HANDLE )myFileChannel != INVALID_HANDLE_VALUE;
+ return myFileHandle != INVALID_HANDLE_VALUE;
 
 }  // end OSD_File :: IsOpen
 
@@ -1897,8 +1652,9 @@ Standard_Boolean OSD_File :: IsOpen () const {
 #define __leave return retVal
 #endif
 
+#ifndef OCCT_UWP
 PSECURITY_DESCRIPTOR __fastcall _osd_wnt_protection_to_sd (
-                                 const OSD_Protection& prot, BOOL fDir, char* fName
+                                 const OSD_Protection& prot, BOOL fDir, const wchar_t* fName
                                 ) {
 
  int                  i, j;
@@ -1914,15 +1670,15 @@ PSECURITY_DESCRIPTOR __fastcall _osd_wnt_protection_to_sd (
  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;
  PTOKEN_GROUPS        pTkGroups       = NULL;
  PTOKEN_PRIMARY_GROUP pTkPrimaryGroup = NULL;
- PSECURITY_DESCRIPTOR retVal;
+ PSECURITY_DESCRIPTOR retVal = NULL;
  PSECURITY_DESCRIPTOR pfSD = NULL;
  BOOL                 fDummy;
  PFILE_ACE            pFileACE;
@@ -1982,9 +1738,9 @@ retry:
   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  ) {
                                              
@@ -2155,6 +1911,7 @@ leave: ;     // added for VisualAge
  return retVal;
  
 }  // end _osd_wnt_protection_to_sd */
+#endif
 
 #if defined(__CYGWIN32__) || defined(__MINGW32__)
 #undef __try
@@ -2162,30 +1919,23 @@ leave: ;     // added for VisualAge
 #undef __leave
 #endif
 
-static void __fastcall _test_raise ( Standard_Integer hFile, Standard_CString str ) {
-
- Standard_Character buff[ 64 ];
+static void __fastcall _test_raise ( HANDLE hFile, Standard_CString str ) {
 
- if (  ( HANDLE )hFile == INVALID_HANDLE_VALUE  ) {
-  _tcscpy (  buff, TEXT( "OSD_File :: " )  );
-  _tcscat (  buff, str );
-  _tcscat (  buff, TEXT( " (): wrong access" )  );
+  if (hFile == INVALID_HANDLE_VALUE) {
+    TCollection_AsciiString buff = "OSD_File :: ";
+    buff += str;
+    buff += " (): wrong access";
 
-  Standard_ProgramError :: Raise ( buff );
- }  // end if
+    Standard_ProgramError::Raise(buff.ToCString());
+  }  // end if
 
 }  // 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
-
-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;
@@ -2193,127 +1943,33 @@ static DWORDLONG __fastcall _get_line ( Standard_PCharacter& buffer, DWORD dwBuf
 
  while ( *ptr != 0 ) {
  
-  if (  *ptr == TEXT( '\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 == TEXT( '\r' ) && ptr[ 1 ] == TEXT( '\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 == TEXT( '\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
 
-#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
-
+#ifndef OCCT_UWP
 static int __fastcall _get_buffer (
                         HANDLE hChannel,
                         Standard_PCharacter& buffer, 
@@ -2370,7 +2026,7 @@ static int __fastcall _get_buffer (
 
 static DWORD __fastcall _get_access_mask ( OSD_SingleProtection prt ) {
 
- DWORD retVal;
+ DWORD retVal = 0;
 
  switch ( prt ) {
  
@@ -2472,7 +2128,7 @@ static DWORD __fastcall _get_access_mask ( OSD_SingleProtection prt ) {
 
   default:
 
-   RAISE(  TEXT( "_get_access_mask (): incorrect parameter" )  );
+   RAISE(  "_get_access_mask (): incorrect parameter"  );
  
  }  // end switch
 
@@ -2482,7 +2138,7 @@ static DWORD __fastcall _get_access_mask ( OSD_SingleProtection prt ) {
 
 static DWORD __fastcall _get_dir_access_mask ( OSD_SingleProtection prt ) {
 
- DWORD retVal;
+ DWORD retVal = 0;
 
  switch ( prt ) {
  
@@ -2584,14 +2240,14 @@ static DWORD __fastcall _get_dir_access_mask ( OSD_SingleProtection prt ) {
 
   default:
 
-   RAISE(  TEXT( "_get_dir_access_mask (): incorrect parameter" )  );
+   RAISE(  "_get_dir_access_mask (): incorrect parameter"  );
  
  }  // end switch
 
  return retVal;
 
 }  // end _get_dir_access_mask
-
+#endif
 static HANDLE __fastcall _open_file (
                           Standard_CString fName,
                           OSD_OpenMode oMode,
@@ -2599,7 +2255,7 @@ static HANDLE __fastcall _open_file (
                          ) {
 
  HANDLE retVal = INVALID_HANDLE_VALUE;
- DWORD  dwDesiredAccess;
+ DWORD  dwDesiredAccess = 0;
  DWORD  dwCreationDistribution;
 
  switch ( oMode ) {
@@ -2624,18 +2280,32 @@ static HANDLE __fastcall _open_file (
 
   default:
 
-   RAISE(  TEXT( "_open_file (): incorrect parameter" )  );
+   RAISE(  "_open_file (): incorrect parameter"  );
   
  }  // end switch
 
  dwCreationDistribution = ( dwOptions != OPEN_NEW ) ? OPEN_EXISTING : CREATE_ALWAYS;
 
- retVal = CreateFile (
-           fName, dwDesiredAccess,
+ // make wide character string from UTF-8
+ TCollection_ExtendedString fNameW(fName, Standard_True);
+#ifndef OCCT_UWP
+ retVal = CreateFileW (
+           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
@@ -2643,12 +2313,24 @@ static HANDLE __fastcall _open_file (
 
  
   dwCreationDistribution = CREATE_ALWAYS;
-  
-  retVal = CreateFile (
-            fName, dwDesiredAccess,
+#ifndef OCCT_UWP
+  retVal = CreateFileW (
+            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;
 
@@ -2659,16 +2341,14 @@ static HANDLE __fastcall _open_file (
 }  // end _open_file
 
 Standard_Integer __fastcall _get_file_type (
-                             Standard_CString fName, Standard_Integer fileHandle
+                             Standard_CString fName, HANDLE fileHandle
                             ) {
 
- Standard_Integer retVal;
- DWORD            dwType;
+ Standard_Integer retVal = 0;
  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 ) {
  
@@ -2679,15 +2359,19 @@ Standard_Integer __fastcall _get_file_type (
   break;
 
   case FILE_TYPE_DISK:
+  {
+   // make wide character string from UTF-8
+   TCollection_ExtendedString fNameW(fName, Standard_True);
 
-   if (   (  dwType = GetFileAttributes ( fName )  ) != 0xFFFFFFFF  )
+   WIN32_FILE_ATTRIBUTE_DATA aFileInfo;
+   if (GetFileAttributesExW (fNameW.ToWideString(), GetFileExInfoStandard, &aFileInfo))
 
-    retVal =  dwType & FILE_ATTRIBUTE_DIRECTORY ? FLAG_DIRECTORY : FLAG_FILE;
+    retVal = aFileInfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ? FLAG_DIRECTORY : FLAG_FILE;
 
    else
 
     retVal = 0x80000000;
-
+  }
   break;
 
   case FILE_TYPE_CHAR:
@@ -2714,6 +2398,8 @@ Standard_Integer __fastcall _get_file_type (
 #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
                 ) {
@@ -2799,13 +2485,14 @@ leave: ;      // added for VisualAge
  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;
@@ -3021,96 +2708,6 @@ static OSD_SingleProtection __fastcall _get_protection_dir ( DWORD mask ) {
  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, Standard_CString fName ) {
-
- BOOL   fOK, fJob;                
- HANDLE hPrinter;
- BYTE   jobInfo[ MAX_PATH + sizeof ( DWORD ) ];
- DWORD  dwNeeded, dwCode;
-
- fOK = fJob = FALSE;
-
- __try {
-  if (  !OpenPrinter ( Standard_PCharacter(pName), &hPrinter, NULL )  ) {
-  
-   hPrinter = NULL;
-   __leave;
-  
-  }  // end if
-
-  if (   !AddJob (
-           hPrinter, 1, jobInfo, MAX_PATH + sizeof ( DWORD ), &dwNeeded
-          )
-  ) __leave;
-
-  fJob = TRUE;
-
-  if (  !CopyFile (
-          fName, (  ( 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()
@@ -3151,8 +2748,21 @@ Standard_Boolean OSD_File::IsExecutable()
 //  if (_access(FileName.ToCString(),0))
 }
 
-#endif // WNT
+#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.
@@ -3169,7 +2779,7 @@ Standard_Boolean OSD_File::ReadLastLine(TCollection_AsciiString& aLine,const Sta
 
   if (Count <= 0)
       return Standard_False ;
-  while(1) {
+  for(;;) {
     ReadLine(aLine, MaxLength, Len) ;
     if (!aLine.IsEmpty()) 
       return Standard_True ;
@@ -3188,4 +2798,3 @@ Standard_Boolean OSD_File::Edit()
 
 
 
-