26 char *cachedir = "/tmp";
29 // =======================================================================
31 // =======================================================================
33 void Sys_DebugNumber(int y, int val)
40 fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) & ~FNDELAY);
45 void Sys_Error (char *error, ...)
50 // change stdin to non blocking
51 fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) & ~FNDELAY);
53 va_start (argptr,error);
54 vsprintf (string,error,argptr);
56 fprintf(stderr, "Error: %s\n", string);
63 void Sys_Warn (char *warning, ...)
68 va_start (argptr,warning);
69 vsprintf (string,warning,argptr);
71 fprintf(stderr, "Warning: %s", string);
78 returns -1 if not present
81 int Sys_FileTime (char *path)
85 if (stat (path,&buf) == -1)
92 void Sys_mkdir (char *path)
97 int Sys_FileOpenRead (char *path, int *handle)
100 struct stat fileinfo;
103 h = open (path, O_RDONLY, 0666);
108 if (fstat (h,&fileinfo) == -1)
109 Sys_Error ("Error fstating %s", path);
111 return fileinfo.st_size;
114 int Sys_FileOpenWrite (char *path)
120 handle = open(path,O_RDWR | O_CREAT | O_TRUNC, 0666);
124 Con_Printf("Sys_FileOpenWrite: Error opening %s: %s", path, strerror(errno));
131 int Sys_FileWrite (int handle, void *src, int count)
133 return write (handle, src, count);
136 void Sys_FileClose (int handle)
141 void Sys_FileSeek (int handle, int position)
143 lseek (handle, position, SEEK_SET);
146 int Sys_FileRead (int handle, void *dest, int count)
148 return read (handle, dest, count);
151 void Sys_DebugLog(char *file, char *fmt, ...)
154 static char data[1024];
157 va_start(argptr, fmt);
158 vsprintf(data, fmt, argptr);
160 fd = open(file, O_WRONLY | O_CREAT | O_APPEND, 0666);
161 write(fd, data, strlen(data));
165 double Sys_DoubleTime (void)
167 static int first = true;
168 static double oldtime = 0.0, basetime = 0.0;
173 gettimeofday(&tp, &tzp);
175 newtime = (double) ((unsigned long) tp.tv_sec) + tp.tv_usec/1000000.0 - basetime;
184 if (newtime < oldtime)
185 Sys_Error("Sys_DoubleTime: time running backwards??\n");
192 // =======================================================================
193 // Sleeps for microseconds
194 // =======================================================================
196 static volatile int oktogo;
198 void alarm_handler(int x)
203 void floating_point_exception_handler(int whatever)
205 signal(SIGFPE, floating_point_exception_handler);
208 char *Sys_ConsoleInput(void)
210 static char text[256];
213 struct timeval timeout;
215 if (cls.state == ca_dedicated) {
217 FD_SET(0, &fdset); // stdin
220 if (select (1, &fdset, NULL, NULL, &timeout) == -1 || !FD_ISSET(0, &fdset))
223 len = read (0, text, sizeof(text));
226 text[len-1] = 0; // rip off the /n and terminate
238 int main (int c, char **v)
241 double oldtime, newtime;
243 signal(SIGFPE, SIG_IGN);
245 memset(&host_parms, 0, sizeof(host_parms));
248 host_parms.argc = com_argc;
249 host_parms.argv = com_argv;
251 host_parms.basedir = basedir;
253 fcntl(0, F_SETFL, fcntl (0, F_GETFL, 0) | FNDELAY);
255 Sys_Shared_EarlyInit();
259 Sys_Shared_LateInit();
261 oldtime = Sys_DoubleTime () - 0.1;
264 // find time spent rendering last frame
265 newtime = Sys_DoubleTime ();
267 Host_Frame (newtime - oldtime);