diff options
author | irungentoo <irungentoo@gmail.com> | 2013-10-17 08:09:06 -0400 |
---|---|---|
committer | irungentoo <irungentoo@gmail.com> | 2013-10-17 08:09:06 -0400 |
commit | bdbf4a367318d4e6b37975627fe86c7e79449ee4 (patch) | |
tree | 81eb1cfae9c3fb44b49a53c25b747ed92b044403 /toxrtp/toxrtp_helper.c | |
parent | 6391208ab33b75d324201eb567e7a4ae2e28b838 (diff) |
Fixed building on windows.
Diffstat (limited to 'toxrtp/toxrtp_helper.c')
-rw-r--r-- | toxrtp/toxrtp_helper.c | 97 |
1 files changed, 48 insertions, 49 deletions
diff --git a/toxrtp/toxrtp_helper.c b/toxrtp/toxrtp_helper.c index bb2dc56b..6f952359 100644 --- a/toxrtp/toxrtp_helper.c +++ b/toxrtp/toxrtp_helper.c | |||
@@ -31,7 +31,6 @@ | |||
31 | #include "toxrtp_helper.h" | 31 | #include "toxrtp_helper.h" |
32 | #include "../toxcore/network.h" | 32 | #include "../toxcore/network.h" |
33 | 33 | ||
34 | #include <arpa/inet.h> /* Fixes implicit function warning. */ | ||
35 | #include <assert.h> | 34 | #include <assert.h> |
36 | 35 | ||
37 | #ifdef WIN | 36 | #ifdef WIN |
@@ -41,11 +40,11 @@ | |||
41 | 40 | ||
42 | static int _seed = 0; /* Not initiated */ | 41 | static int _seed = 0; /* Not initiated */ |
43 | 42 | ||
44 | int t_setipport ( const char* _ip, unsigned short _port, void* _dest ) | 43 | int t_setipport ( const char *_ip, unsigned short _port, void *_dest ) |
45 | { | 44 | { |
46 | assert(_dest); | 45 | assert(_dest); |
47 | 46 | ||
48 | IP_Port* _dest_c = ( IP_Port* ) _dest; | 47 | IP_Port *_dest_c = ( IP_Port * ) _dest; |
49 | ip_init(&_dest_c->ip, 0); | 48 | ip_init(&_dest_c->ip, 0); |
50 | 49 | ||
51 | IP_Port _ipv6_garbage; | 50 | IP_Port _ipv6_garbage; |
@@ -72,7 +71,7 @@ uint32_t t_random ( uint32_t _max ) | |||
72 | } | 71 | } |
73 | } | 72 | } |
74 | 73 | ||
75 | void t_memcpy ( uint8_t* _dest, const uint8_t* _source, size_t _size ) | 74 | void t_memcpy ( uint8_t *_dest, const uint8_t *_source, size_t _size ) |
76 | { | 75 | { |
77 | /* | 76 | /* |
78 | * Using countdown to zero method | 77 | * Using countdown to zero method |
@@ -87,7 +86,7 @@ void t_memcpy ( uint8_t* _dest, const uint8_t* _source, size_t _size ) | |||
87 | 86 | ||
88 | } | 87 | } |
89 | 88 | ||
90 | uint8_t* t_memset ( uint8_t* _dest, uint8_t _valu, size_t _size ) | 89 | uint8_t *t_memset ( uint8_t *_dest, uint8_t _valu, size_t _size ) |
91 | { | 90 | { |
92 | /* | 91 | /* |
93 | * Again using countdown to zero method | 92 | * Again using countdown to zero method |
@@ -102,9 +101,9 @@ uint8_t* t_memset ( uint8_t* _dest, uint8_t _valu, size_t _size ) | |||
102 | return _dest; | 101 | return _dest; |
103 | } | 102 | } |
104 | 103 | ||
105 | size_t t_memlen ( const uint8_t* _valu) | 104 | size_t t_memlen ( const uint8_t *_valu) |
106 | { | 105 | { |
107 | const uint8_t* _it; | 106 | const uint8_t *_it; |
108 | size_t _retu = 0; | 107 | size_t _retu = 0; |
109 | 108 | ||
110 | for ( _it = _valu; *_it; ++_it ) ++_retu; | 109 | for ( _it = _valu; *_it; ++_it ) ++_retu; |
@@ -112,13 +111,13 @@ size_t t_memlen ( const uint8_t* _valu) | |||
112 | return _retu; | 111 | return _retu; |
113 | } | 112 | } |
114 | 113 | ||
115 | uint8_t* t_strallcpy ( const uint8_t* _source ) /* string alloc and copy */ | 114 | uint8_t *t_strallcpy ( const uint8_t *_source ) /* string alloc and copy */ |
116 | { | 115 | { |
117 | assert(_source); | 116 | assert(_source); |
118 | 117 | ||
119 | size_t _length = t_memlen(_source) + 1; /* make space for null character */ | 118 | size_t _length = t_memlen(_source) + 1; /* make space for null character */ |
120 | 119 | ||
121 | uint8_t* _dest = calloc( sizeof ( uint8_t ), _length ); | 120 | uint8_t *_dest = calloc( sizeof ( uint8_t ), _length ); |
122 | assert(_dest); | 121 | assert(_dest); |
123 | 122 | ||
124 | t_memcpy(_dest, _source, _length); | 123 | t_memcpy(_dest, _source, _length); |
@@ -126,75 +125,75 @@ uint8_t* t_strallcpy ( const uint8_t* _source ) /* string alloc and copy */ | |||
126 | return _dest; | 125 | return _dest; |
127 | } | 126 | } |
128 | 127 | ||
129 | size_t t_strfind ( const uint8_t* _str, const uint8_t* _substr ) | 128 | size_t t_strfind ( const uint8_t *_str, const uint8_t *_substr ) |
130 | { | 129 | { |
131 | size_t _pos = 0; | 130 | size_t _pos = 0; |
132 | size_t _it, _delit = 0; | 131 | size_t _it, _delit = 0; |
133 | 132 | ||
134 | for ( _it = 0; _str[_it] != '\0'; _it++ ){ | 133 | for ( _it = 0; _str[_it] != '\0'; _it++ ) { |
135 | if ( _str[_it] == _substr[_delit] ){ | 134 | if ( _str[_it] == _substr[_delit] ) { |
136 | _pos = _it; | 135 | _pos = _it; |
137 | while ( _str[_it] == _substr[_delit] && _str[_it] != '\0' ){ | 136 | |
137 | while ( _str[_it] == _substr[_delit] && _str[_it] != '\0' ) { | ||
138 | _it ++; | 138 | _it ++; |
139 | _delit++; | 139 | _delit++; |
140 | 140 | ||
141 | if ( _substr[_delit] == '\0' ){ | 141 | if ( _substr[_delit] == '\0' ) { |
142 | return _pos; | 142 | return _pos; |
143 | } | 143 | } |
144 | } | 144 | } |
145 | |||
145 | _delit = 0; | 146 | _delit = 0; |
146 | _pos = 0; | 147 | _pos = 0; |
147 | } | 148 | } |
148 | } | 149 | } |
150 | |||
149 | return _pos; | 151 | return _pos; |
150 | } | 152 | } |
151 | 153 | ||
152 | #ifdef WIN | 154 | #ifdef WIN |
153 | #if defined(_MSC_VER) || defined(_MSC_EXTENSIONS) | 155 | #if defined(_MSC_VER) || defined(_MSC_EXTENSIONS) |
154 | #define DELTA_EPOCH_IN_MICROSECS 11644473600000000Ui64 | 156 | #define DELTA_EPOCH_IN_MICROSECS 11644473600000000Ui64 |
155 | #else | 157 | #else |
156 | #define DELTA_EPOCH_IN_MICROSECS 11644473600000000ULL | 158 | #define DELTA_EPOCH_IN_MICROSECS 11644473600000000ULL |
157 | #endif | 159 | #endif |
158 | 160 | ||
159 | struct timezone | 161 | struct timezone { |
160 | { | 162 | int tz_minuteswest; /* minutes W of Greenwich */ |
161 | int tz_minuteswest; /* minutes W of Greenwich */ | 163 | int tz_dsttime; /* type of dst correction */ |
162 | int tz_dsttime; /* type of dst correction */ | ||
163 | }; | 164 | }; |
164 | 165 | ||
165 | int gettimeofday(struct timeval *tv, struct timezone *tz) | 166 | int gettimeofday(struct timeval *tv, struct timezone *tz) |
166 | { | 167 | { |
167 | FILETIME ft; | 168 | FILETIME ft; |
168 | unsigned __int64 tmpres = 0; | 169 | unsigned __int64 tmpres = 0; |
169 | static int tzflag; | 170 | static int tzflag; |
170 | 171 | ||
171 | if (NULL != tv) | 172 | if (NULL != tv) { |
172 | { | 173 | GetSystemTimeAsFileTime(&ft); |
173 | GetSystemTimeAsFileTime(&ft); | 174 | |
174 | 175 | tmpres |= ft.dwHighDateTime; | |
175 | tmpres |= ft.dwHighDateTime; | 176 | tmpres <<= 32; |
176 | tmpres <<= 32; | 177 | tmpres |= ft.dwLowDateTime; |
177 | tmpres |= ft.dwLowDateTime; | 178 | |
178 | 179 | /*converting file time to unix epoch*/ | |
179 | /*converting file time to unix epoch*/ | 180 | tmpres -= DELTA_EPOCH_IN_MICROSECS; |
180 | tmpres -= DELTA_EPOCH_IN_MICROSECS; | 181 | tmpres /= 10; /*convert into microseconds*/ |
181 | tmpres /= 10; /*convert into microseconds*/ | 182 | tv->tv_sec = (long)(tmpres / 1000000UL); |
182 | tv->tv_sec = (long)(tmpres / 1000000UL); | 183 | tv->tv_usec = (long)(tmpres % 1000000UL); |
183 | tv->tv_usec = (long)(tmpres % 1000000UL); | 184 | } |
184 | } | 185 | |
185 | 186 | if (NULL != tz) { | |
186 | if (NULL != tz) | 187 | if (!tzflag) { |
187 | { | 188 | _tzset(); |
188 | if (!tzflag) | 189 | tzflag++; |
189 | { | 190 | } |
190 | _tzset(); | 191 | |
191 | tzflag++; | 192 | tz->tz_minuteswest = _timezone / 60; |
193 | tz->tz_dsttime = _daylight; | ||
192 | } | 194 | } |
193 | tz->tz_minuteswest = _timezone / 60; | ||
194 | tz->tz_dsttime = _daylight; | ||
195 | } | ||
196 | 195 | ||
197 | return 0; | 196 | return 0; |
198 | } | 197 | } |
199 | #endif /* WIN */ | 198 | #endif /* WIN */ |
200 | 199 | ||