1 /*
2  * The contents of this file are subject to the Mozilla Public
3  * License Version 1.1 (the "License"); you may not use this file
4  * except in compliance with the License. You may obtain a copy of
5  * the License at http://www.mozilla.org/MPL/
6  *
7  * Software distributed under the License is distributed on an "AS
8  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
9  * implied. See the License for the specific language governing
10  * rights and limitations under the License.
11  *
12  * The Original Code is MPEG4IP.
13  *
14  * The Initial Developer of the Original Code is Cisco Systems Inc.
15  * Portions created by Cisco Systems Inc. are
16  * Copyright (C) Cisco Systems Inc. 2005.  All Rights Reserved.
17  *
18  * Contributor(s):
19  *		Bill May wmay@cisco.com
20  */
21 /* windows defines */
22 #ifndef __MPEG4IP_WIN32_H__
23 #define __MPEG4IP_WIN32_H__
24 #define HAVE_IN_PORT_T
25 #define HAVE_SOCKLEN_T
26 #define NEED_SDL_VIDEO_IN_MAIN_THREAD
27 #ifndef _WIN32_WINNT
28 #define _WIN32_WINNT 0x0400
29 #endif
30 #define _WINSOCKAPI_
31 #define _INTEGRAL_MAX_BITS 64
32 #ifndef __GNUC__
33 #define _CRT_SECURE_NO_DEPRECATE 1
34 #ifndef _WIN32
35 #define _WIN32
36 #endif
37 #endif
38 #include <windows.h>
39 #include <winsock2.h>
40 #include <stdio.h>
41 #include <errno.h>
42 #include <stdlib.h>
43 #include <time.h>
44 #include <limits.h>
45 
46 #ifndef inline
47 #define inline __inline
48 #endif
49 typedef unsigned __int64 uint64_t;
50 typedef unsigned __int32 uint32_t;
51 typedef unsigned __int16 uint16_t;
52 typedef unsigned __int8 uint8_t;
53 typedef unsigned __int64 u_int64_t;
54 typedef unsigned __int32 u_int32_t;
55 typedef unsigned __int16 u_int16_t;
56 typedef unsigned __int8 u_int8_t;
57 typedef signed __int64 int64_t;
58 typedef signed __int32 int32_t;
59 typedef signed __int16 int16_t;
60 typedef signed __int8  int8_t;
61 typedef unsigned short in_port_t;
62 typedef int socklen_t;
63 typedef int ssize_t;
64 typedef unsigned int uint;
snprintf(char * buffer,size_t count,const char * format,...)65 static inline int snprintf(char *buffer, size_t count,
66 			  const char *format, ...) {
67   va_list ap;
68   int ret;
69   va_start(ap, format);
70   ret = vsnprintf_s(buffer, count, _TRUNCATE, format, ap);
71   va_end(ap);
72   if (ret == -1) {
73     if (errno == EINVAL) return -1;
74     return (int)count;
75   }
76   return ret;
77 }
78 #define strncasecmp _strnicmp
79 #define strcasecmp _stricmp
80 #define localtime_r(a,b) localtime_s(b,a)
81 #define printf printf_s
82 #define fprintf fprintf_s
83 
84 #include <io.h>
85 #include <fcntl.h>
86 #include <sys/types.h>
87 #include <sys/stat.h>
88 #ifndef __GNUC__
89 #define read _read
90 #define write _write
91 #define lseek _lseek
92 #define close _close
93 #define open _open
94 #define access _access
95 #define vsnprintf _vsnprintf
96 #define stat _stati64
97 #define fstat _fstati64
98 #define fileno _fileno
99 #define strdup _strdup
100 #endif
101 #define F_OK 0
102 #define OPEN_RDWR (_O_RDWR | _O_BINARY)
103 #define OPEN_CREAT (_O_CREAT | _O_BINARY)
104 #define OPEN_RDONLY (_O_RDONLY | _O_BINARY)
105 #define srandom srand
106 #define random rand
107 
108 #define IOSBINARY ios::binary
109 
110 #ifdef __cplusplus
111 extern "C" {
112 #endif
113 int gettimeofday(struct timeval *t, void *);
114 #ifdef __cplusplus
115 }
116 #endif
117 
118 #ifndef PATH_MAX
119 #define PATH_MAX MAX_PATH
120 #endif
121 #define MAX_UINT64 -1
122 
123 #define D64F "I64d"
124 #define U64F  "I64u"
125 #define X64F "I64x"
126 
127 #define TO_D64(a) (a##I64)
128 #define TO_U64(a) (a##UI64)
129 
130 #define LOG_EMERG 0
131 #define LOG_ALERT 1
132 #define LOG_CRIT 2
133 #define LOG_ERR 3
134 #define LOG_WARNING 4
135 #define LOG_NOTICE 5
136 #define LOG_INFO 6
137 #define LOG_DEBUG 7
138 
139 #if     defined (__GNUC__) || (!__STDC__ && _INTEGRAL_MAX_BITS >= 64)
140 #define VAR_TO_FPOS(fpos, var) (fpos) = (var)
141 #define FPOS_TO_VAR(fpos, typed, var) (var) = (typed)(fpos)
142 #else
143 #define VAR_TO_FPOS(fpos, var) (fpos).lopart = ((var) & UINT_MAX); (fpos).hipart = ((var) >> 32)
144 #define FPOS_TO_VAR(fpos, typed, var) (var) = (typed)((uint64_t)((fpos).hipart ) << 32 | (fpos).lopart)
145 #endif
146 
147 #define __STRING(expr) #expr
148 
149 #define FOPEN_READ_BINARY "rb"
150 #define FOPEN_WRITE_BINARY "wb"
151 
152 #define UINT64_TO_DOUBLE(a) ((double)((int64_t)(a)))
153 #ifdef __cplusplus
154 extern "C" {
155 #endif
156 char *strcasestr(const char *haystack, const char *needle);
157 #ifdef __cplusplus
158 }
159 #endif
160 
161 
162 #define SIZEOF_BOOL 1
163 
164 #ifndef __GNUC__
165 #ifndef _SS_PAD1SIZE
166 struct sockaddr_storage {
167 	unsigned short ss_family;
168 	uint32_t ss_align;
169 	char __ss_padding[128 - 2 * sizeof(uint32_t)];
170 };
171 #endif
172 #pragma warning(disable : 4244)
173 #pragma warning(disable: 4996)
174 #define HAVE_STRUCT_SOCKADDR_STORAGE 1
175 #define HAVE_INET_PTON 1
176 #define HAVE_INET_NTOP 1
177 #endif
178 #endif
179