nux-1.14.0
|
00001 /* 00002 * Copyright 2010 Inalogic® Inc. 00003 * 00004 * This program is free software: you can redistribute it and/or modify it 00005 * under the terms of the GNU Lesser General Public License, as 00006 * published by the Free Software Foundation; either version 2.1 or 3.0 00007 * of the License. 00008 * 00009 * This program is distributed in the hope that it will be useful, but 00010 * WITHOUT ANY WARRANTY; without even the implied warranties of 00011 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR 00012 * PURPOSE. See the applicable version of the GNU Lesser General Public 00013 * License for more details. 00014 * 00015 * You should have received a copy of both the GNU Lesser General Public 00016 * License along with this program. If not, see <http://www.gnu.org/licenses/> 00017 * 00018 * Authored by: Jay Taoko <jaytaoko@inalogic.com> 00019 * 00020 */ 00021 00022 00023 #ifndef SYSTEMGNU_H 00024 #define SYSTEMGNU_H 00025 00026 #include <utime.h> 00027 #include <unistd.h> 00028 #include <sys/time.h> 00029 #include <sys/types.h> 00030 #include <sys/stat.h> 00031 #include <sys/syscall.h> 00032 #include <errno.h> 00033 #include <sched.h> 00034 #include <inttypes.h> 00035 #include <fcntl.h> 00036 00037 #include <glib.h> 00038 #include <pthread.h> 00039 00040 // If NUX_LOG_FILE_ANSI is set to 1, log files will be written in ASCII characters even when in UNICODE. 00041 #define NUX_LOG_FILE_ANSI 1 00042 00043 00044 #define NUX_VARARGS __cdecl // Functions with variable arguments 00045 00046 // Calling Convention 00047 // This is the default calling convention for C and C++ programs. 00048 // Because the stack is cleaned up by the caller, it can do vararg functions. 00049 // Argument-passing order: Right to left 00050 #define NUX_CDECL __cdecl 00051 // The __stdcall calling convention is used to call Win32 API functions. 00052 // The callee cleans the stack, so the compiler makes vararg functions __cdecl. 00053 // Argument-passing order: Right to left 00054 #define NUX_STDCALL __stdcall 00055 // The __fastcall calling convention specifies that arguments to functions are to be passed in registers, when possible. 00056 #define NUX_FASTCALL __fastcall 00057 // This is the default calling convention used by C++ member functions that do not use variable arguments. 00058 // Under thiscall, the callee cleans the stack, which is impossible for vararg functions. 00059 #define NUX_THISCALL thiscall // 00060 00061 #define NUX_INLINE inline // Force inline code 00062 #define NUX_FORCEINLINE inline //__attribute__ ((__always_inline)) // Force inline code 00063 #define NUX_FORCENOINLINE __attribute__ ((noinline)) // Force code to NOT be inline 00064 00065 00066 // Unsigned base types. 00067 typedef unsigned char BOOL; // 8-bit unsigned. 00068 typedef unsigned char BYTE; // 8-bit unsigned. 00069 typedef unsigned short WORD; // 16-bit unsigned. 00070 typedef unsigned int UINT; // 32-bit unsigned. 00071 typedef unsigned long DWORD; // 32-bit unsigned. 00072 typedef uint64_t QWORD; // 64-bit unsigned. 00073 00074 // Signed base types. 00075 typedef signed char SBYTE; // 8-bit signed. 00076 typedef signed short SWORD; // 16-bit signed. 00077 typedef signed int INT; // 32-bit signed. 00078 typedef int64_t SQWORD; // 64-bit signed. 00079 00080 00081 // Character types. 00082 typedef char ANSICHAR; // An ANSI character. 00083 typedef unsigned char ANSIUCHAR; // An ANSI character. 00084 typedef wchar_t UNICHAR; // A unicode character. 00085 00086 // Other base types. 00087 typedef float FLOAT; // 32-bit IEEE floating point. 00088 typedef double DOUBLE; // 64-bit IEEE double. 00089 typedef unsigned long SIZE_T; // Corresponds to C SIZE_T. 00090 00092 // UNICODE // 00094 #ifdef NUX_UNICODE 00095 typedef UNICHAR TCHAR; 00096 #undef TEXT 00097 #define TEXT(s) L##s 00098 #else 00099 typedef ANSICHAR TCHAR; 00100 #undef TEXT 00101 #define TEXT(s) s 00102 #endif 00103 00104 00105 #ifdef NUX_UNICODE 00106 #define WINE_tchar_true(a) (1) 00107 #define WINE_tchar_false(a) (0) 00108 #define WINE_tchar_tclen(a) (1) 00109 #define WINE_tchar_tccpy(a,b) do { *(a)=*(b); } while (0) 00110 #else 00111 #define WINE_tchar_true(a) (1) 00112 #define WINE_tchar_false(a) (0) 00113 #define WINE_tchar_tclen(a) (1) 00114 #define WINE_tchar_tccpy(a,b) do { *(a)=*(b); } while (0) 00115 #endif 00116 00117 #ifndef NUX_UNICODE 00118 #ifndef NUX_MBCS 00119 #define NUX_TCHAR_ROUTINE(ansi, mbcs, unicode) ansi 00120 #else 00121 #define NUX_TCHAR_ROUTINE(ansi, mbcs, unicode) mbcs 00122 #endif 00123 #else 00124 #define NUX_TCHAR_ROUTINE(ansi, mbcs, unicode) unicode 00125 #endif 00126 00127 00128 #define NUX_UNIX_SYS_HOST_ROOT TEXT("/") 00129 #define NUX_UNIX_SYS_HOME TEXT("/home") 00130 00132 #define __targv NUX_TCHAR_ROUTINE(__argv, __argv, __wargv) 00133 #define _fgettc NUX_TCHAR_ROUTINE(fgetc, fgetc, fgetwc) 00134 #define _fgettchar NUX_TCHAR_ROUTINE(fgetchar, fgetchar, _fgetwchar) 00135 #define _fgetts NUX_TCHAR_ROUTINE(fgets, fgets, fgetws) 00136 #define _fputtc NUX_TCHAR_ROUTINE(fputc, fputc, fputwc) 00137 #define _fputtchar NUX_TCHAR_ROUTINE(fputchar, fputchar, _fputwchar) 00138 #define _fputts NUX_TCHAR_ROUTINE(fputs, fputs, fputws) 00139 #define _ftprintf NUX_TCHAR_ROUTINE(fprintf, fprintf, fwprintf) 00140 #define _ftscanf NUX_TCHAR_ROUTINE(fscanf, fscanf, fwscanf) 00141 #define _gettc NUX_TCHAR_ROUTINE(getc, getc, getwc) 00142 #define _gettchar NUX_TCHAR_ROUTINE(getchar, getchar, getwchar) 00143 #define _getts NUX_TCHAR_ROUTINE(gets, gets, getws) 00144 #define _isalnum NUX_TCHAR_ROUTINE(isalnum, _ismbcalnum, iswalnum) 00145 #define _istalpha NUX_TCHAR_ROUTINE(isalpha, _ismbcalpha, iswalpha) 00146 #define _istascii NUX_TCHAR_ROUTINE(isascii, __isascii, iswascii) 00147 #define _istcntrl NUX_TCHAR_ROUTINE(iscntrl, iscntrl, iswcntrl) 00148 #define _istdigit NUX_TCHAR_ROUTINE(isdigit, _ismbcdigit, iswdigit) 00149 #define _istgraph NUX_TCHAR_ROUTINE(isgraph, _ismbcgraph, iswgraph) 00150 #define _istlead NUX_TCHAR_ROUTINE(WINE_tchar_false,_ismbblead, WINE_tchar_false) 00151 #define _istleadbyte NUX_TCHAR_ROUTINE(WINE_tchar_false,isleadbyte, WINE_tchar_false) 00152 #define _istlegal NUX_TCHAR_ROUTINE(WINE_tchar_true, _ismbclegal, WINE_tchar_true) 00153 #define _istlower NUX_TCHAR_ROUTINE(islower, _ismbcslower,iswlower) 00154 #define _istprint NUX_TCHAR_ROUTINE(isprint, _ismbcprint, iswprint) 00155 #define _istpunct NUX_TCHAR_ROUTINE(ispunct, _ismbcpunct, iswpunct) 00156 #define _istspace NUX_TCHAR_ROUTINE(isspace, _ismbcspace, iswspace) 00157 #define _istupper NUX_TCHAR_ROUTINE(isupper, _ismbcupper, iswupper) 00158 #define _istxdigit NUX_TCHAR_ROUTINE(isxdigit, isxdigit, iswxdigit) 00159 #define _itot NUX_TCHAR_ROUTINE(_itoa, _itoa, _itow) 00160 #define _ltot NUX_TCHAR_ROUTINE(_ltoa, _ltoa, _ltow) 00161 #define _puttc NUX_TCHAR_ROUTINE(putc, putc, putwc) 00162 #define _puttchar NUX_TCHAR_ROUTINE(putchar, putchar, putwchar) 00163 #define _putts NUX_TCHAR_ROUTINE(puts, puts, putws) 00164 #define _sntprintf NUX_TCHAR_ROUTINE(sprintf, sprintf, swprintf) 00165 #define _stprintf NUX_TCHAR_ROUTINE(sprintf, sprintf, swprintf) 00166 #define _stscanf NUX_TCHAR_ROUTINE(sscanf, sscanf, swscanf) 00167 #define _taccess NUX_TCHAR_ROUTINE(access, _access, _waccess) 00168 #define _tasctime NUX_TCHAR_ROUTINE(asctime, asctime, _wasctime) 00169 #define _tccpy NUX_TCHAR_ROUTINE(WINE_tchar_tccpy,_mbccpy, WINE_tchar_tccpy) 00170 #define _tchdir NUX_TCHAR_ROUTINE(chdir, _chdir, _wchdir) 00171 #define _tclen NUX_TCHAR_ROUTINE(WINE_tchar_tclen,_mbclen, WINE_tchar_tclen) 00172 #define _tchmod NUX_TCHAR_ROUTINE(chmod, _chmod, _wchmod) 00173 #define _tcreat NUX_TCHAR_ROUTINE(creat, _creat, _wcreat) 00174 #define _tcscat NUX_TCHAR_ROUTINE(strcat, _mbscat, wcscat) 00175 #define _tcschr NUX_TCHAR_ROUTINE(strchr, _mbschr, wcschr) 00176 #define _tcsclen NUX_TCHAR_ROUTINE(strlen, _mbslen, wcslen) 00177 #define _tcscmp NUX_TCHAR_ROUTINE(strcmp, _mbscmp, wcscmp) 00178 #define _tcscoll NUX_TCHAR_ROUTINE(strcoll, _mbscoll, wcscoll) 00179 #define _tcscpy NUX_TCHAR_ROUTINE(strcpy, _mbscpy, wcscpy) 00180 #define _tcscspn NUX_TCHAR_ROUTINE(strcspn, _mbscspn, wcscspn) 00181 #define _tcsdec NUX_TCHAR_ROUTINE(_strdec, _mbsdec, _wcsdec) 00182 #define _tcsdup NUX_TCHAR_ROUTINE(strdup, _mbsdup, _wcsdup) 00183 #define _tcsftime NUX_TCHAR_ROUTINE(strftime, strftime, wcsftime) 00184 #define _tcsicmp NUX_TCHAR_ROUTINE(strcasecmp, _mbsicmp, _wcsicmp) 00185 #define _tcsicoll NUX_TCHAR_ROUTINE(_stricoll, _stricoll, _wcsicoll) 00186 #define _tcsinc NUX_TCHAR_ROUTINE(_strinc, _mbsinc, _wcsinc) 00187 #define _tcslen NUX_TCHAR_ROUTINE(strlen, strlen, wcslen) 00188 #define _tcslwr NUX_TCHAR_ROUTINE(strlwr, _mbslwr, wcslwr) 00189 #define _tcsnbcnt NUX_TCHAR_ROUTINE(_strncnt, _mbsnbcnt, _wcnscnt) 00190 #define _tcsncat NUX_TCHAR_ROUTINE(strncat, _mbsnbcat, wcsncat) 00191 #define _tcsnccat NUX_TCHAR_ROUTINE(strncat, _mbsncat, wcsncat) 00192 #define _tcsncmp NUX_TCHAR_ROUTINE(strncmp, _mbsnbcmp, wcsncmp) 00193 #define _tcsnccmp NUX_TCHAR_ROUTINE(strncmp, _mbsncmp, wcsncmp) 00194 #define _tcsnccnt NUX_TCHAR_ROUTINE(_strncnt, _mbsnccnt, _wcsncnt) 00195 #define _tcsnccpy NUX_TCHAR_ROUTINE(strncpy, _mbsncpy, wcsncpy) 00196 #define _tcsncicmp NUX_TCHAR_ROUTINE(_strnicmp, _mbsnicmp, _wcsnicmp) 00197 #define _tcsncpy NUX_TCHAR_ROUTINE(strncpy, _mbsnbcpy, wcsncpy) 00198 #define _tcsncset NUX_TCHAR_ROUTINE(_strnset, _mbsnset, _wcsnset) 00199 #define _tcsnextc NUX_TCHAR_ROUTINE(_strnextc, _mbsnextc, _wcsnextc) 00200 #define _tcsnicmp NUX_TCHAR_ROUTINE(_strnicmp, _mbsnicmp, _wcsnicmp) 00201 #define _tcsnicoll NUX_TCHAR_ROUTINE(_strnicoll, _strnicoll _wcsnicoll) 00202 #define _tcsninc NUX_TCHAR_ROUTINE(_strninc, _mbsninc, _wcsninc) 00203 #define _tcsnccnt NUX_TCHAR_ROUTINE(_strncnt, _mbsnccnt, _wcsncnt) 00204 #define _tcsnset NUX_TCHAR_ROUTINE(_strnset, _mbsnbset, _wcsnset) 00205 #define _tcspbrk NUX_TCHAR_ROUTINE(strpbrk, _mbspbrk, wcspbrk) 00206 #define _tcsspnp NUX_TCHAR_ROUTINE(_strspnp, _mbsspnp, _wcsspnp) 00207 #define _tcsrchr NUX_TCHAR_ROUTINE(strrchr, _mbsrchr, wcsrchr) 00208 #define _tcsrev NUX_TCHAR_ROUTINE(_strrev, _mbsrev, _wcsrev) 00209 #define _tcsset NUX_TCHAR_ROUTINE(_strset, _mbsset, _wcsset) 00210 #define _tcsspn NUX_TCHAR_ROUTINE(strspn, _mbsspn, wcsspn) 00211 #define _tcsstr NUX_TCHAR_ROUTINE(strstr, _mbsstr, wcsstr) 00212 #define _tcstod NUX_TCHAR_ROUTINE(strtod, strtod, wcstod) 00213 #define _tcstok NUX_TCHAR_ROUTINE(strtok, _mbstok, wcstok) 00214 #define _tcstol NUX_TCHAR_ROUTINE(strtol, strtol, wcstol) 00215 #define _tcstoul NUX_TCHAR_ROUTINE(std::strtoul, strtoul, std::wcstoul) 00216 #define _tcsupr NUX_TCHAR_ROUTINE(strupr, _mbsupr, wcsupr) 00217 #define _tcsxfrm NUX_TCHAR_ROUTINE(strxfrm, strxfrm, wcsxfrm) 00218 #define _tctime NUX_TCHAR_ROUTINE(ctime, ctime, _wctime) 00219 #define _tenviron NUX_TCHAR_ROUTINE(_environ, _environ, _wenviron) 00220 #define _texecl NUX_TCHAR_ROUTINE(execl, _execl, _wexecl) 00221 #define _texecle NUX_TCHAR_ROUTINE(execle, _execle, _wexecle) 00222 #define _texeclp NUX_TCHAR_ROUTINE(execlp, _execlp, _wexeclp) 00223 #define _texeclpe NUX_TCHAR_ROUTINE(execlpe, _execlpe, _wexeclpe) 00224 #define _texecv NUX_TCHAR_ROUTINE(execv, _execv, _wexecv) 00225 #define _texecve NUX_TCHAR_ROUTINE(execve, _execve, _wexecve) 00226 #define _texecvp NUX_TCHAR_ROUTINE(execvp, _execvp, _wexecvp) 00227 #define _texecvpe NUX_TCHAR_ROUTINE(execvpe, _execvpe, _wexecvpe) 00228 #define _tfdopen NUX_TCHAR_ROUTINE(fdopen, _fdopen, _wfdopen) 00229 #define _tfinddata_t NUX_TCHAR_ROUTINE(_finddata_t, _finddata_t, _wfinddata_t) 00230 #define _tfinddatai64_t NUX_TCHAR_ROUTINE(_finddatai64_t,_finddatai64_t,_wfinddatai64_t) 00231 #define _tfindfirst NUX_TCHAR_ROUTINE(_findfirst, _findfirst, _wfindfirst) 00232 #define _tfindnext NUX_TCHAR_ROUTINE(_findnext, _findnext, _wfindnext) 00233 #define _tfopen NUX_TCHAR_ROUTINE(fopen, fopen, _wfopen) 00234 #define _tfreopen NUX_TCHAR_ROUTINE(freopen, freopen, _wfreopen) 00235 #define _tfsopen NUX_TCHAR_ROUTINE(_fsopen, _fsopen, _wfsopen) 00236 #define _tfullpath NUX_TCHAR_ROUTINE(_fullpath, _fullpath, _wfullpath) 00237 #define _tgetcwd NUX_TCHAR_ROUTINE(getcwd, _getcwd, _wgetcwd) 00238 #define _tgetenv NUX_TCHAR_ROUTINE(getenv, getenv, _wgetenv) 00239 #define _tmain NUX_TCHAR_ROUTINE(main, main, wmain) 00240 #define _tmakepath NUX_TCHAR_ROUTINE(_makepath, _makepath, _wmakepath) 00241 #define _tmkdir NUX_TCHAR_ROUTINE(mkdir, _mkdir, _wmkdir) 00242 #define _tmktemp NUX_TCHAR_ROUTINE(mktemp, _mktemp, _wmktemp) 00243 #define _tperror NUX_TCHAR_ROUTINE(perror, perror, _wperror) 00244 #define _topen NUX_TCHAR_ROUTINE(open, _open, _wopen) 00245 #define _totlower NUX_TCHAR_ROUTINE(std::tolower, _mbctolower, towlower) 00246 #define _totupper NUX_TCHAR_ROUTINE(std::toupper, _mbctoupper, towupper) 00247 #define _tpopen NUX_TCHAR_ROUTINE(popen, _popen, _wpopen) 00248 #define _tprintf NUX_TCHAR_ROUTINE(printf, printf, wprintf) 00249 #define _tremove NUX_TCHAR_ROUTINE(remove, remove, _wremove) 00250 #define _trename NUX_TCHAR_ROUTINE(rename, rename, _wrename) 00251 #define _trmdir NUX_TCHAR_ROUTINE(rmdir, _rmdir, _wrmdir) 00252 #define _tsearchenv NUX_TCHAR_ROUTINE(_searchenv, _searchenv, _wsearchenv) 00253 #define _tscanf NUX_TCHAR_ROUTINE(scanf, scanf, wscanf) 00254 #define _tsetlocale NUX_TCHAR_ROUTINE(setlocale, setlocale, _wsetlocale) 00255 #define _tsopen NUX_TCHAR_ROUTINE(_sopen, _sopen, _wsopen) 00256 #define _tspawnl NUX_TCHAR_ROUTINE(_spawnl, _spawnl, _wspawnl) 00257 #define _tspawnle NUX_TCHAR_ROUTINE(_spawnle, _spawnle, _wspawnle) 00258 #define _tspawnlp NUX_TCHAR_ROUTINE(_spawnlp, _spawnlp, _wspawnlp) 00259 #define _tspawnlpe NUX_TCHAR_ROUTINE(_spawnlpe, _spawnlpe, _wspawnlpe) 00260 #define _tspawnv NUX_TCHAR_ROUTINE(_spawnv, _spawnv, _wspawnv) 00261 #define _tspawnve NUX_TCHAR_ROUTINE(_spawnve, _spawnve, _wspawnve) 00262 #define _tspawnvp NUX_TCHAR_ROUTINE(_spawnvp, _spawnvp, _tspawnvp) 00263 #define _tspawnvpe NUX_TCHAR_ROUTINE(_spawnvpe, _spawnvpe, _tspawnvpe) 00264 #define _tsplitpath NUX_TCHAR_ROUTINE(_splitpath, _splitpath, _wsplitpath) 00265 #define _tstat NUX_TCHAR_ROUTINE(_stat, _stat, _wstat) 00266 #define _tstrdate NUX_TCHAR_ROUTINE(_strdate, _strdate, _wstrdate) 00267 #define _tstrtime NUX_TCHAR_ROUTINE(_strtime, _strtime, _wstrtime) 00268 #define _tsystem NUX_TCHAR_ROUTINE(system, system, _wsystem) 00269 #define _ttempnam NUX_TCHAR_ROUTINE(tempnam, _tempnam, _wtempnam) 00270 #define _ttmpnam NUX_TCHAR_ROUTINE(tmpnam, tmpnam, _wtmpnam) 00271 #define _ttoi NUX_TCHAR_ROUTINE(atoi, atoi, _wtoi) 00272 #define _ttol NUX_TCHAR_ROUTINE(atol, atol, _wtol) 00273 #define _tutime NUX_TCHAR_ROUTINE(utime, _utime, _wutime) 00274 #define _tWinMain NUX_TCHAR_ROUTINE(WinMain, WinMain, wWinMain) 00275 #define _ultot NUX_TCHAR_ROUTINE(_ultoa, _ultoa, _ultow) 00276 #define _ungettc NUX_TCHAR_ROUTINE(ungetc, ungetc, ungetwc) 00277 #define _vftprintf NUX_TCHAR_ROUTINE(vfprintf, vfprintf, vfwprintf) 00278 #define _vsntprintf NUX_TCHAR_ROUTINE(vsnprintf, _vsnprintf, _vsnwprintf) 00279 #define _vstprintf NUX_TCHAR_ROUTINE(vsprintf, vsprintf, vswprintf) 00280 #define _vtprintf NUX_TCHAR_ROUTINE(vprintf, vprintf, vwprintf) 00281 #define _TEOF NUX_TCHAR_ROUTINE(EOF, EOF, WEOF) 00282 00283 00284 00285 #endif // SYSTEMGNU_H 00286 00287