source: zzuf/trunk/src/timer.c @ 1702

Last change on this file since 1702 was 1702, checked in by Sam Hocevar, 13 years ago
  • Added DLL injection to the Win32 port attempt.
  • Property svn:keywords set to Id
File size: 1.4 KB
Line 
1/*
2 *  zzuf - general purpose fuzzer
3 *  Copyright (c) 2006 Sam Hocevar <sam@zoy.org>
4 *                All Rights Reserved
5 *
6 *  $Id: timer.c 1702 2007-01-24 15:06:17Z sam $
7 *
8 *  This program is free software. It comes without any warranty, to
9 *  the extent permitted by applicable law. You can redistribute it
10 *  and/or modify it under the terms of the Do What The Fuck You Want
11 *  To Public License, Version 2, as published by Sam Hocevar. See
12 *  http://sam.zoy.org/wtfpl/COPYING for more details.
13 */
14
15/*
16 *  timer.c: timing functions
17 */
18
19#include "config.h"
20
21#if defined HAVE_STDINT_H
22#   include <stdint.h>
23#elif defined HAVE_INTTYPES_H
24#   include <inttypes.h>
25#endif
26#if defined HAVE_WINDOWS_H
27#   include <windows.h>
28#endif
29#include <stdio.h>
30#include <sys/time.h>
31#include <time.h>
32
33#include "timer.h"
34
35int64_t _zz_time(void)
36{
37#if defined HAVE_GETTIMEOFDAY
38    struct timeval tv;
39    gettimeofday(&tv, NULL);
40    return (int64_t)tv.tv_sec * 1000000 + tv.tv_usec;
41#else
42    static CRITICAL_SECTION cs;
43    static unsigned long int prev;
44    static int64_t tv_base = 0;
45    unsigned long int tv_msec;
46
47    if(tv_base == 0)
48    {
49        tv_base = 1;
50        prev = 0;
51        InitializeCriticalSection(&cs);
52    }
53
54    EnterCriticalSection(&cs);
55    tv_msec = GetTickCount();
56    if(tv_msec < prev)
57        tv_base += 0x100000000LL; /* We wrapped */
58    prev = tv_msec;
59    LeaveCriticalSection(&cs);
60
61    return (tv_base + tv_msec) * 1000;
62#endif
63}
64
Note: See TracBrowser for help on using the repository browser.