소스 검색

Switch from rand_r to rand in lhash_test.

Android doesn't support rand_r.

Change-Id: Iaea767f64da4f6b83907c20d891811a0023ce530
kris/onging/CECPQ3_patch15
Adam Langley 10 년 전
부모
커밋
2f1f89d6af
1개의 변경된 파일7개의 추가작업 그리고 14개의 파일을 삭제
  1. +7
    -14
      crypto/lhash/lhash_test.c

+ 7
- 14
crypto/lhash/lhash_test.c 파일 보기

@@ -14,12 +14,6 @@

#define _BSD_SOURCE

#if !defined(__APPLE__)
/* _POSIX_SOURCE is needed on Linux in order to get rand_r, but on OS X causes
* a build failure. */
#define _POSIX_SOURCE
#endif

#include <openssl/lhash.h>

#include <stdio.h>
@@ -105,13 +99,13 @@ static char *dummy_lh_delete(struct dummy_lhash *lh, const void *s) {
return NULL;
}

static char *rand_string(unsigned *rand_state) {
unsigned len = 1 + (rand_r(rand_state) % 3);
static char *rand_string() {
unsigned len = 1 + (rand() % 3);
char *ret = malloc(len + 1);
unsigned i;

for (i = 0; i < len; i++) {
ret[i] = '0' + (rand_r(rand_state) & 7);
ret[i] = '0' + (rand() & 7);
}
ret[i] = 0;

@@ -121,7 +115,6 @@ static char *rand_string(unsigned *rand_state) {
int main(int argc, char **argv) {
_LHASH *lh = lh_new(NULL, NULL);
struct dummy_lhash dummy_lh = {NULL};
unsigned rand_state = 0;
unsigned i;

for (i = 0; i < 100000; i++) {
@@ -133,10 +126,10 @@ int main(int argc, char **argv) {
return 1;
}

action = rand_r(&rand_state) % 3;
action = rand() % 3;
switch (action) {
case 0:
s = rand_string(&rand_state);
s = rand_string();
s1 = (char *)lh_retrieve(lh, s);
s2 = dummy_lh_retrieve(&dummy_lh, s);
if (s1 != NULL && (s2 == NULL || strcmp(s1, s2) != 0)) {
@@ -147,7 +140,7 @@ int main(int argc, char **argv) {
break;

case 1:
s = rand_string(&rand_state);
s = rand_string();
lh_insert(lh, (void **)&s1, s);
dummy_lh_insert(&dummy_lh, &s2, strdup(s));

@@ -165,7 +158,7 @@ int main(int argc, char **argv) {
break;

case 2:
s = rand_string(&rand_state);
s = rand_string();
s1 = lh_delete(lh, s);
s2 = dummy_lh_delete(&dummy_lh, s);



불러오는 중...
취소
저장