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_BINARY | O_CREAT | O_APPEND, 0666);
161 fd = open(file, O_WRONLY | O_CREAT | O_APPEND, 0666);
162 write(fd, data, strlen(data));
166 double Sys_DoubleTime (void)
168 static int first = true;
169 static double oldtime = 0.0, basetime = 0.0;
174 gettimeofday(&tp, &tzp);
176 newtime = (double) ((unsigned long) tp.tv_sec) + tp.tv_usec/1000000.0 - basetime;
185 if (newtime < oldtime)
186 Sys_Error("Sys_DoubleTime: time running backwards??\n");
193 // =======================================================================
194 // Sleeps for microseconds
195 // =======================================================================
197 static volatile int oktogo;
199 void alarm_handler(int x)
204 void floating_point_exception_handler(int whatever)
206 // Sys_Warn("floating point exception\n");
207 signal(SIGFPE, floating_point_exception_handler);
210 char *Sys_ConsoleInput(void)
212 static char text[256];
215 struct timeval timeout;
217 if (cls.state == ca_dedicated) {
219 FD_SET(0, &fdset); // stdin
222 if (select (1, &fdset, NULL, NULL, &timeout) == -1 || !FD_ISSET(0, &fdset))
225 len = read (0, text, sizeof(text));
228 text[len-1] = 0; // rip off the /n and terminate
240 int main (int c, char **v)
243 double oldtime, newtime;
245 // static char cwd[1024];
247 // signal(SIGFPE, floating_point_exception_handler);
248 signal(SIGFPE, SIG_IGN);
250 memset(&host_parms, 0, sizeof(host_parms));
253 host_parms.argc = com_argc;
254 host_parms.argv = com_argv;
256 host_parms.basedir = basedir;
258 fcntl(0, F_SETFL, fcntl (0, F_GETFL, 0) | FNDELAY);
260 Sys_Shared_EarlyInit();
264 Sys_Shared_LateInit();
266 oldtime = Sys_DoubleTime () - 0.1;
269 // find time spent rendering last frame
270 newtime = Sys_DoubleTime ();
272 Host_Frame (newtime - oldtime);