You.i Engine
YiPredefLinux.h
Go to the documentation of this file.
1 // © You i Labs Inc. 2000-2017. All rights reserved.
2 #ifndef _YI_PREDEF_LINUX_H_
3 #define _YI_PREDEF_LINUX_H_
4 
5 #include <cstdio>
6 #include <cstdlib>
7 #include <ctype.h>
8 #include <cstring>
9 #include <time.h> // for nanosleep
10 #include <unistd.h> // for usleep() for upcoming gcc 4.7
11 //#include <strings.h>
12 //#include <cwchar>
13 //#include <cstdint> // for sleep()
14 
15 #include <queue>
16 #include <stack>
17 #include <vector>
18 #include <map>
19 #include <list>
20 #include <iterator>
21 #include <sstream>
22 #include <iostream>
23 #include <algorithm>
24 #include <fstream>
25 #include <cfloat>
26 
32 // platform-dependant functions
33 // memory
34 #define YI_SYSTEM_FREE(a) free(a)
35 #define YI_SYSTEM_MALLOC(a) malloc(a)
36 #define YI_SYSTEM_REALLOC(a, b) realloc(a, b)
37 #define YI_MEMCMP(a, b, c) memcmp(a, b, c)
38 #define YI_MEMMOVE(a, b, c) memmove(a, b, c)
39 #define YI_MEMCOPY(a, b, c) memcpy(a, b, c)
40 #define YI_MEMSET(a, b, c) memset(a, b, c)
41 
42 // multi-byte string
43 // NOTE: To be used only when absolutely required.
44 // Wide strings are preferred
45 #define YI_STRCAT(a, b) strcat(a, b)
46 #define YI_STRCHR(a, b) strchr(a, b)
47 #define YI_STRCMP(a, b) strcmp(a, b)
48 #define YI_STRCPY(a, b) strcpy(a, b)
49 #define YI_STRLEN(a) strlen(a)
50 #define YI_STRREV(a) STRREV(a)
51 #define YI_STRNCMP(a, b, c) strncmp(a, b, c)
52 #define YI_STRNICMP(a, b, c) strncmp(a, b, c)
53 #define YI_STRNCAT(a, b, c) strncat(a, b, c)
54 #define YI_STRNCPY(a, b, c) strncpy(a, b, c)
55 #define YI_STRRCHR(a, b) strrchr(a, b)
56 #define YI_STRTOUL(a, b, c) strtoul(a, b, c)
57 #define YI_VSNPRINTF(a, b, c, d) vsnprintf(a, b, c, d)
58 #define YI_STRICMP(a, b) strcasecmp(a, b)
59 #define YI_SPRINTF sprintf
60 #define YI_SNPRINTF snprintf
61 #define YI_ATOI(a) atoi(a)
62 #define YI_ATOF(a) atof(a)
63 
64 // wide string
65 #define YI_WCSCPY WCSCPY
66 #define YI_WCSNCPY WCSNCPY
67 #define YI_WCSLEN WCSLEN
68 #define YI_WCSREV WCSREV
69 #define YI_WCSCMP WCSCMP
70 #define YI_WCSNCMP WCSNCMP
71 #define YI_WCSICMP WCSICMP
72 #define YI_WCSNICMP WCSNICMP
73 #define YI_WCSCAT WCSCAT
74 #define YI_WCSNCAT WCSNCAT
75 #define YI_WCSSTR WCSSTR
76 #define YI_WCSCHR WCSCHR
77 #define YI_SWPRINTF swprintf
78 
79 #if _POSIX_C_SOURCE >= 199309L
80 inline void YI_SLEEP(long timeMs)
81 {
82  struct timespec ts;
83  ts.tv_sec = int(timeMs / 1000);
84  ts.tv_nsec = (timeMs % 1000) * 1000000;
85  nanosleep(&ts, NULL);
86 }
87 
88 inline void YI_USLEEP(long timeUs)
89 {
90  struct timespec ts;
91  ts.tv_sec = int(timeUs / 1000000);
92  ts.tv_nsec = (timeUs % 1000000) * 1000;
93  nanosleep(&ts, NULL);
94 }
95 #else
96 // usleep: This C routine is considered obsolete (as opposed to the shell
97 // command by the same name). The interaction of this function with SIGALRM and
98 // other timer functions such as sleep(), alarm(), setitimer(), and nanosleep()
99 // is unspecified (CWE-676). Use nanosleep(2) or setitimer(2) instead.
100 #define YI_SLEEP(x) usleep((x)*1000)
101 #define YI_USLEEP(x) usleep(x)
102 #endif
103 
104 
105 //File handling
106 #define YI_FILE FILE
107 #define YI_FREAD (int32_t) fread
108 #define YI_FWRITE fwrite
109 #define YI_FGETC fgetc
110 #define YI_FPUTC fputc
111 
112 #if !defined(_SIZE_T_DEFINED) && !defined(_SIZE_T)
113 typedef unsigned int size_t;
114 #define _SIZE_T
115 #define _SIZE_T_DEFINED
116 #endif
117 
118 typedef void *HANDLE;
119 
120 #if defined(YI_WEBOS) || defined(YI_TIZEN_NACL)
121 #define YI_HAS_VIRTUAL_KEYBOARD
122 #endif
123 
124 #if defined (YI_TIZEN_NACL)
125 //On Tizen, the floating point accuracy of the hardware is unpredictable and results in bands of artifacts in the text when using the regular text rendering shader.
126 //Using an alternate shader, the error is greatly reduced (though not eliminated). The alternate approach is incompatible with the Galaxy Tab A SM-T350 and so must
127 //not be used globally.
128 //The remaining error is reduced by using LINEAR text filtering in the text atlas
129 #define YI_USE_FALLBACK_TEXT_RENDERING
130 #define YI_USE_LINEAR_TEXT_FILTERING
131 #endif
132 
137 #endif // _YI_PREDEF_LINUX_H_
#define YI_SLEEP(x)
Definition: YiPredefLinux.h:100
unsigned int size_t
Definition: YiPredefLinux.h:113
void * HANDLE
Definition: YiPredefLinux.h:118
#define YI_USLEEP(x)
Definition: YiPredefLinux.h:101