History

Merge the encoder/decoder crt_util_safe_x.h into the common lib

Martin Storsjö committed 12 years ago

Commit 2f5f25b1 parent 55336de7 files · +312 −328Browse files

Showing the changes to codec/decoder/core/src/utils.cpp (1 of 7 files). Show all

Unified · Split

codec/decoder/core/src/utils.cpp+0−222
@@ -38,32 +38,8 @@ · 37 unmodified lines
38 *************************************************************************************38 *************************************************************************************
39 */39 */
40 40
41#include <string.h>
42#include <stdlib.h>
43#include <math.h>
44#include <time.h>
45#if defined(_WIN32)
46#include <windows.h>
47#include <sys/types.h>
48#include <sys/timeb.h>
49#ifndef _MSC_VER
50#include <sys/time.h>
51#ifndef HAVE_STRNLEN
52#define strnlen(a,b) strlen(a)
53#endif //!HAVE_STRNLEN
54#endif //!_MSC_VER
55#else
56#include <sys/time.h>
57#include <sys/timeb.h>
58#endif //_WIN32
59
60#include "utils.h"41#include "utils.h"
61#include "macros.h"
62#include "wels_const.h"
63#include "cpu_core.h"
64#include "decoder_context.h"42#include "decoder_context.h"
65#include "crt_util_safe_x.h" // Safe CRT routines like utils for cross platforms
66#include "mem_align.h"
67 43
68namespace WelsDec {44namespace WelsDec {
69 45
@@ -82,202 +58,4 @@ void_t WelsLog (void_t* pPtr, int32_t iLevel, const char* kpFmt, ...) { · 12 unmodified lines
82 va_end (pVl);58 va_end (pVl);
83}59}
84 60
85
86#if defined(_WIN32) && defined(_MSC_VER)
87
88#if defined(_MSC_VER) && (_MSC_VER>=1500)
89
90int32_t WelsSnprintf (str_t* pBuffer, int32_t iSizeOfBuffer, const str_t* kpFormat, ...) {
91 va_list pArgPtr;
92 int32_t iRc;
93
94 va_start (pArgPtr, kpFormat);
95
96 iRc = vsnprintf_s (pBuffer, iSizeOfBuffer, _TRUNCATE, kpFormat, pArgPtr);
97
98 va_end (pArgPtr);
99
100 return iRc;
101}
102
103str_t* WelsStrncpy (str_t* pDest, int32_t iSizeInBytes, const str_t* kpSrc, int32_t iCount) {
104 strncpy_s (pDest, iSizeInBytes, kpSrc, iCount);
105
106 return pDest;
107}
108
109int32_t WelsStrnlen (const str_t* kpStr, int32_t iMaxlen) {
110 return strnlen_s (kpStr, iMaxlen);
111}
112
113int32_t WelsVsprintf (str_t* pBuffer, int32_t iSizeOfBuffer, const str_t* kpFormat, va_list pArgPtr) {
114 return vsprintf_s (pBuffer, iSizeOfBuffer, kpFormat, pArgPtr);
115}
116
117WelsFileHandle* WelsFopen (const str_t* kpFilename, const str_t* kpMode) {
118 WelsFileHandle* pFp = NULL;
119 if (fopen_s (&pFp, kpFilename, kpMode) != 0) {
120 return NULL;
121 }
122
123 return pFp;
124}
125
126int32_t WelsFclose (WelsFileHandle* pFp) {
127 return fclose (pFp);
128}
129
130int32_t WelsGetTimeOfDay (SWelsTime* pTp) {
131 return _ftime_s (pTp);
132}
133
134int32_t WelsStrftime (str_t* pBuffer, int32_t iSize, const str_t* kpFormat, const SWelsTime* kpTp) {
135 struct tm sTimeNow;
136
137 localtime_s (&sTimeNow, &kpTp->time);
138
139 return strftime (pBuffer, iSize, kpFormat, &sTimeNow);
140}
141
142#else
143
144int32_t WelsSnprintf (str_t* pBuffer, int32_t iSizeOfBuffer, const str_t* kpFormat, ...) {
145 va_list pArgPtr;
146 int32_t iRc;
147
148 va_start (pArgPtr, kpFormat);
149
150 iRc = vsprintf (pBuffer, kpFormat, pArgPtr); //confirmed_safe_unsafe_usage
151
152 va_end (pArgPtr);
153
154 return iRc;
155}
156
157str_t* WelsStrncpy (str_t* pDest, int32_t iSizeInBytes, const str_t* kpSrc, int32_t iCount) {
158 strncpy (pDest, kpSrc, iCount); //confirmed_safe_unsafe_usage
159
160 return pDest;
161}
162
163int32_t WelsStrnlen (const str_t* kpStr, int32_t iMaxlen) {
164 return strlen (kpStr); //confirmed_safe_unsafe_usage
165}
166
167int32_t WelsVsprintf (str_t* pBuffer, int32_t iSizeOfBuffer, const str_t* kpFormat, va_list pArgPtr) {
168 return vsprintf (pBuffer, kpFormat, pArgPtr); //confirmed_safe_unsafe_usage
169}
170
171
172WelsFileHandle* WelsFopen (const str_t* kpFilename, const str_t* kpMode) {
173 return fopen (kpFilename, kpMode);
174}
175
176int32_t WelsFclose (WelsFileHandle* pFp) {
177 return fclose (pFp);
178}
179
180int32_t WelsGetTimeOfDay (SWelsTime* pTp) {
181 _ftime (pTp);
182 return 0;
183}
184
185int32_t WelsStrftime (str_t* pBuffer, int32_t iSize, const str_t* kpFormat, const SWelsTime* kpTp) {
186 struct tm* pTnow;
187
188 pTnow = localtime (&kpTp->time);
189
190 return strftime (pBuffer, iSize, kpFormat, pTnow);
191}
192
193
194#endif // _MSC_VER
195
196#else //GCC
197
198int32_t WelsSnprintf (str_t* pBuffer, int32_t iSizeOfBuffer, const str_t* kpFormat, ...) {
199 va_list pArgPtr;
200 int32_t iRc;
201
202 va_start (pArgPtr, kpFormat);
203
204 iRc = vsnprintf (pBuffer, iSizeOfBuffer, kpFormat, pArgPtr);
205
206 va_end (pArgPtr);
207
208 return iRc;
209}
210
211str_t* WelsStrncpy (str_t* pDest, int32_t iSizeInBytes, const str_t* kpSrc, int32_t iCount) {
212 return strncpy (pDest, kpSrc, iCount); //confirmed_safe_unsafe_usage
213}
214
215#if !defined(MACOS) && !defined(UNIX) && !defined(APPLE_IOS)
216int32_t WelsStrnlen (const str_t* kpStr, int32_t iMaxlen) {
217 return strnlen (kpStr, iMaxlen); //confirmed_safe_unsafe_usage
218}
219#else
220int32_t WelsStrnlen (const str_t* kpString, int32_t iMaxlen) {
221 // In mac os, there is no strnlen in string.h, we can only use strlen instead of strnlen or
222 // implement strnlen by ourself
223
224#if 1
225 return strlen (kpString); //confirmed_safe_unsafe_usage
226#else
227 const str_t* kpSrc;
228 for (kpSrc = kpString; iMaxlen-- && *kpSrc != '\0'; ++kpSrc)
229 return kpSrc - kpString;
230#endif
231
232}
233#endif
234
235int32_t WelsVsprintf (str_t* pBuffer, int32_t iSizeOfBuffer, const str_t* kpFormat, va_list pArgPtr) {
236 return vsprintf (pBuffer, kpFormat, pArgPtr); //confirmed_safe_unsafe_usage
237}
238
239WelsFileHandle* WelsFopen (const str_t* kpFilename, const str_t* kpMode) {
240 return fopen (kpFilename, kpMode);
241}
242
243int32_t WelsFclose (WelsFileHandle* pFp) {
244 return fclose (pFp);
245}
246
247int32_t WelsGetTimeOfDay (SWelsTime* pTp) {
248 struct timeval sTv;
249
250 if (gettimeofday (&sTv, NULL)) {
251 return -1;
252 }
253
254 pTp->time = sTv.tv_sec;
255 pTp->millitm = (uint16_t)sTv.tv_usec / 1000;
256
257 return 0;
258}
259
260int32_t WelsStrftime (str_t* pBuffer, int32_t iSize, const str_t* kpFormat, const SWelsTime* kpTp) {
261 struct tm* pTnow;
262
263 pTnow = localtime (&kpTp->time);
264
265 return strftime (pBuffer, iSize, kpFormat, pTnow);
266}
267
268#endif
269
270
271int32_t WelsFwrite (const void_t* kpBuffer, int32_t iSize, int32_t iCount, WelsFileHandle* pFp) {
272 return fwrite (kpBuffer, iSize, iCount, pFp);
273}
274
275uint16_t WelsGetMillsecond (const SWelsTime* kpTp) {
276 return kpTp->millitm;
277}
278
279int32_t WelsFflush (WelsFileHandle* pFp) {
280 return fflush (pFp);
281}
282
283} // namespace WelsDec61} // namespace WelsDec

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t