1*0ac341f1SConrad Meyer
2*0ac341f1SConrad Meyer #include <stdlib.h>
3*0ac341f1SConrad Meyer
4*0ac341f1SConrad Meyer /* C++Builder defines a "random" macro */
5*0ac341f1SConrad Meyer #undef random
6*0ac341f1SConrad Meyer
7*0ac341f1SConrad Meyer #ifdef __native_client__
8*0ac341f1SConrad Meyer # define memset(dst, c, n) xmemset(dst, c, n)
9*0ac341f1SConrad Meyer
10*0ac341f1SConrad Meyer static void *
xmemset(void * dst,int c,size_t n)11*0ac341f1SConrad Meyer xmemset(void *dst, int c, size_t n)
12*0ac341f1SConrad Meyer {
13*0ac341f1SConrad Meyer unsigned char * dst_ = (unsigned char *) dst;
14*0ac341f1SConrad Meyer const unsigned char c_ = (unsigned char) c;
15*0ac341f1SConrad Meyer size_t i;
16*0ac341f1SConrad Meyer
17*0ac341f1SConrad Meyer for (i = 0; i < n; i++) {
18*0ac341f1SConrad Meyer dst_[i] = c_;
19*0ac341f1SConrad Meyer }
20*0ac341f1SConrad Meyer return dst;
21*0ac341f1SConrad Meyer }
22*0ac341f1SConrad Meyer #endif
23*0ac341f1SConrad Meyer
24*0ac341f1SConrad Meyer #ifdef __EMSCRIPTEN__
25*0ac341f1SConrad Meyer # define strcmp(s1, s2) xstrcmp(s1, s2)
26*0ac341f1SConrad Meyer
27*0ac341f1SConrad Meyer static int
strcmp(const char * s1,const char * s2)28*0ac341f1SConrad Meyer strcmp(const char *s1, const char *s2)
29*0ac341f1SConrad Meyer {
30*0ac341f1SConrad Meyer while (*s1 == *s2++) {
31*0ac341f1SConrad Meyer if (*s1++ == 0) {
32*0ac341f1SConrad Meyer return 0;
33*0ac341f1SConrad Meyer }
34*0ac341f1SConrad Meyer }
35*0ac341f1SConrad Meyer return *(unsigned char *) s1 - *(unsigned char *) --s2;
36*0ac341f1SConrad Meyer }
37*0ac341f1SConrad Meyer #endif
38*0ac341f1SConrad Meyer
39*0ac341f1SConrad Meyer #ifdef _WIN32
40*0ac341f1SConrad Meyer static void
srandom(unsigned seed)41*0ac341f1SConrad Meyer srandom(unsigned seed)
42*0ac341f1SConrad Meyer {
43*0ac341f1SConrad Meyer srand(seed);
44*0ac341f1SConrad Meyer }
45*0ac341f1SConrad Meyer
46*0ac341f1SConrad Meyer static long
random(void)47*0ac341f1SConrad Meyer random(void)
48*0ac341f1SConrad Meyer {
49*0ac341f1SConrad Meyer return (long) rand();
50*0ac341f1SConrad Meyer }
51*0ac341f1SConrad Meyer #endif
52