// 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);
// General routines
// =======================================================================
-void Sys_DebugNumber(int y, int val)
-{
-}
-
void Sys_Quit (void)
{
Host_Shutdown();
exit(0);
}
-void Sys_Error (char *error, ...)
+void Sys_Error (const char *error, ...)
{
va_list argptr;
char string[1024];
}
-void Sys_Warn (char *warning, ...)
+void Sys_Warn (const char *warning, ...)
{
va_list argptr;
char string[1024];
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;
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);
#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;
#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
#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)
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);
-}
-
-
/*
===============================================================================
void SleepUntilInput (int time);
-void Sys_Error (char *error, ...)
+void Sys_Error (const char *error, ...)
{
va_list argptr;
char text[1024], text2[1024];
*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);