ecere: Initial Emscripten support
[sdk] / ecere / src / sys / File.c
index a317fa5..26cced2 100644 (file)
@@ -1,4 +1,7 @@
+#define _Noreturn
+
 #undef __BLOCKS__
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdarg.h>
@@ -45,9 +48,9 @@ void __ecereNameSpace__ecere__com__eSystem_Delete(void * memory);
 void * __ecereNameSpace__ecere__com__eSystem_New0(unsigned int size);
 void * __ecereNameSpace__ecere__com__eSystem_Renew(void * memory, unsigned int size);
 void * __ecereNameSpace__ecere__com__eSystem_Renew0(void * memory, unsigned int size);
-unsigned short * __ecereNameSpace__ecere__sys__UTF8toUTF16(char * source, int * wordCount);
-unsigned short * __ecereNameSpace__ecere__sys__UTF8toUTF16Buffer(char * source, uint16 * dest, int max);
-char * __ecereNameSpace__ecere__sys__UTF16toUTF8(uint16 * source);
+unsigned short * __ecereNameSpace__ecere__sys__UTF8toUTF16(const char * source, int * wordCount);
+unsigned short * __ecereNameSpace__ecere__sys__UTF8toUTF16Buffer(const char * source, uint16 * dest, int max);
+char * __ecereNameSpace__ecere__sys__UTF16toUTF8(const uint16 * source);
 void __ecereNameSpace__ecere__sys__ChangeCh(char * string, char ch1, char ch2);
 
 #if defined(__WIN32__) || defined(__WATCOMC__)
@@ -101,21 +104,21 @@ typedef struct
    SecSince1970 created;
 } FileStats;
 
-char * __ecereNameSpace__ecere__sys__GetLastDirectory(char * string, char * output);
-bool __ecereNameSpace__ecere__sys__SplitArchivePath(char * fileName, char * archiveName, char ** archiveFile);
+char * __ecereNameSpace__ecere__sys__GetLastDirectory(const char * string, char * output);
+bool __ecereNameSpace__ecere__sys__SplitArchivePath(const char * fileName, char * archiveName, char ** archiveFile);
 
 #if defined(__WIN32__) && !defined(ECERE_BOOTSTRAP)
-void __ecereMethod___ecereNameSpace__ecere__sys__EARFileSystem_FixCase(char * archive, char * name);
+void __ecereMethod___ecereNameSpace__ecere__sys__EARFileSystem_FixCase(const char * archive, char * name);
 
 static BOOL CALLBACK EnumThreadWindowsProc(HWND hwnd, LPARAM lParam)
 {
    DWORD pid;
    if(IsWindowVisible(hwnd) && GetWindowThreadProcessId(hwnd, &pid) && pid == GetCurrentProcessId())
-   {      
+   {
       *(void **)lParam = hwnd;
       return FALSE;
    }
-   return TRUE;   
+   return TRUE;
 }
 bool WinReviveNetworkResource(uint16 * _wfileName)
 {
@@ -147,7 +150,7 @@ bool WinReviveNetworkResource(uint16 * _wfileName)
    if(!windowHandle)
    {
       EnumWindows(EnumThreadWindowsProc, (LPARAM)&windowHandle);
-      
+
    }
    if(WNetAddConnection3(windowHandle, &nr, null, null, CONNECT_INTERACTIVE|CONNECT_PROMPT) == NO_ERROR)
       result = true;
@@ -189,7 +192,7 @@ bool FILE_Lock(FILE * input, FILE * output, FileLock type, uint64 start, uint64
             (uint)(length ? ((length & 0xFFFFFFFF00000000LL) >> 32) : 0xFFFFFFFF),
             &overlapped) != 0;
       else
-         return LockFileEx(hFile, ((type == exclusive) ? LOCKFILE_EXCLUSIVE_LOCK : 0) | (wait ? 0 : LOCKFILE_FAIL_IMMEDIATELY), 0, 
+         return LockFileEx(hFile, ((type == exclusive) ? LOCKFILE_EXCLUSIVE_LOCK : 0) | (wait ? 0 : LOCKFILE_FAIL_IMMEDIATELY), 0,
             (uint)(length ? (length & 0xFFFFFFFF) : 0xFFFFFFFF),
             (uint)(length ? ((length & 0xFFFFFFFF00000000LL) >> 32) : 0xFFFFFFFF),
             &overlapped) != 0;
@@ -205,7 +208,7 @@ bool FILE_Lock(FILE * input, FILE * output, FileLock type, uint64 start, uint64
 
       fd = fileno(output ? output : input);
       return fcntl(fd, wait ? F_SETLKW : F_SETLK, &fl) != -1;
-#endif      
+#endif
    }
 }
 
@@ -219,7 +222,7 @@ void FILE_set_buffered(FILE * input, FILE * output, bool value)
 #endif
 }
 
-FileAttribs FILE_FileExists(char * fileName)
+FileAttribs FILE_FileExists(const char * fileName)
 {
 #ifdef __WIN32__
    FileAttribs result = 0;
@@ -295,7 +298,7 @@ FileAttribs FILE_FileExists(char * fileName)
 #endif
 }
 
-bool FILE_FileGetSize(char * fileName, FileSize * size)
+bool FILE_FileGetSize(const char * fileName, FileSize * size)
 {
    bool result = false;
 #if defined(__WIN32__)
@@ -316,7 +319,7 @@ bool FILE_FileGetSize(char * fileName, FileSize * size)
    return result;
 }
 
-bool FILE_FileGetStats(char * fileName, FileStats * stats)
+bool FILE_FileGetStats(const char * fileName, FileStats * stats)
 {
    bool result = false;
 #if defined(__WIN32__)
@@ -348,13 +351,15 @@ bool FILE_FileGetStats(char * fileName, FileStats * stats)
             stats->accessed = Win32FileTimeToTimeStamp(&a);
             stats->modified = Win32FileTimeToTimeStamp(&m);
 #endif
-            
+
             CloseHandle(hFile);
          }
       }
 #else
       stats->accessed = s.st_atime;
-      stats->created = s.st_ctime;
+      // UNIX st_ctime is 'status change' time, not creation time
+      // Marking created as 0, as ctime changes cause unreproducible builds
+      stats->created = 0;
       stats->modified = s.st_mtime;
 #endif
 /*
@@ -419,7 +424,7 @@ void FILE_FileFixCase(char * file)
       }
       // Copy Entire Computer to new path
       else if(file[0] == '/'  && !file[1])
-   
+
       {
          parent[0] = '/';
          parent[1] = '\0';
@@ -436,7 +441,7 @@ void FILE_FileFixCase(char * file)
          for(;(ch = file[c]) && (ch != '/' && ch != '\\'); c++)
          {
             if(len < MAX_FILENAME)
-               directory[len++] = ch;  
+               directory[len++] = ch;
          }
          directory[len] = '\0';
 
@@ -552,7 +557,7 @@ void FILE_FileFixCase(char * file)
 #endif
 }
 
-void FILE_FileOpen(char * fileName, FileOpenMode mode, FILE ** input, FILE **output)
+void FILE_FileOpen(const char * fileName, FileOpenMode mode, FILE ** input, FILE **output)
 {
 #if defined(__WIN32__) && !defined(ECERE_BOOTSTRAP)
    uint16 * _wfileName = __ecereNameSpace__ecere__sys__UTF8toUTF16(fileName, null);