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