]> git.xonotic.org Git - xonotic/darkplaces.git/blob - sys_unix.c
deduplicate Sys_ConsoleInput()
[xonotic/darkplaces.git] / sys_unix.c
1
2 #ifdef WIN32
3 #include <windows.h>
4 #include <mmsystem.h>
5 #include <io.h>
6 #else
7 #include <sys/time.h>
8 #include <unistd.h>
9 #include <fcntl.h>
10 #endif
11
12 #include "darkplaces.h"
13
14 sys_t sys;
15
16 // =======================================================================
17 // General routines
18 // =======================================================================
19 void Sys_Shutdown (void)
20 {
21 #ifndef WIN32
22         fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) & ~O_NONBLOCK);
23 #endif
24         fflush(stdout);
25 }
26
27 void Sys_Error (const char *error, ...)
28 {
29         va_list argptr;
30         char string[MAX_INPUTLINE];
31
32 // change stdin to non blocking
33 #ifndef WIN32
34         fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) & ~O_NONBLOCK);
35 #endif
36         va_start (argptr,error);
37         dpvsnprintf (string, sizeof (string), error, argptr);
38         va_end (argptr);
39
40         Con_Printf(CON_ERROR "Engine Error: %s\n", string);
41
42         //Host_Shutdown ();
43         exit (1);
44 }
45
46 void Sys_Print(const char *text)
47 {
48         if(sys.outfd < 0)
49                 return;
50         // BUG: for some reason, NDELAY also affects stdout (1) when used on stdin (0).
51         // this is because both go to /dev/tty by default!
52         {
53 #ifndef WIN32
54                 int origflags = fcntl (sys.outfd, F_GETFL, 0);
55                 fcntl (sys.outfd, F_SETFL, origflags & ~O_NONBLOCK);
56 #else
57 #define write _write
58 #endif
59                 while(*text)
60                 {
61                         fs_offset_t written = (fs_offset_t)write(sys.outfd, text, (int)strlen(text));
62                         if(written <= 0)
63                                 break; // sorry, I cannot do anything about this error - without an output
64                         text += written;
65                 }
66 #ifndef WIN32
67                 fcntl (sys.outfd, F_SETFL, origflags);
68 #endif
69         }
70         //fprintf(stdout, "%s", text);
71 }
72
73 char *Sys_GetClipboardData (void)
74 {
75         return NULL;
76 }
77
78 void Sys_SDL_Init(void)
79 {
80 }
81
82 qbool sys_supportsdlgetticks = false;
83 unsigned int Sys_SDL_GetTicks (void)
84 {
85         Sys_Error("Called Sys_SDL_GetTicks on non-SDL target");
86         return 0;
87 }
88 void Sys_SDL_Delay (unsigned int milliseconds)
89 {
90         Sys_Error("Called Sys_SDL_Delay on non-SDL target");
91 }