random() for Windoze

async_key_management
vb 8 years ago
parent 867651482e
commit 46a44263fe

@ -12,12 +12,15 @@ static char * generate_boundary(const char * boundary_prefix)
time_t now;
char name[MAX_MESSAGE_ID];
long value;
id[MAX_MESSAGE_ID - 1] = 0;
name[MAX_MESSAGE_ID - 1] = 0;
now = time(NULL);
#ifndef WIN32
value = random();
gethostname(name, MAX_MESSAGE_ID);
gethostname(name, MAX_MESSAGE_ID - 1);
#else
value = now;
strcpy(name, "WINDOWS");

@ -13,7 +13,7 @@ extern "C" {
// plaintext (in) plaintext of message as UTF-8 string
// htmltext (in) optional HTML version of message as UTF-8
// string or NULL if it does not apply
// resulttext (out) the resulting encoded text
// resulttext (out) the resulting encoded text or NULL on any error
//
// return value:
// PEP_STATUS_OK if everything worked

@ -7,6 +7,8 @@
#define _WIN32_WINNT 0x0600
#include <windows.h>
#define _CRT_RAND_S
#include <stdlib.h>
#include <assert.h>
#include <string>
#include <stdexcept>
@ -186,4 +188,18 @@ const char *gpg_conf()
return path.c_str();
}
long random(void)
{
unsigned int r;
errno_t e;
assert(sizeof(unsigned int) == sizeof(long)); // this is Windoze
do {
e = rand_s(&r);
} while (e);
return (long) (r & ((1<<31)-1));
}
} // "C"

@ -23,6 +23,8 @@ const char *windoze_local_db(void);
const char *windoze_system_db(void);
const char *gpg_conf(void);
long random(void);
#ifdef __cplusplus
}
#endif

Loading…
Cancel
Save