COVISE Core
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
unixcompat.h
Go to the documentation of this file.
1 /* This file is part of COVISE.
2 
3  You can use it under the terms of the GNU Lesser General Public License
4  version 2.1 or later, see lgpl-2.1.txt.
5 
6  * License: LGPL 2+ */
7 
8 #ifndef COV_WINCOMPAT_H
9 #define COV_WINCOMPAT_H
10 
11 #include <stdarg.h>
12 #include <string.h>
13 #include <stdio.h>
14 
15 #ifndef WINCOMPATINLINE
16 #ifdef __cplusplus
17 #define WINCOMPATINLINE inline
18 #else
19 #define WINCOMPATINLINE static
20 #endif
21 #endif
22 
23 #if defined(_WIN32) || defined(_WIN64)
24 #include <float.h>
25 #if !defined(__MINGW32__)
26 #define isnan _isnan
27 #endif
28 #include <winsock2.h>
29 #ifndef WIN32_LEAN_AND_MEAN
30 #define WIN32_LEAN_AMD_MEAN
31 #include <windows.h>
32 #undef WIN32_LEAN_AMD_MEAN
33 #else
34 #include <windows.h>
35 #endif
36 #ifndef _WIN32_WCE
37 #include <sys/types.h>
38 #include <sys/timeb.h>
39 #include <direct.h>
40 #endif
41 #ifndef SURFACE
42 
43 WINCOMPATINLINE char *basename(char *pathptr)
44 {
45  static char fullPath[MAX_PATH];
46  static char dummystr[] = ".";
47  char *filebn = 0;
48  char *retval = dummystr;
49  if (GetFullPathName(pathptr, MAX_PATH, fullPath, &filebn) != 0)
50  {
51  if (*filebn != 0)
52  retval = filebn;
53  }
54  return retval;
55 }
56 #endif
57 
58 #if !defined(__MINGW32__)
59 WINCOMPATINLINE int strcasecmp(const char *s1, const char *s2)
60 {
61  return stricmp(s1, s2);
62 }
63 #endif
64 
65 WINCOMPATINLINE void sleep(int time)
66 {
67  Sleep(time * 1000);
68 }
69 
70 WINCOMPATINLINE void usleep(int time)
71 {
72  Sleep(time / 1000);
73 }
74 
75 #if !defined(__MINGW32__)
76 WINCOMPATINLINE int strncasecmp(const char *s1, const char *s2, size_t n)
77 {
78  return strnicmp(s1, s2, n);
79 }
80 
81 WINCOMPATINLINE int snprintf(char *str, size_t size, const char *format, ...)
82 {
83  int result;
84  va_list ap;
85  va_start(ap, format);
86  result = _vsnprintf(str, size, format, ap);
87  va_end(ap);
88  str[size - 1] = '\0';
89  return result;
90 }
91 #endif
92 
93 #if defined(_MSC_VER) && (_MSC_VER < 1020)
94 WINCOMPATINLINE int vsnprintf(char *str, size_t size, const char *format, va_list ap)
95 {
96  int result = _vsnprintf(str, size, format, ap);
97  str[size - 1] = '\0';
98  return result;
99 }
100 #endif
101 
102 #if defined(__MINGW32__)
103 #include <sys/time.h>
104 #else
105 struct timezone
106 {
107  int tz_minuteswest;
108  int tz_dsttime;
109 };
110 
111 WINCOMPATINLINE int gettimeofday(struct timeval *tv, struct timezone *tz)
112 {
113  struct __timeb64 currentTime;
114  (void)tz;
115 #if _MSC_VER < 1400
116  _ftime64(&currentTime);
117 #else
118  _ftime64_s(&currentTime);
119 #endif
120  tv->tv_sec = (long)currentTime.time;
121  tv->tv_usec = (long)currentTime.millitm * 1000;
122 
123  return 0;
124 }
125 #endif
126 
127 #else /* unix */
128 #include <unistd.h>
129 #include <sys/time.h>
130 #endif /* _WIN32 or _WIN64 */
131 
132 #if defined(_WIN32) || defined(__hpux)
133 WINCOMPATINLINE char *strtok_r(char *s1, const char *s2, char **lasts)
134 {
135  char *ret;
136 
137  if (s1 == NULL)
138  s1 = *lasts;
139  while (*s1 && strchr(s2, *s1))
140  ++s1;
141  if (*s1 == '\0')
142  return NULL;
143  ret = s1;
144  while (*s1 && !strchr(s2, *s1))
145  ++s1;
146  if (*s1)
147  *s1++ = '\0';
148  *lasts = s1;
149  return ret;
150 }
151 #endif
152 
153 #if !defined(__linux__) && !defined(__APPLE__)
154 WINCOMPATINLINE char *strsep(char **s, const char *delim)
155 {
156  if (!s)
157  return NULL;
158 
159  char *start = *s;
160  char *p = *s;
161 
162  if (p == NULL)
163  return NULL;
164 
165  while (*p)
166  {
167  const char *d = delim;
168  while (*d)
169  {
170  if (*p == *d)
171  {
172  *p = '\0';
173  *s = p + 1;
174  return start;
175  }
176  d++;
177  }
178  p++;
179  }
180 
181  *s = NULL;
182  return start;
183 }
184 #endif
185 
186 #if defined(__APPLE__)
187 WINCOMPATINLINE off_t lseek64(int fildes, off_t offset, int whence)
188 {
189  return lseek(fildes, offset, whence);
190 }
191 #endif
192 
193 #endif /* COV_WINCOMPAT_H */
WINCOMPATINLINE char * strsep(char **s, const char *delim)
Definition: unixcompat.h:154
static const int s2
Definition: SammConv.cpp:38
GLbyte GLbyte tz
Definition: khronos-glext.h:9715
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: khronos-glext.h:6344
GLdouble n
Definition: khronos-glext.h:8447
GLdouble s
Definition: khronos-glext.h:6441
#define NULL
Definition: covise_list.h:22
GLsizeiptr size
Definition: khronos-glext.h:6610
GLfloat GLfloat p
Definition: khronos-glext.h:9861
typedef void(APIENTRY *GLDEBUGPROCARB)(GLenum source
GLuint start
Definition: khronos-glext.h:6343
#define WINCOMPATINLINE
Definition: unixcompat.h:19
GLuint64EXT * result
Definition: khronos-glext.h:12573
GLintptr offset
Definition: khronos-glext.h:6611
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat s1
Definition: khronos-glext.h:13144