forked from erikkaashoek/Comskip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
platform.c
116 lines (102 loc) · 2.33 KB
/
platform.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#include "platform.h"
#if defined(_WIN32)
BOOL AnsiToUnicode16(const char *in_Src, WCHAR *out_Dst, INT in_MaxLen)
{
/* locals */
INT lv_Len;
int i;
// do NOT decrease maxlen for the eos
if (in_MaxLen <= 0)
return FALSE;
// let windows find out the meaning of ansi
// - the SrcLen=-1 triggers MBTWC to add a eos to Dst and fails if MaxLen is too small.
// - if SrcLen is specified then no eos is added
// - if (SrcLen+1) is specified then the eos IS added
lv_Len = MultiByteToWideChar(CP_UTF8, 0, in_Src, -1, out_Dst, in_MaxLen);
/*
for (i = 0; i < strlen(in_Src); i++)
{
fprintf(stderr, "[%i]=%i\n", i, in_Src[i]);
}
*/
// validate
if (lv_Len < 0)
lv_Len = 0;
// ensure eos, watch out for a full buffersize
// - if the buffer is full without an eos then clear the output like MBTWC does
// in case of too small outputbuffer
// - unfortunately there is no way to let MBTWC return shortened strings,
// if the outputbuffer is too small then it fails completely
if (lv_Len < in_MaxLen)
out_Dst[lv_Len] = 0;
else if (out_Dst[in_MaxLen-1])
out_Dst[0] = 0;
// done
return TRUE;
}
int mystat(char * f, stath s)
{
wchar_t wf[2000];
int n;
n= AnsiToUnicode16(f, wf, 2000);
return(_wstati64(wf,s));
}
fileh myfopen(const char * f, char * m)
{
wchar_t wf[2000], wm[2000];
int n;
n= AnsiToUnicode16(f, wf, 2000);
n= AnsiToUnicode16(m, wm, 2000);
return(_wfopen(wf,wm));
}
int myremove(char * f)
{
wchar_t wf[2000];
int n;
n= AnsiToUnicode16(f, wf, 2000);
return(_wremove(wf));
}
#endif
#if !defined(_WIN32)
int mystat(char * f, stath s)
{
return stat(f, s);
}
fileh myfopen(const char * f, char * m)
{
return fopen(f, m);
}
int myremove(char * f)
{
return unlink(f);
}
#endif
#if !defined(_WIN32)
int min(int i, int j)
{
return(i<j?i:j);
}
int max(int i, int j)
{
return(i>j?i:j);
}
char *_strupr(char *string)
{
char *s;
if (string)
{
for (s = string; *s; ++s)
*s = toupper(*s);
}
return string;
}
#endif
#if defined(_WIN32) && !defined(__MINGW32__) && !defined(__MINGW64__)
void gettimeofday (struct timeval * tp, void * dummy)
{
struct _timeb tm;
_ftime (&tm);
tp->tv_sec = tm.time;
tp->tv_usec = tm.millitm * 1000;
}
#endif