1 /* 2 sys.h 3 4 non-portable functions 5 6 Copyright (C) 1996-1997 Id Software, Inc. 7 8 This program is free software; you can redistribute it and/or 9 modify it under the terms of the GNU General Public License 10 as published by the Free Software Foundation; either version 2 11 of the License, or (at your option) any later version. 12 13 This program is distributed in the hope that it will be useful, 14 but WITHOUT ANY WARRANTY; without even the implied warranty of 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 16 17 See the GNU General Public License for more details. 18 19 You should have received a copy of the GNU General Public License 20 along with this program; if not, write to: 21 22 Free Software Foundation, Inc. 23 59 Temple Place - Suite 330 24 Boston, MA 02111-1307, USA 25 26 */ 27 28 #ifndef __sys_h 29 #define __sys_h 30 31 /** \defgroup sys Portability 32 \ingroup utils 33 Non-portable functions 34 */ 35 //@{ 36 37 #include <stdio.h> 38 #include <stdint.h> 39 #include <stdarg.h> 40 41 extern struct cvar_s *sys_nostdout; 42 extern struct cvar_s *sys_extrasleep; 43 extern struct cvar_s *sys_dead_sleep; 44 extern struct cvar_s *sys_sleep; 45 46 extern struct cvar_s *developer; 47 48 49 extern const char sys_char_map[256]; 50 51 typedef struct date_s { 52 int sec; 53 int min; 54 int hour; 55 int day; 56 int mon; 57 int year; 58 char str[128]; 59 } date_t; 60 61 int Sys_FileTime (const char *path); 62 int Sys_mkdir (const char *path); 63 64 typedef void (*sys_printf_t) (const char *fmt, va_list args); 65 66 void Sys_SetStdPrintf (sys_printf_t func); 67 void Sys_SetErrPrintf (sys_printf_t func); 68 69 void Sys_Print (FILE *stream, const char *fmt, va_list args); 70 void Sys_Printf (const char *fmt, ...) __attribute__((format(printf,1,2))); 71 void Sys_Error (const char *error, ...) __attribute__((format(printf,1,2), noreturn)); 72 void Sys_Quit (void) __attribute__((noreturn)); 73 void Sys_Shutdown (void); 74 void Sys_RegisterShutdown (void (*func) (void)); 75 double Sys_DoubleTime (void); 76 void Sys_TimeOfDay(date_t *date); 77 78 void Sys_MaskPrintf (int mask, const char *fmt, ...) __attribute__((format(printf,2,3))); 79 #define SYS_DEV (1|0) 80 #define SYS_WARN (1|2) // bit 0 so developer 1 will pick it up 81 #define SYS_VID (1|4) 82 #define SYS_FS_NF (1|8) 83 #define SYS_FS_F (1|16) 84 #define SYS_FS (1|32) 85 #define SYS_NET (1|64) 86 #define SYS_RUA_OBJ (1|128) 87 #define SYS_RUA_MSG (1|256) 88 #define SYS_SND (1|512) 89 #define SYS_GLT (1|1024) 90 #define SYS_GLSL (1|2048) 91 #define SYS_SKIN (1|4096) 92 #define SYS_MODEL (1|8192) 93 94 int Sys_CheckInput (int idle, int net_socket); 95 const char *Sys_ConsoleInput (void); 96 97 void Sys_Sleep (void); 98 99 int Sys_TimeID (void); 100 // called to yield for a little bit so as 101 // not to hog cpu when paused or debugging 102 103 void Sys_MaskFPUExceptions (void); 104 void Sys_PushSignalHook (int (*hook)(int, void*), void *data); 105 void Sys_PopSignalHook (void); 106 107 // send text to the console 108 109 void Sys_Init (void); 110 void Sys_Init_Cvars (void); 111 112 // 113 // memory protection 114 // 115 void Sys_MakeCodeWriteable (uintptr_t startaddr, size_t length); 116 void Sys_PageIn (void *ptr, int size); 117 118 // 119 // system IO 120 // 121 void Sys_DebugLog(const char *file, const char *fmt, ...) __attribute__((format(printf,2,3))); 122 123 #define SYS_CHECKMEM(x) \ 124 do { \ 125 if (!(x)) \ 126 Sys_Error ("%s: Failed to allocate memory.", __FUNCTION__); \ 127 } while (0) 128 129 /** Create all parent directories leading to the file specified by path. 130 131 \param path The path to create. 132 \return 0 on success, -1 on failure. 133 134 \note No directory will be created for the name after the final 135 <code>/</code>. This is to allow the same path string to be used for 136 both this function and Qopen. 137 */ 138 int Sys_CreatePath (const char *path); 139 140 /** Expand leading "~/" in \a path to the user's home directory. 141 On Linux-like systems, the user's home directory is obtained from the 142 system, or failing that, the \c HOME environment variable. 143 144 On Windows systems, first the \c HOME environment variable is checked. 145 If \c HOME is not set, \c WINDIR is used. 146 147 \param path the path to check for "~/" 148 \return the expanded path 149 \note It is the caller's responsibility to free the returned string. 150 */ 151 char *Sys_ExpandSquiggle (const char *path); 152 153 //@} 154 155 #endif // __sys_h 156