Commit 77e76d73 authored by Yoni Fogel's avatar Yoni Fogel

Addresses #1531 portability layer changes required for porting utils

git-svn-id: file:///svn/toku/tokudb@10480 c7de825b-a66e-492c-adef-691d508d4ae1
parent 0a6ee4d2
#include <unistd.h>
char *optarg;
int optind;
static const char *match(char c, const char *optstring) {
int i;
......@@ -16,6 +17,7 @@ int getopt(int argc, char * const argv[], const char *optstring) {
const char *theopt;
if (lastargc == 0) {
lastargc = 1;
optind = 1;
}
optarg = 0;
if (lastargc >= argc) {
......@@ -41,6 +43,7 @@ int getopt(int argc, char * const argv[], const char *optstring) {
} else
optarg = argv[lastargc++];
}
optind = lastargc;
return theopt[0];
}
#ifndef _TOKUWIN_GETOPT_H
#define _TOKUWIN_GETOPT_H
#if defined(__cplusplus)
extern "C" {
#endif
int
getopt(int argc, char *const argv[], const char *optstring);
extern char *optarg;
extern int optind;
#if defined(__cplusplus)
};
#endif
#endif
......@@ -7,13 +7,27 @@
#include <toku_stdlib.h>
#include <windows.h>
static int used_srand = 0;
long int
random(void) {
u_int32_t r;
errno_t r_error = rand_s(&r);
assert(r_error==0);
//Should return 0 to 2**31-1 instead of 2**32-1
r >>= 1;
if (used_srand) {
//rand is a relatively poor number generator, but can be seeded
//rand generates 15 bits. We need 3 calls to generate 31 bits.
u_int32_t r1 = rand() & ((1<<15)-1);
u_int32_t r2 = rand() & ((1<<15)-1);;
u_int32_t r3 = rand() & 0x1;
r = r1 | (r2<<15) | (r3<<30);
}
else {
//rand_s is a good number generator, but cannot be seeded (for
//repeatability).
errno_t r_error = rand_s(&r);
assert(r_error==0);
//Should return 0 to 2**31-1 instead of 2**32-1
r >>= 1;
}
return r;
}
......@@ -21,6 +35,7 @@ random(void) {
//reimplement random.
void
srandom(unsigned int seed) {
seed = seed;
srand(seed);
used_srand = 1;
}
......@@ -8,6 +8,7 @@ extern "C" {
#include <io.h>
#include <stdio.h>
#include <stdint.h>
#include <getopt.h>
int fsync(int fildes);
......@@ -26,11 +27,6 @@ sleep(unsigned int);
int
usleep(unsigned int);
int
getopt(int argc, char *const argv[], const char *optstring);
extern char *optarg;
#if defined(__cplusplus)
};
#endif
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment