diff --git a/common/sys_common.c b/common/sys_common.c index a6545cc..fe71fe8 100644 --- a/common/sys_common.c +++ b/common/sys_common.c @@ -33,6 +33,12 @@ #ifdef HAVE_SYS_STAT_H # include #endif +#ifdef HAVE_SYS_TIME_H +# include +#endif +#ifdef HAVE_SYS_TIMEB_H +# include +#endif int nostdout = 0; @@ -68,6 +74,23 @@ void Sys_Printf (char *fmt, ...) } +/* +================ +Sys_mkdir +================ +*/ +void Sys_mkdir (char *path) +{ +#if defined(_WIN32) + _mkdir(path); +#elif defined(HAVE_MKDIR) + mkdir(path, 0777); +#else +# warning No mkdir() - creating directories will not be possible +#endif +} + + /* ============ Sys_FileTime @@ -100,3 +123,41 @@ int Sys_FileTime (char *path) return ret; } + + +/* +================ +Sys_DoubleTime +================ +*/ +double Sys_DoubleTime(void) +{ + static int starttime = 0; + long secs, usecs; + +#if defined(HAVE_GETTIMEOFDAY) + struct timeval tp; + + gettimeofday(&tp, NULL); + secs = tp.tv_sec; + usecs = tp.tv_usec; +#elif defined(HAVE_FTIME) + struct timeb tstruct; + + ftime(&tstruct); + secs = tstruct.time; + usecs = tstruct.millitm*1000; +#elif defined(HAVE__FTIME) + struct _timeb tstruct; + + _ftime(&tstruct); + secs = tstruct.time; + usecs = tstruct.millitm*1000; +#else +# error You need to implement Sys_DoubleTime() +#endif + + if (!starttime) starttime = secs; + + return (secs - starttime) + usecs/1000000.0; +} diff --git a/common/sys_linux.c b/common/sys_linux.c index aec1b70..944fec0 100644 --- a/common/sys_linux.c +++ b/common/sys_linux.c @@ -104,10 +104,6 @@ void Sys_Warn (char *warning, ...) { fprintf(stderr, "Warning: %s", string); } -void Sys_mkdir (char *path) { - mkdir (path, 0777); -} - int Sys_FileOpenRead (char *path, int *handle) { int h; @@ -190,21 +186,6 @@ void Sys_EditFile(char *filename) { } } -double Sys_DoubleTime (void) { - - struct timeval tp; - struct timezone tzp; - static int secbase; - - gettimeofday(&tp, &tzp); - - if (!secbase) { - secbase = tp.tv_sec; - return tp.tv_usec/1000000.0; - } - return (tp.tv_sec - secbase) + tp.tv_usec/1000000.0; -} - // ======================================================================= // Sleeps for microseconds // ======================================================================= diff --git a/common/sys_null.c b/common/sys_null.c index 65457b6..19b330e 100644 --- a/common/sys_null.c +++ b/common/sys_null.c @@ -115,11 +115,6 @@ int Sys_FileWrite (int handle, void *data, int count) return fwrite (data, 1, count, sys_handles[handle]); } -void Sys_mkdir (char *path) -{ -} - - /* System I/O */ @@ -150,15 +145,6 @@ void Sys_Quit (void) exit (0); } -double Sys_DoubleTime (void) -{ - static double t; - - t += 0.1; - - return t; -} - char *Sys_ConsoleInput (void) { return NULL; diff --git a/qw_client/sys_win.c b/qw_client/sys_win.c index 9716414..73a5fdc 100644 --- a/qw_client/sys_win.c +++ b/qw_client/sys_win.c @@ -97,12 +97,6 @@ int filelength (FILE *f) #endif -void Sys_mkdir (char *path) -{ - _mkdir (path); -} - - /* =============================================================================== @@ -337,30 +331,6 @@ void Sys_InitFloatTime (void) #endif -double Sys_DoubleTime (void) -{ - static DWORD starttime; - static qboolean first = true; - DWORD now; - double t; - - now = timeGetTime(); - - if (first) { - first = false; - starttime = now; - return 0.0; - } - - if (now < starttime) // wrapped? - return (now / 1000.0) + (LONG_MAX - starttime / 1000.0); - - if (now - starttime == 0) - return 0.0; - - return (now - starttime) / 1000.0; -} - char *Sys_ConsoleInput (void) { static char text[256]; diff --git a/qw_server/sys_unix.c b/qw_server/sys_unix.c index 076ca7b..ec58a65 100644 --- a/qw_server/sys_unix.c +++ b/qw_server/sys_unix.c @@ -47,43 +47,6 @@ qboolean stdin_ready; =============================================================================== */ -/* -============ -Sys_mkdir - -============ -*/ -void Sys_mkdir (char *path) -{ - if (mkdir (path, 0777) != -1) - return; - if (errno != EEXIST) - Sys_Error ("mkdir %s: %s",path, strerror(errno)); -} - - -/* -================ -Sys_DoubleTime -================ -*/ -double Sys_DoubleTime (void) -{ - struct timeval tp; - struct timezone tzp; - static int secbase; - - gettimeofday(&tp, &tzp); - - if (!secbase) - { - secbase = tp.tv_sec; - return tp.tv_usec/1000000.0; - } - - return (tp.tv_sec - secbase) + tp.tv_usec/1000000.0; -} - /* ================ Sys_Error diff --git a/qw_server/sys_win.c b/qw_server/sys_win.c index 6c3d6cb..6cee9ad 100644 --- a/qw_server/sys_win.c +++ b/qw_server/sys_win.c @@ -26,17 +26,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. extern cvar_t sys_nostdout; -/* -================ -Sys_mkdir -================ -*/ -void Sys_mkdir (char *path) -{ - _mkdir(path); -} - - /* ================ Sys_Error @@ -58,27 +47,6 @@ void Sys_Error (char *error, ...) } -/* -================ -Sys_DoubleTime -================ -*/ -double Sys_DoubleTime (void) -{ - double t; - struct _timeb tstruct; - static int starttime; - - _ftime( &tstruct ); - - if (!starttime) - starttime = tstruct.time; - t = (tstruct.time-starttime) + tstruct.millitm*0.001; - - return t; -} - - /* ================ Sys_ConsoleInput diff --git a/uquake/sys_unix.c b/uquake/sys_unix.c index 1a0b80b..a3a7bc7 100644 --- a/uquake/sys_unix.c +++ b/uquake/sys_unix.c @@ -173,11 +173,6 @@ int Sys_FileWrite (int handle, void *data, int count) return fwrite (data, 1, count, sys_handles[handle].hFile); } -void Sys_mkdir (char *path) -{ - mkdir( path, 0777 ); -} - /* =============================================================================== @@ -225,23 +220,6 @@ void Sys_Quit (void) exit (0); } -double Sys_DoubleTime (void) -{ - struct timeval tp; - struct timezone tzp; - static int secbase; - - gettimeofday(&tp, &tzp); - - if (!secbase) - { - secbase = tp.tv_sec; - return tp.tv_usec/1000000.0; - } - - return (tp.tv_sec - secbase) + tp.tv_usec/1000000.0; -} - char *Sys_ConsoleInput (void) { static char text[256]; diff --git a/uquake/sys_win.c b/uquake/sys_win.c index 286a042..de5a657 100644 --- a/uquake/sys_win.c +++ b/uquake/sys_win.c @@ -222,11 +222,6 @@ int Sys_FileWrite (int handle, void *data, int count) return x; } -void Sys_mkdir (char *path) -{ - _mkdir (path); -} - /* =============================================================================== @@ -519,30 +514,6 @@ void Sys_InitFloatTime (void) } #endif -double Sys_DoubleTime (void) -{ - static DWORD starttime; - static qboolean first = true; - DWORD now; - double t; - - now = timeGetTime(); - - if (first) { - first = false; - starttime = now; - return 0.0; - } - - if (now < starttime) // wrapped? - return (now / 1000.0) + (LONG_MAX - starttime / 1000.0); - - if (now - starttime == 0) - return 0.0; - - return (now - starttime) / 1000.0; -} - char *Sys_ConsoleInput (void) { static char text[256]; diff --git a/uquake/sys_wind.c b/uquake/sys_wind.c index 7bef114..26f0202 100644 --- a/uquake/sys_wind.c +++ b/uquake/sys_wind.c @@ -121,11 +121,6 @@ int Sys_FileWrite (int handle, void *data, int count) return fwrite (data, 1, count, sys_handles[handle]); } -void Sys_mkdir (char *path) -{ -} - - /* =============================================================================== @@ -163,21 +158,6 @@ void Sys_Quit (void) exit (0); } -double Sys_DoubleTime (void) -{ - double t; - struct _timeb tstruct; - static int starttime; - - _ftime( &tstruct ); - - if (!starttime) - starttime = tstruct.time; - t = (tstruct.time-starttime) + tstruct.millitm*0.001; - - return t; -} - void Sys_Sleep (void) { }