#include "archive.h"
#include "archive_private.h"
+#include "archive_random_private.h"
#include "archive_string.h"
#ifndef O_CLOEXEC
struct stat st;
int fd;
char *tp, *ep;
- unsigned seed;
fd = -1;
archive_string_init(&temp_name);
archive_strcat(&temp_name, "XXXXXXXXXX");
ep = temp_name.s + archive_strlen(&temp_name);
- fd = open("/dev/random", O_RDONLY | O_CLOEXEC);
- __archive_ensure_cloexec_flag(fd);
- if (fd < 0)
- seed = time(NULL);
- else {
- if (read(fd, &seed, sizeof(seed)) < 0)
- seed = time(NULL);
- close(fd);
- }
do {
char *p;
p = tp;
- while (p < ep)
- *p++ = num[((unsigned)rand_r(&seed)) % sizeof(num)];
+ archive_random(p, ep - p);
+ while (p < ep) {
+ int d = *((unsigned char *)p) % sizeof(num);
+ *p++ = num[d];
+ }
fd = open(temp_name.s, O_CREAT | O_EXCL | O_RDWR | O_CLOEXEC,
0600);
} while (fd < 0 && errno == EEXIST);
#include "archive_entry.h"
#include "archive_entry_locale.h"
#include "archive_private.h"
+#include "archive_random_private.h"
#include "archive_write_private.h"
struct warc_s {
w->typ = 0;
/* also initialise our rng */
w->rng = (unsigned int)w->now;
- srand(w->rng);
a->format_data = w;
a->format_name = "WARC/1.0";
static int
_gen_uuid(warc_uuid_t *tgt)
{
- tgt->u[0U] = (unsigned int)rand();
- tgt->u[1U] = (unsigned int)rand();
- tgt->u[2U] = (unsigned int)rand();
- tgt->u[3U] = (unsigned int)rand();
+ archive_random(tgt->u, sizeof(tgt->u));
/* obey uuid version 4 rules */
tgt->u[1U] &= 0xffff0fffU;
tgt->u[1U] |= 0x4000U;