ecere: gfx/gui: support P/NaCl platform. add new Pepper interface driver for targetin...
[sdk] / ecere / src / sys / File.ec
index 462f27f..ad6e8f9 100644 (file)
@@ -4,6 +4,7 @@ default:
 #define set _set
 #define uint _uint
 #define File _File
+#define strlen _strlen
 #undef __BLOCKS__
 #include <stdio.h>
 #include <stdarg.h>
@@ -40,14 +41,16 @@ default:
 
 #if defined(__WIN32__)
 #define WIN32_LEAN_AND_MEAN
+#define String String_
 #include <windows.h>
+#undef String
 #include <io.h>
 
-BOOL WINAPI GetVolumePathName(LPCTSTR lpszFileName,LPTSTR lpszVolumePathName,DWORD cchBufferLength);
+BOOL __declspec(dllimport) WINAPI GetVolumePathName(LPCTSTR lpszFileName,LPTSTR lpszVolumePathName,DWORD cchBufferLength);
 
 // Missing function...
 /*
-#ifndef WNetGetResourceInformation 
+#ifndef WNetGetResourceInformation
 DWORD APIENTRY WNetGetResourceInformationA(LPNETRESOURCE lpNetResource, LPVOID lpBuffer, LPDWORD lpcbBuffer, LPTSTR* lplpSystem);
 #ifdef UNICODE
 #define WNetGetResourceInformation  WNetGetResourceInformationW
@@ -70,6 +73,7 @@ private:
 #undef set
 #undef uint
 #undef File
+#undef strlen
 
 import "System"
 
@@ -82,14 +86,17 @@ import "dataTypes"
 // IMPLEMENTATION OF THESE IS IN _File.c
 default:
 
+FILE *eC_stdin(void);
+FILE *eC_stdout(void);
+
 uint FILE_GetSize(FILE * input);
 bool FILE_Lock(FILE * input, FILE * output, FileLock type, uint64 start, uint64 length, bool wait);
 void FILE_set_buffered(FILE * input, FILE * output, bool value);
-FileAttribs FILE_FileExists(char * fileName);
-bool FILE_FileGetSize(char * fileName, FileSize * size);
-bool FILE_FileGetStats(char * fileName, FileStats stats);
+FileAttribs FILE_FileExists(const char * fileName);
+bool FILE_FileGetSize(const char * fileName, FileSize * size);
+bool FILE_FileGetStats(const char * fileName, FileStats stats);
 void FILE_FileFixCase(char * file);
-void FILE_FileOpen(char * fileName, FileOpenMode mode, FILE ** input, FILE **output);
+void FILE_FileOpen(const char * fileName, FileOpenMode mode, FILE ** input, FILE **output);
 
 private:
 
@@ -121,13 +128,13 @@ public class FileSize : uint
       return result;
    }
 
-   char * OnGetString(char * string, void * fieldData, bool * needClass)
+   const char * OnGetString(char * string, void * fieldData, bool * needClass)
    {
       PrintSize(string, this, 2);
       return string;
    }
 
-   bool OnGetDataFromString(char * string)
+   bool OnGetDataFromString(const char * string)
    {
       char * end;
       double value = strtod(string, &end);
@@ -156,13 +163,13 @@ public class FileSize64 : uint64
       return result;
    }
 
-   char * OnGetString(char * string, void * fieldData, bool * needClass)
+   const char * OnGetString(char * string, void * fieldData, bool * needClass)
    {
       PrintBigSize(string, this, 2);
       return string;
    }
 
-   bool OnGetDataFromString(char * string)
+   bool OnGetDataFromString(const char * string)
    {
       char * end;
       double value = strtod(string, &end);
@@ -180,22 +187,22 @@ public class FileSize64 : uint64
 
 class FileSystem
 {
-   virtual File ::Open(char * archive, char * name, FileOpenMode mode);
+   virtual File ::Open(const char * archive, const char * name, FileOpenMode mode);
 
    // Query on names
-   virtual FileAttribs ::Exists(char * archive, char * fileName);
-   virtual bool ::GetSize(char * archive, char * fileName, FileSize * size);
-   virtual bool ::Stats(char * archive, char * fileName, FileStats stats);
-   virtual void ::FixCase(char * archive, char * fileName);
+   virtual FileAttribs ::Exists(const char * archive, const char * fileName);
+   virtual bool ::GetSize(const char * archive, const char * fileName, FileSize * size);
+   virtual bool ::Stats(const char * archive, const char * fileName, FileStats stats);
+   virtual void ::FixCase(const char * archive, char * fileName);
 
    // File Listing
-   virtual bool ::Find(FileDesc file, char * archive, char * name);
+   virtual bool ::Find(FileDesc file, const char * archive, const char * name);
    virtual bool ::FindNext(FileDesc file);
    virtual void ::CloseDir(FileDesc file);
 
    // Archive manipulation
-   virtual Archive ::OpenArchive(char * fileName, ArchiveOpenFlags create);
-   virtual bool ::QuerySize(char * fileName, FileSize * size);
+   virtual Archive ::OpenArchive(const char * fileName, ArchiveOpenFlags create);
+   virtual bool ::QuerySize(const char * fileName, FileSize * size);
 };
 
 public enum FileOpenMode { read = 1, write, append, readWrite, writeRead, appendRead };
@@ -221,7 +228,7 @@ public class File : IOChannel
       return Read(bytes, 1, numBytes);
    }
 
-   uint WriteData(byte * bytes, uint numBytes)
+   uint WriteData(const byte * bytes, uint numBytes)
    {
       return Write(bytes, 1, numBytes);
    }
@@ -242,7 +249,7 @@ public class File : IOChannel
       output = null;
    }
 
-   bool OnGetDataFromString(char * string)
+   bool OnGetDataFromString(const char * string)
    {
       if(!string[0])
       {
@@ -268,7 +275,7 @@ public class File : IOChannel
       return false;
    }
 
-   char * OnGetString(char * tempString, void * fieldData, bool * needClass)
+   const char * OnGetString(char * tempString, void * fieldData, bool * needClass)
    {
       if(this)
       {
@@ -283,8 +290,8 @@ public class File : IOChannel
    {
       Window editData = class::OnEdit(dataBox, obsolete, x + 24, y, w - 48, h, userData);
       Button load
-      { 
-         dataBox, inactive = true, text = $"Imp", hotKey = f2,
+      {
+         dataBox, inactive = true, text = $"Import"."Imp", hotKey = f2,
          position = { Max(x + 24, x + w - 24), y }, size = { 24, h };
 
          bool DataBox::NotifyClicked(Button button, int x, int y, Modifiers mods)
@@ -295,7 +302,7 @@ public class File : IOChannel
 
             if(fileDialog.Modal() == ok)
             {
-               char * filePath = fileDialog.filePath;
+               const char * filePath = fileDialog.filePath;
                File output = null;
                if(output.OnGetDataFromString(filePath))
                {
@@ -307,8 +314,8 @@ public class File : IOChannel
          }
       };
       Button save
-      { 
-         dataBox, inactive = true, text = $"Exp", hotKey = f2,
+      {
+         dataBox, inactive = true, text = $"Export"."Exp", hotKey = f2,
          position = { Max(x + 24, x + w - 48), y }, size = { 24, h };
 
          bool DataBox::NotifyClicked(Button button, int x, int y, Modifiers mods)
@@ -318,7 +325,7 @@ public class File : IOChannel
             fileDialog.filePath = "";
             if(fileDialog.Modal() == ok)
             {
-               char * filePath = fileDialog.filePath;
+               const char * filePath = fileDialog.filePath;
                File f = FileOpen(filePath, write);
                if(f)
                {
@@ -328,10 +335,10 @@ public class File : IOChannel
                   {
                      byte buffer[4096];
                      uint read = input.Read(buffer, 1, sizeof(buffer));
-                     f.Write(buffer, 1, read);                     
+                     f.Write(buffer, 1, read);
                   }
                   delete f;
-               }               
+               }
             }
             return true;
          }
@@ -355,7 +362,7 @@ public class File : IOChannel
             uint count = Read(uncompressed, 1,  size);
             if(count == size)
             {
-               uint cSize = size + size / 1000 + 12;
+               uLongf cSize = size + size / 1000 + 12;
                byte * compressed = new byte[cSize];
                if(compressed)
                {
@@ -363,7 +370,7 @@ public class File : IOChannel
 
                   size.OnSerialize(channel);
                   cSize.OnSerialize(channel);
-                  channel.WriteData(compressed, cSize);
+                  channel.WriteData(compressed, (uint)cSize);
 
                   delete compressed;
                }
@@ -394,7 +401,8 @@ public class File : IOChannel
 
    void OnUnserialize(IOChannel channel)
    {
-      uint size, cSize;
+      uLongf size;
+      uint cSize;
 
       this = null;
 
@@ -414,7 +422,7 @@ public class File : IOChannel
                {
                   this = TempFile { };
                   uncompress(uncompressed, &size, compressed, cSize);
-                  Write(uncompressed, 1, size);
+                  Write(uncompressed, 1, (uint)size);
                   Seek(0, start);
 
                   delete uncompressed;
@@ -463,7 +471,7 @@ public:
 
    virtual uint Tell(void)
    {
-      return input ? ftell(input) : ftell(output);
+      return (uint)(input ? ftell(input) : ftell(output));
    }
 
    virtual int Read(void * buffer, uint size, uint count)
@@ -471,7 +479,7 @@ public:
       return input ? (int)fread(buffer, size, count, input) : 0;
    }
 
-   virtual int Write(void * buffer, uint size, uint count)
+   virtual int Write(const void * buffer, uint size, uint count)
    {
       return output ? (int)fwrite(buffer, size, count, output) : 0;
    }
@@ -509,9 +517,9 @@ public:
 
    virtual bool Eof(void)
    {
-      return input ? feof(input) : true;
+      return input ? feof(input) != 0 : true;
    }
-   
+
    virtual bool Truncate(FileSize size)
    {
    #ifdef ECERE_BOOTSTRAP
@@ -522,7 +530,7 @@ public:
       return output ? (_chsize(fileno(output), size) == 0) : false;
    #else
       return output ? (ftruncate(fileno(output), size) == 0) : false;
-   #endif   
+   #endif
    #endif
    }
 
@@ -530,7 +538,7 @@ public:
    {
       return FILE_GetSize(input);
    }
-   
+
    virtual void CloseInput(void)
    {
       if(input)
@@ -564,7 +572,7 @@ public:
    }
 
    // Normal Methods
-   int Printf(char * format, ...)
+   int Printf(const char * format, ...)
    {
       int result = 0;
       if(format)
@@ -623,13 +631,13 @@ public:
          while(c<max-1)
          {
             char ch = 0;
-         
+
             if(/*!Peek() || */ !Getc(&ch))
             {
                result = false;
                break;
             }
-            if(ch =='\n') 
+            if(ch =='\n')
                break;
             if(ch !='\r')
                s[c++]=ch;
@@ -651,7 +659,10 @@ public:
       while(true)
       {
          if(!Getc(&ch))
+         {
             result = false;
+            break;
+         }
          if( (ch!='\n') && (ch!='\r') && (ch!=' ') && (ch!=',') && (ch!='\t'))
             break;
          if(Eof()) break;
@@ -673,11 +684,11 @@ public:
             else
                string[c]=ch;
 
-            if(!Getc(&ch)) 
+            if(!Getc(&ch))
             {
                c++;
                result = false;
-               break;            
+               break;
             }
          }
          string[c]=0;
@@ -696,7 +707,7 @@ public:
    {
       char string[32];
       GetString(string, sizeof(string));
-      return strtoul(string, null, 16);
+      return (uint)strtoul(string, null, 16);
    }
 
    float GetFloat(void)
@@ -720,7 +731,7 @@ public:
       set
       {
          FILE_set_buffered(input, output, value);
-      }      
+      }
    }
    property bool eof { get { return Eof(); } }
 
@@ -748,7 +759,7 @@ public:
       return c;
    }
 
-   bool CopyTo(char * outputFileName)
+   bool CopyTo(const char * outputFileName)
    {
       bool result = false;
       File f = FileOpen(outputFileName, write);
@@ -774,7 +785,7 @@ public:
    }
 
 #if 0
-   virtual bool Open(char * fileName, FileOpenMode mode)
+   virtual bool Open(const char * fileName, FileOpenMode mode)
    {
       bool result = false;
       if(this)
@@ -798,7 +809,7 @@ public:
          //if(!result)
          {
             /* TOFIX:
-            LogErrorCode((mode == Read || mode == ReadWrite) ? 
+            LogErrorCode((mode == Read || mode == ReadWrite) ?
                ERR_FILE_NOT_FOUND : ERR_FILE_WRITE_FAILED, fileName);
             */
          }
@@ -814,10 +825,28 @@ public:
    }
 }
 
+#if defined(__WIN32__)
+default extern intptr_t stdinHandle;
+default extern intptr_t stdoutHandle;
+#endif
+
 public class ConsoleFile : File
 {
-   input = stdin;
-   output = stdout;
+   input = eC_stdin();
+   output = eC_stdout();
+
+#if defined(__WIN32__)
+   void CloseInput()
+   {
+      CloseHandle((HANDLE)stdinHandle);
+   }
+   /*
+   void CloseOutput()
+   {
+      CloseHandle((HANDLE)stdoutHandle);
+   }*/
+#endif
+
    ~ConsoleFile()
    {
       input = null;
@@ -833,6 +862,10 @@ public:
    // property bool { };
 };
 
+#ifdef ECERE_BOOTSTRAP
+public class SecSince1970 : int64;
+#endif
+
 public struct FileStats
 {
    FileAttribs attribs;
@@ -875,11 +908,11 @@ default void TimeStampToWin32FileTime(TimeStamp t, FILETIME * fileTime)
    // TIME_ZONE_INFORMATION tz = { 0 };
    SYSTEMTIME st, lt;
    DateTime tm;
-   
+
    tm = t;
 
    st.wYear = (short)tm.year;
-   st.wMonth = (short)tm.month + 1;
+   st.wMonth = (short)(tm.month + 1);
    st.wDay = (short)tm.day;
    st.wHour = (short)tm.hour;
    st.wMinute = (short)tm.minute;
@@ -904,10 +937,11 @@ default bool WinReviveNetworkResource(uint16 * _wfileName);
 
 #endif
 
-public FileAttribs FileExists(char * fileName)
+public FileAttribs FileExists(const char * fileName)
 {
-   char archiveName[MAX_LOCATION], * archiveFile;
 #if !defined(ECERE_BOOTSTRAP)
+   char archiveName[MAX_LOCATION];
+   const char * archiveFile;
    if(SplitArchivePath(fileName, archiveName, &archiveFile))
    {
       return EARFileSystem::Exists(archiveName, archiveFile);
@@ -923,19 +957,20 @@ public FileAttribs FileExists(char * fileName)
 
 static int openCount;
 
-public File FileOpen(char * fileName, FileOpenMode mode)
+public File FileOpen(const char * fileName, FileOpenMode mode)
 {
    File result = null;
    if(fileName)
    {
-      char archiveName[MAX_LOCATION], * archiveFile;
 #if !defined(ECERE_BOOTSTRAP)
+      char archiveName[MAX_LOCATION];
+      const char * archiveFile;
       if(SplitArchivePath(fileName, archiveName, &archiveFile))
       {
          result = EARFileSystem::Open(archiveName, archiveFile, mode);
       }
 #if !defined(ECERE_VANILLA) && !defined(ECERE_NONET)
-      else if(strstr(fileName, "http://") == fileName)
+      else if(strstr(fileName, "http://") == fileName || strstr(fileName, "https://"))
       {
          result = FileOpenURL(fileName);
       }
@@ -944,7 +979,7 @@ public File FileOpen(char * fileName, FileOpenMode mode)
 #endif
       if(strstr(fileName, "File://") == fileName)
       {
-         result = (File)strtoul(fileName+7, null, 16);
+         result = (File)(uintptr)strtoull(fileName+7, null, 16);
          if(result)
          {
             if(result._class && eClass_IsDerived(result._class, class(File)))
@@ -982,7 +1017,7 @@ public File FileOpen(char * fileName, FileOpenMode mode)
             {
                delete file;
                /* TOFIX:
-               LogErrorCode((mode == Read || mode == ReadWrite) ? 
+               LogErrorCode((mode == Read || mode == ReadWrite) ?
                   ERR_FILE_NOT_FOUND : ERR_FILE_WRITE_FAILED, fileName);
                */
             }
@@ -998,7 +1033,7 @@ public void FileFixCase(char * file)
 }
 
 #if !defined(ECERE_BOOTSTRAP)
-public bool FileTruncate(char * fileName, FileSize size)
+public bool FileTruncate(const char * fileName, FileSize size)
 {
 #if defined(__WIN32__)
    uint16 * _wfileName = UTF8toUTF16(fileName, null);
@@ -1018,7 +1053,7 @@ public bool FileTruncate(char * fileName, FileSize size)
 }
 #endif
 
-public bool FileGetSize(char * fileName, FileSize * size)
+public bool FileGetSize(const char * fileName, FileSize * size)
 {
    bool result = false;
    if(size)
@@ -1027,7 +1062,8 @@ public bool FileGetSize(char * fileName, FileSize * size)
       if(fileName)
       {
 #if !defined(ECERE_BOOTSTRAP)
-         char archiveName[MAX_LOCATION], * archiveFile;
+         char archiveName[MAX_LOCATION];
+         const char * archiveFile;
          if(SplitArchivePath(fileName, archiveName, &archiveFile))
             return EARFileSystem::GetSize(archiveName, archiveFile, size);
          else
@@ -1038,13 +1074,14 @@ public bool FileGetSize(char * fileName, FileSize * size)
    return result;
 }
 
-public bool FileGetStats(char * fileName, FileStats stats)
+public bool FileGetStats(const char * fileName, FileStats stats)
 {
    bool result = false;
    if(stats && fileName)
    {
 #if !defined(ECERE_BOOTSTRAP)
-      char archiveName[MAX_LOCATION], * archiveFile;
+      char archiveName[MAX_LOCATION];
+      const char * archiveFile;
       if(SplitArchivePath(fileName, archiveName, &archiveFile))
          result = EARFileSystem::Stats(archiveName, archiveFile, stats);
       else
@@ -1056,7 +1093,7 @@ public bool FileGetStats(char * fileName, FileStats stats)
 
 #ifndef ECERE_BOOTSTRAP
 
-public bool FileSetAttribs(char * fileName, FileAttribs attribs)
+public bool FileSetAttribs(const char * fileName, FileAttribs attribs)
 {
 #ifdef __WIN32__
    uint winAttribs = 0;
@@ -1071,7 +1108,7 @@ public bool FileSetAttribs(char * fileName, FileAttribs attribs)
    return true;
 }
 
-public bool FileSetTime(char * fileName, TimeStamp created, TimeStamp accessed, TimeStamp modified)
+public bool FileSetTime(const char * fileName, TimeStamp created, TimeStamp accessed, TimeStamp modified)
 {
    bool result = false;
    TimeStamp currentTime = time(null);
@@ -1088,7 +1125,7 @@ public bool FileSetTime(char * fileName, TimeStamp created, TimeStamp accessed,
       if(hFile != INVALID_HANDLE_VALUE)
       {
          FILETIME c, a, m;
-      
+
          TimeStampToWin32FileTime(created, &c);
          TimeStampToWin32FileTime(accessed, &a);
          TimeStampToWin32FileTime(modified, &m);
@@ -1102,7 +1139,7 @@ public bool FileSetTime(char * fileName, TimeStamp created, TimeStamp accessed,
             mm = Win32FileTimeToTimeStamp(&m);
          }
          */
-                  
+
          if(SetFileTime(hFile, &c, &a, &m))
             result = true;
 
@@ -1110,9 +1147,11 @@ public bool FileSetTime(char * fileName, TimeStamp created, TimeStamp accessed,
       }
 #else
       struct utimbuf t = { (int)accessed, (int)modified };
+#if !defined(__pnacl__)
       if(!utime(fileName, &t))
          result = true;
 #endif
+#endif
    }
    return result;
 }
@@ -1139,14 +1178,15 @@ private class Dir : struct
    char name[MAX_LOCATION];
 };
 
-static FileDesc FileFind(char * path, char * extensions)
+static FileDesc FileFind(const char * path, const char * extensions)
 {
    FileDesc result = null;
    FileDesc file;
 
    if((file = FileDesc {}))
    {
-      char archiveName[MAX_LOCATION], * archiveFile;
+      char archiveName[MAX_LOCATION];
+      const char * archiveFile;
       if(SplitArchivePath(path, archiveName, &archiveFile))
       {
          if(EARFileSystem::Find(file, archiveName, archiveFile))
@@ -1158,16 +1198,17 @@ static FileDesc FileFind(char * path, char * extensions)
       else
       {
          Dir d;
-      
+
          if((d = file.dir = Dir {}))
          {
 #if defined(__WIN32__)
             if(!strcmp(path, "/"))
             {
                int c;
-               d.fHandle = (void *)0xFFFFFFFF; //GetLogicalDrives();
+               uint drives = 0xFFFFFFFF;
+               d.fHandle = (HANDLE)(uintptr)drives; //GetLogicalDrives();
                for(c = 0; c<26; c++)
-                  if(((uint)d.fHandle) & (1<<c))
+                  if(((uint)(uintptr)d.fHandle) & (1<<c))
                   {
                      char volume[MAX_FILENAME] = "";
                      uint16 _wvolume[MAX_FILENAME];
@@ -1189,10 +1230,10 @@ static FileDesc FileFind(char * path, char * extensions)
                         case DRIVE_REMOTE:    file.stats.attribs.isRemote = true; break;
                         case DRIVE_CDROM:     file.stats.attribs.isCDROM = true; break;
                      }
-                     *((uint *)&d.fHandle) ^= (1<<c);
+                     drives ^= (1<<c);
                      if(driveType == DRIVE_NO_ROOT_DIR) continue;
-                  
-                     if(driveType != DRIVE_REMOVABLE && driveType != DRIVE_REMOTE && 
+
+                     if(driveType != DRIVE_REMOVABLE && driveType != DRIVE_REMOTE &&
                         GetVolumeInformation(_wfilePath, _wvolume, MAX_FILENAME - 1, null, null, null, null, 0))
                      {
                         file.path[2] = '\0';
@@ -1207,6 +1248,7 @@ static FileDesc FileFind(char * path, char * extensions)
                      result = file;
                      break;
                   }
+               d.fHandle = (HANDLE)(uintptr) drives;
                d.resource = 0;
             }
             else if(path[0] != '\\' || path[1] != '\\' || strstr(path+2, "\\"))
@@ -1251,15 +1293,15 @@ static FileDesc FileFind(char * path, char * extensions)
             else
             {
                HANDLE handle = 0;
-               int count = 0xFFFFFFFF;
-               uint size = 512 * sizeof(NETRESOURCE);
+               DWORD count = 0xFFFFFFFF;
+               DWORD size = 512 * sizeof(NETRESOURCE);
                NETRESOURCE * buffer = (NETRESOURCE *)new0 byte[size];
                NETRESOURCE nr = {0};
 
                d.fHandle = null;
                nr.dwScope       = RESOURCE_GLOBALNET;
                nr.dwType        = RESOURCETYPE_DISK;
-               nr.lpProvider = L"Microsoft Windows Network";
+               nr.lpProvider = (uint16 *)L"Microsoft Windows Network";
 
                strcpy(d.name, path);
                if(path[2])
@@ -1308,7 +1350,7 @@ static FileDesc FileFind(char * path, char * extensions)
                else
                {
                   int c;
-                  nr.lpProvider = L"Microsoft Windows Network";
+                  nr.lpProvider = (uint16 *)L"Microsoft Windows Network";
 
                   // Entire Network
                   WNetOpenEnum(RESOURCE_GLOBALNET, RESOURCETYPE_DISK, 0, &nr, &handle);
@@ -1325,11 +1367,11 @@ static FileDesc FileFind(char * path, char * extensions)
                   for(c = 0; c<count; c++)
                   {
                      NETRESOURCE * resources;
-                     int countInGroup = 0xFFFFFFFF;
+                     DWORD countInGroup = 0xFFFFFFFF;
 
                      size = 512 * sizeof(NETRESOURCE);
                      resources = (NETRESOURCE *)new0 byte[size];
-                  
+
                      // Entire Network
                      WNetOpenEnum(RESOURCE_GLOBALNET, RESOURCETYPE_DISK, 0, &buffer[c], &handle);
                      while(true)
@@ -1387,11 +1429,13 @@ static FileDesc FileFind(char * path, char * extensions)
                strcat(file.path, file.name);
                if(!stat(file.path, &s))
                {
+#if !defined(__pnacl__)
                   file.stats.attribs = (s.st_mode&S_IFDIR) ? FileAttribs { isDirectory = true } : FileAttribs { isFile = true };
-                  file.stats.size = s.st_size;
+                  file.stats.size = (FileSize)s.st_size;
                   file.stats.accessed = s.st_atime;
                   file.stats.modified = s.st_mtime;
                   file.stats.created = s.st_ctime;
+#endif
                }
                strcpy(d.name, path);
 
@@ -1423,7 +1467,7 @@ private class FileDesc : struct
    subclass(FileSystem) system;
    Dir dir;
 
-   bool Validate(char * extensions)
+   bool Validate(const char * extensions)
    {
       if(strcmp(name, "..") && strcmp(name, ".") && strcmp(name, ""))
       {
@@ -1452,7 +1496,7 @@ private class FileDesc : struct
       return false;
    }
 
-   FileDesc FindNext(char * extensions)
+   FileDesc FindNext(const char * extensions)
    {
       FileDesc result = null;
 
@@ -1477,9 +1521,10 @@ private class FileDesc : struct
             if(!strcmp(d.name, "/"))
             {
                int c;
+               uint drives = (uint)(uintptr)d.fHandle;
                for(c = 0; c<26; c++)
                {
-                  if(((uint)d.fHandle) & (1<<c))
+                  if(drives & (1<<c))
                   {
                      char volume[MAX_FILENAME] = "";
                      int driveType;
@@ -1494,7 +1539,7 @@ private class FileDesc : struct
                      _wpath[2] = path[2] = '\\';
                      _wpath[3] = path[3] = 0;
                      driveType = GetDriveType(_wpath);
-                     *((uint *)&d.fHandle) ^= (1<<c);
+                     drives ^= (1<<c);
 
                      switch(driveType)
                      {
@@ -1506,7 +1551,7 @@ private class FileDesc : struct
                      {
                         uint16 remoteName[1024];
                         int status;
-                        int size = 1024;
+                        DWORD size = 1024;
                         _wpath[2] = 0;
 
                         status = WNetGetConnection(_wpath, remoteName, &size);
@@ -1517,7 +1562,7 @@ private class FileDesc : struct
                         _wpath[3] = 0;
                      }
 
-                     if(driveType != DRIVE_REMOVABLE && driveType != DRIVE_REMOTE && 
+                     if(driveType != DRIVE_REMOVABLE && driveType != DRIVE_REMOTE &&
                         GetVolumeInformation(_wpath, _wvolume, MAX_FILENAME - 1, null, null, null, null, 0))
                      {
                         UTF16toUTF8Buffer(_wvolume, volume, MAX_FILENAME);
@@ -1533,6 +1578,7 @@ private class FileDesc : struct
                      break;
                   }
                }
+               d.fHandle = (HANDLE)(uintptr) drives;
                break;
             }
             else if(d.name[0] != '\\' || d.name[1] != '\\' || strstr(d.name+2, "\\"))
@@ -1595,10 +1641,10 @@ private class FileDesc : struct
                   {
                      if(c != d.workGroup)
                      {
-                        int countInGroup = 0xFFFFFFFF;
+                        DWORD countInGroup = 0xFFFFFFFF;
                         HANDLE handle;
                         NETRESOURCE * resources;
-                        uint size = 512 * sizeof(NETRESOURCE);
+                        DWORD size = 512 * sizeof(NETRESOURCE);
 
                         resources = (NETRESOURCE *)new0 byte[size];
                         // Entire Network
@@ -1610,7 +1656,7 @@ private class FileDesc : struct
                               break;
                            countInGroup = 0xFFFFFFFF;
                            resources = (NETRESOURCE *)renew0 resources byte[size];
-                           
+
                         }
                         WNetCloseEnum(handle);
                         d.numResources = countInGroup;
@@ -1636,7 +1682,7 @@ private class FileDesc : struct
                      }
                      else
                      {
-                        if(d.resources) 
+                        if(d.resources)
                            delete d.resources;
                      }
                   }
@@ -1662,12 +1708,14 @@ private class FileDesc : struct
                strcat(path, name);
                if(!stat(path, &s))
                {
+#if !defined(__pnacl__)
                   stats.attribs = FileAttribs { };
                   stats.attribs = (s.st_mode&S_IFDIR) ? FileAttribs { isDirectory = true } : FileAttribs { isFile = true };
-                  stats.size = s.st_size;
+                  stats.size = (FileSize)s.st_size;
                   stats.accessed = s.st_atime;
                   stats.modified = s.st_mtime;
                   stats.created = s.st_ctime;
+#endif
                }
                result = this;
             }
@@ -1706,12 +1754,11 @@ private class FileDesc : struct
 public struct FileListing
 {
 public:
-   char * directory;
-   char * extensions;
+   const char * directory;
+   const char * extensions;
 
    bool Find()
    {
-      bool result = false;
       if(desc)
          desc = desc.FindNext(extensions);
       else
@@ -1728,8 +1775,8 @@ public:
       desc = null;
    }
 
-   property char * name { get { return (char *)(desc ? desc.name : null); } };
-   property char * path { get { return (char *)(desc ? desc.path : null); } };
+   property const char * name { get { return desc ? desc.name : null; } };
+   property const char * path { get { return desc ? desc.path : null; } };
    property FileStats stats { get { value = desc ? desc.stats : FileStats { }; } };
 
 private:
@@ -1737,7 +1784,7 @@ private:
 };
 #endif
 
-public File CreateTemporaryFile(char * tempFileName, char * template)
+public File CreateTemporaryFile(char * tempFileName, const char * template)
 {
 #ifndef ECERE_BOOTSTRAP // quick fix for now
    File f;
@@ -1749,7 +1796,7 @@ public File CreateTemporaryFile(char * tempFileName, char * template)
    //strcpy(buffer, template);
    strcat(buffer, "XXXXXX");
    // mktemp(buffer);
-   fd = mkstemp(buffer);   
+   fd = mkstemp(buffer);
    strcpy(tempFileName, buffer);
    f = { };
    f.output = f.input = fdopen(fd, "r+");
@@ -1758,14 +1805,16 @@ public File CreateTemporaryFile(char * tempFileName, char * template)
    GetTempPathA(MAX_LOCATION, tempPath);     // TODO: Patch this whole thing to support Unicode temp path
    GetTempFileNameA(tempPath, template, 0, tempFileName);
    f = FileOpen(tempFileName, readWrite);
-#endif   
+#endif
    return f;
+#else
+   return null;
 #endif
 }
 
 #undef DeleteFile
 
-public void CreateTemporaryDir(char * tempFileName, char * template)
+public void CreateTemporaryDir(char * tempFileName, const char * template)
 {
 #ifndef ECERE_BOOTSTRAP // quick fix for now
 #if defined(__unix__) || defined(__APPLE__)
@@ -1790,9 +1839,8 @@ public void CreateTemporaryDir(char * tempFileName, char * template)
 public void MakeSlashPath(char * p)
 {
    FileFixCase(p);
-#ifdef WIN32
-   ChangeCh(p, '\\', '/');
-#endif
+   if(__runtimePlatform == win32)
+      ChangeCh(p, '\\', '/');
 }
 
 public void MakeSystemPath(char * p)
@@ -1800,7 +1848,7 @@ public void MakeSystemPath(char * p)
    FileFixCase(p);
 }
 
-public char * CopySystemPath(char * p)
+public char * CopySystemPath(const char * p)
 {
    char * d = CopyString(p);
    if(d)
@@ -1808,7 +1856,7 @@ public char * CopySystemPath(char * p)
    return d;
 }
 
-public char * CopyUnixPath(char * p)
+public char * CopyUnixPath(const char * p)
 {
    char * d = CopyString(p);
    if(d)
@@ -1816,7 +1864,7 @@ public char * CopyUnixPath(char * p)
    return d;
 }
 
-public char * GetSystemPathBuffer(char * d, char * p)
+public char * GetSystemPathBuffer(char * d, const char * p)
 {
    if(d != p)
       strcpy(d, p ? p : "");
@@ -1824,7 +1872,7 @@ public char * GetSystemPathBuffer(char * d, char * p)
    return d;
 }
 
-public char * GetSlashPathBuffer(char * d, char * p)
+public char * GetSlashPathBuffer(char * d, const char * p)
 {
    if(d != p)
       strcpy(d, p ? p : "");