]> de.git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
cleaned up and merged a lot of sys_*.c code into sys_shared.c
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Tue, 20 Aug 2002 03:13:02 +0000 (03:13 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Tue, 20 Aug 2002 03:13:02 +0000 (03:13 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@2261 d7cf8633-e32d-0410-b094-e92efae38249

sys.h
sys_linux.c
sys_shared.c
sys_win.c

diff --git a/sys.h b/sys.h
index e8de6bb1aa9615220f7a8c3859db845e32f29fd8..0c91f4d097021d4f5e7aaea6746ef6d09831e372 100644 (file)
--- a/sys.h
+++ b/sys.h
@@ -29,25 +29,23 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 // returns the file size
 // return -1 if file is not present
 // the file should be in BINARY mode for stupid OSs that care
-int Sys_FileOpenRead (char *path, int *hndl);
+int Sys_FileOpenRead (const char *path, int *hndl);
 
-int Sys_FileOpenWrite (char *path);
+int Sys_FileOpenWrite (const char *path);
 void Sys_FileClose (int handle);
 void Sys_FileSeek (int handle, int position);
 int Sys_FileRead (int handle, void *dest, int count);
 int Sys_FileWrite (int handle, void *data, int count);
-int    Sys_FileTime (char *path);
-void Sys_mkdir (char *path);
+int    Sys_FileTime (const char *path);
+void Sys_mkdir (const char *path);
 
 //
 // system IO
 //
-void Sys_DebugLog(char *file, char *fmt, ...);
-
-void Sys_Error (char *error, ...);
+void Sys_Error (const char *error, ...);
 // an error will cause the entire program to exit
 
-void Sys_Printf (char *fmt, ...);
+void Sys_Printf (const char *fmt, ...);
 // send text to the console
 
 void Sys_Quit (void);
index eb2993cb71e509acf62a7f2c3028a5ea01c8679f..0dc1ce9e61ae8da4f4dc1263115945178c7147b2 100644 (file)
@@ -30,10 +30,6 @@ char *cachedir = "/tmp";
 // General routines
 // =======================================================================
 
-void Sys_DebugNumber(int y, int val)
-{
-}
-
 void Sys_Quit (void)
 {
        Host_Shutdown();
@@ -42,7 +38,7 @@ void Sys_Quit (void)
        exit(0);
 }
 
-void Sys_Error (char *error, ...)
+void Sys_Error (const char *error, ...)
 {
        va_list argptr;
        char string[1024];
@@ -60,7 +56,7 @@ void Sys_Error (char *error, ...)
 
 }
 
-void Sys_Warn (char *warning, ...)
+void Sys_Warn (const char *warning, ...)
 {
        va_list argptr;
        char string[1024];
@@ -71,96 +67,6 @@ void Sys_Warn (char *warning, ...)
        fprintf(stderr, "Warning: %s", string);
 }
 
-/*
-============
-Sys_FileTime
-
-returns -1 if not present
-============
-*/
-int Sys_FileTime (char *path)
-{
-       struct stat buf;
-
-       if (stat (path,&buf) == -1)
-               return -1;
-
-       return buf.st_mtime;
-}
-
-
-void Sys_mkdir (char *path)
-{
-       mkdir (path, 0777);
-}
-
-int Sys_FileOpenRead (char *path, int *handle)
-{
-       int h;
-       struct stat fileinfo;
-
-       h = open (path, O_RDONLY, 0666);
-       *handle = h;
-       if (h == -1)
-               return -1;
-
-       if (fstat (h,&fileinfo) == -1)
-               Sys_Error ("Error fstating %s", path);
-
-       return fileinfo.st_size;
-}
-
-int Sys_FileOpenWrite (char *path)
-{
-       int handle;
-
-       umask (0);
-
-       handle = open(path,O_RDWR | O_CREAT | O_TRUNC, 0666);
-
-       if (handle == -1)
-       {
-               Con_Printf("Sys_FileOpenWrite: Error opening %s: %s", path, strerror(errno));
-               return 0;
-       }
-
-       return handle;
-}
-
-int Sys_FileWrite (int handle, void *src, int count)
-{
-       return write (handle, src, count);
-}
-
-void Sys_FileClose (int handle)
-{
-       close (handle);
-}
-
-void Sys_FileSeek (int handle, int position)
-{
-       lseek (handle, position, SEEK_SET);
-}
-
-int Sys_FileRead (int handle, void *dest, int count)
-{
-       return read (handle, dest, count);
-}
-
-void Sys_DebugLog(char *file, char *fmt, ...)
-{
-       va_list argptr;
-       static char data[1024];
-       int fd;
-
-       va_start(argptr, fmt);
-       vsprintf(data, fmt, argptr);
-       va_end(argptr);
-       fd = open(file, O_WRONLY | O_CREAT | O_APPEND, 0666);
-       write(fd, data, strlen(data));
-       close(fd);
-}
-
 double Sys_DoubleTime (void)
 {
        static int first = true;
@@ -246,10 +152,8 @@ int main (int c, char **v)
 
        memset(&host_parms, 0, sizeof(host_parms));
 
-       COM_InitArgv(c, v);
-       host_parms.argc = com_argc;
-       host_parms.argv = com_argv;
-
+       host_parms.argc = c;
+       host_parms.argv = v;
        host_parms.basedir = basedir;
 
        fcntl(0, F_SETFL, fcntl (0, F_GETFL, 0) | FNDELAY);
index 370752bfd3d509d242e6dc862a964ff694b56c56..11f160402fd6a2f10098f04d42b74c8ae94d12e0 100644 (file)
@@ -2,9 +2,11 @@
 #include "quakedef.h"
 #include <time.h>
 #ifndef WIN32
+#include <sys/stat.h>
 #include <unistd.h>
 #include <fcntl.h>
 #endif
+#include <errno.h>
 
 extern cvar_t  timestamps;
 extern cvar_t  timeformat;
@@ -53,7 +55,7 @@ extern HANDLE hinput, houtput;
 #endif
 
 #define MAX_PRINT_MSG  16384
-void Sys_Printf (char *fmt, ...)
+void Sys_Printf (const char *fmt, ...)
 {
        va_list         argptr;
        char            start[MAX_PRINT_MSG];   // String we started with
@@ -102,6 +104,133 @@ void Sys_Printf (char *fmt, ...)
 #endif
 }
 
+// LordHavoc: 256 pak files (was 10)
+#define MAX_HANDLES 256
+QFile *sys_handles[MAX_HANDLES];
+
+int findhandle (void)
+{
+       int i;
+
+       for (i = 1;i < MAX_HANDLES;i++)
+               if (!sys_handles[i])
+                       return i;
+       Sys_Error ("out of handles");
+       return -1;
+}
+
+/*
+================
+Sys_FileLength
+================
+*/
+int Sys_FileLength (QFile *f)
+{
+       int pos, end;
+
+       pos = Qtell (f);
+       Qseek (f, 0, SEEK_END);
+       end = Qtell (f);
+       Qseek (f, pos, SEEK_SET);
+
+       return end;
+}
+
+int Sys_FileOpenRead (const char *path, int *handle)
+{
+       QFile *f;
+       int i, retval;
+
+       i = findhandle ();
+
+       f = Qopen(path, "rbz");
+
+       if (!f)
+       {
+               *handle = -1;
+               retval = -1;
+       }
+       else
+       {
+               sys_handles[i] = f;
+               *handle = i;
+               retval = Sys_FileLength(f);
+       }
+
+       return retval;
+}
+
+int Sys_FileOpenWrite (const char *path)
+{
+       QFile   *f;
+       int             i;
+
+       i = findhandle ();
+
+       f = Qopen(path, "wb");
+       if (!f)
+       {
+               Con_Printf("Sys_FileOpenWrite: Error opening %s: %s", path, strerror(errno));
+               return 0;
+       }
+       sys_handles[i] = f;
+
+       return i;
+}
+
+void Sys_FileClose (int handle)
+{
+       Qclose (sys_handles[handle]);
+       sys_handles[handle] = NULL;
+}
+
+void Sys_FileSeek (int handle, int position)
+{
+       Qseek (sys_handles[handle], position, SEEK_SET);
+}
+
+int Sys_FileRead (int handle, void *dest, int count)
+{
+       return Qread (sys_handles[handle], dest, count);
+}
+
+int Sys_FileWrite (int handle, void *data, int count)
+{
+       return Qwrite (sys_handles[handle], data, count);
+}
+
+int Sys_FileTime (const char *path)
+{
+#if WIN32
+       QFile *f;
+
+       f = Qopen(path, "rb");
+       if (f)
+       {
+               Qclose(f);
+               return 1;
+       }
+
+       return -1;
+#else
+       struct stat buf;
+
+       if (stat (path,&buf) == -1)
+               return -1;
+
+       return buf.st_mtime;
+#endif
+}
+
+void Sys_mkdir (const char *path)
+{
+#if WIN32
+       _mkdir (path);
+#else
+       mkdir (path, 0777);
+#endif
+}
+
 char engineversion[128];
 
 void Sys_Shared_EarlyInit(void)
index 151565564a33cbcccd3ddc51cf212ee742a2199e..5bd55f902cf5babb09e16b5d8c93caa14ade9318 100644 (file)
--- a/sys_win.c
+++ b/sys_win.c
@@ -45,130 +45,6 @@ static HANDLE       hFile;
 static HANDLE  heventParent;
 static HANDLE  heventChild;
 
-/*
-===============================================================================
-
-QFile IO
-
-===============================================================================
-*/
-
-// LordHavoc: 256 pak files (was 10)
-#define        MAX_HANDLES             256
-QFile  *sys_handles[MAX_HANDLES];
-
-int            findhandle (void)
-{
-       int             i;
-
-       for (i=1 ; i<MAX_HANDLES ; i++)
-               if (!sys_handles[i])
-                       return i;
-       Sys_Error ("out of handles");
-       return -1;
-}
-
-/*
-================
-Sys_FileLength
-================
-*/
-int Sys_FileLength (QFile *f)
-{
-       int             pos;
-       int             end;
-
-       pos = Qtell (f);
-       Qseek (f, 0, SEEK_END);
-       end = Qtell (f);
-       Qseek (f, pos, SEEK_SET);
-
-       return end;
-}
-
-int Sys_FileOpenRead (char *path, int *hndl)
-{
-       QFile   *f;
-       int             i, retval;
-
-       i = findhandle ();
-
-       f = Qopen(path, "rbz");
-
-       if (!f)
-       {
-               *hndl = -1;
-               retval = -1;
-       }
-       else
-       {
-               sys_handles[i] = f;
-               *hndl = i;
-               retval = Sys_FileLength(f);
-       }
-
-       return retval;
-}
-
-int Sys_FileOpenWrite (char *path)
-{
-       QFile   *f;
-       int             i;
-
-       i = findhandle ();
-
-       f = Qopen(path, "wb");
-       if (!f)
-       {
-               Con_Printf("Sys_FileOpenWrite: Error opening %s: %s", path, strerror(errno));
-               return 0;
-       }
-       sys_handles[i] = f;
-
-       return i;
-}
-
-void Sys_FileClose (int handle)
-{
-       Qclose (sys_handles[handle]);
-       sys_handles[handle] = NULL;
-}
-
-void Sys_FileSeek (int handle, int position)
-{
-       Qseek (sys_handles[handle], position, SEEK_SET);
-}
-
-int Sys_FileRead (int handle, void *dest, int count)
-{
-       return Qread (sys_handles[handle], dest, count);
-}
-
-int Sys_FileWrite (int handle, void *data, int count)
-{
-       return Qwrite (sys_handles[handle], data, count);
-}
-
-int    Sys_FileTime (char *path)
-{
-       QFile   *f;
-
-       f = Qopen(path, "rb");
-       if (f)
-       {
-               Qclose(f);
-               return 1;
-       }
-
-       return -1;
-}
-
-void Sys_mkdir (char *path)
-{
-       _mkdir (path);
-}
-
-
 /*
 ===============================================================================
 
@@ -179,7 +55,7 @@ SYSTEM IO
 
 void SleepUntilInput (int time);
 
-void Sys_Error (char *error, ...)
+void Sys_Error (const char *error, ...)
 {
        va_list         argptr;
        char            text[1024], text2[1024];
@@ -521,17 +397,10 @@ int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLin
                                *lpCmdLine = 0;
                                lpCmdLine++;
                        }
-
                }
        }
-
        host_parms.argv = argv;
 
-       COM_InitArgv (host_parms.argc, host_parms.argv);
-
-       host_parms.argc = com_argc;
-       host_parms.argv = com_argv;
-
        Sys_Shared_EarlyInit();
 
        Cvar_RegisterVariable(&sys_usetimegettime);