#ifndef PORTABLE
# include <unistd.h>
+# include <sys/time.h>
#endif
#include <mLib/darray.h>
return (0);
}
+static double doubletime(void)
+{
+#ifdef PORTABLE
+ static time_t start = (time_t)-1;
+ time_t now = time(0);
+
+ if (start == (time_t)-1) start = now;
+ return difftime(now, start);
+#else
+ struct timeval tv;
+
+ gettimeofday(&tv, 0);
+ return (tv.tv_sec + tv.tv_usec/1000000.0);
+#endif
+}
+
static int generate(grand *r, mp *outsz,
int (*func)(const void *buf, size_t sz, void *p),
void *p)
unsigned percent = 0;
mp *kb = MP_ZERO, *t = MP_NEW;
dstr d = DSTR_INIT;
- time_t last;
+ double now, last;
static char baton[] = "-\\|/";
char *bp;
int rc;
/* --- Spit out random data --- */
- last = time(0);
+ last = doubletime();
bp = baton;
if (flags & f_progress) {
char *errbuf = xmalloc(BUFSIZ);
/* --- Update the display --- */
if (flags & f_progress) {
- time_t now = time(0);
unsigned up = 0;
+ now = doubletime();
+
if (percent > 100)
up = 1;
if (!outsz) {
- if (difftime(now, last) > 1.0) {
+ if (now - last > 1.0) {
up = 1;
}
if (up)
mp_div(&t, 0, t, outsz);
assert(!MP_NEGP(t) && MP_CMP(t, <, MP_UINT_MAX));
pc = mp_touint(t);
- if (pc > percent || percent > 100 || difftime(now, last) > 1.0) {
+ if (pc > percent || percent > 100 || now - last > 1.0) {
if (percent > 100)
percent = 0;
percent &= ~1;