mirror of
https://github.com/hashcat/hashcat.git
synced 2025-06-05 23:58:49 +00:00
Fix clock_gettime() on OSX
This commit is contained in:
parent
a680f194e8
commit
4f8343b8b1
@ -6,6 +6,13 @@
|
|||||||
#ifndef _TIMER_H
|
#ifndef _TIMER_H
|
||||||
#define _TIMER_H
|
#define _TIMER_H
|
||||||
|
|
||||||
|
#if defined(__APPLE__)
|
||||||
|
#include <sys/time.h>
|
||||||
|
#include <mach/clock.h>
|
||||||
|
#include <mach/mach.h>
|
||||||
|
#include <mach/mach_time.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
void hc_timer_set (hc_timer_t *a);
|
void hc_timer_set (hc_timer_t *a);
|
||||||
double hc_timer_get (hc_timer_t a);
|
double hc_timer_get (hc_timer_t a);
|
||||||
|
|
||||||
|
18
src/timer.c
18
src/timer.c
@ -33,7 +33,25 @@ inline double hc_timer_get (hc_timer_t a)
|
|||||||
|
|
||||||
inline void hc_timer_set (hc_timer_t* a)
|
inline void hc_timer_set (hc_timer_t* a)
|
||||||
{
|
{
|
||||||
|
#if defined (__APPLE__)
|
||||||
|
// taken from proxmark3/client/util_posix
|
||||||
|
static uint64_t clock_start_time = 0;
|
||||||
|
static mach_timebase_info_data_t timebase_info = {0, 0};
|
||||||
|
uint64_t now = mach_absolute_time();
|
||||||
|
|
||||||
|
if (clock_start_time == 0)
|
||||||
|
{
|
||||||
|
mach_timebase_info(&timebase_info);
|
||||||
|
clock_start_time = now;
|
||||||
|
}
|
||||||
|
|
||||||
|
now = (uint64_t)((double)(now - clock_start_time) * (double)timebase_info.numer / (double)timebase_info.denom);
|
||||||
|
|
||||||
|
a->tv_sec = now / 1000000000;
|
||||||
|
a->tv_nsec = now % 1000000000;
|
||||||
|
#else
|
||||||
clock_gettime (CLOCK_MONOTONIC, a);
|
clock_gettime (CLOCK_MONOTONIC, a);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
inline double hc_timer_get (hc_timer_t a)
|
inline double hc_timer_get (hc_timer_t a)
|
||||||
|
Loading…
Reference in New Issue
Block a user