libsodium/test/default/cmptest.h
Frank Denis 8088e486ee strcmp() with optimization level > 1 is broken on Emscripten (!)
Trivial workaround that should eventually go to the quirks file
until this is fixed in Emscripten.
2015-01-22 19:06:21 +01:00

74 lines
1.4 KiB
C

#ifndef __CMPTEST_H__
#define __CMPTEST_H__
#include <assert.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include "sodium.h"
#ifdef __EMSCRIPTEN__
# undef TEST_SRCDIR
# define TEST_SRCDIR "/test-data"
#endif
#ifndef TEST_SRCDIR
# define TEST_SRCDIR "."
#endif
#define TEST_NAME_RES TEST_NAME ".res"
#define TEST_NAME_OUT TEST_SRCDIR "/" TEST_NAME ".exp"
#ifdef HAVE_ARC4RANDOM
# undef rand
# define rand(X) arc4random(X)
#endif
#ifdef __EMSCRIPTEN__
# define strcmp(s1, s2) xstrcmp(s1, s2)
int strcmp(const char *s1, const char *s2) {
while (*s1 == *s2++) { if (*s1++ == 0) return 0; }
return *(unsigned char *) s1 - *(unsigned char *) --s2;
}
#endif
FILE *fp_res;
int xmain(void);
int main(void)
{
FILE *fp_out;
int c;
if ((fp_res = fopen(TEST_NAME_RES, "w+")) == NULL) {
perror("fopen(" TEST_NAME_RES ")");
return 99;
}
if (sodium_init() != 0) {
return 99;
}
if (xmain() != 0) {
return 99;
}
rewind(fp_res);
if ((fp_out = fopen(TEST_NAME_OUT, "r")) == NULL) {
perror("fopen(" TEST_NAME_OUT ")");
return 99;
}
do {
if ((c = fgetc(fp_res)) != fgetc(fp_out)) {
return 99;
}
} while (c != EOF);
return 0;
}
#undef printf
#define printf(...) fprintf(fp_res, __VA_ARGS__)
#define main xmain
#endif