]>
git.zerfleddert.de Git - proxmark3-svn/blob - client/util_posix.c
3e61b67469df2e31446fa38ccf52d047de9095d6
1 //-----------------------------------------------------------------------------
2 // Copyright (C) 2010 iZsh <izsh at fail0verflow.com>
4 // This code is licensed to you under the terms of the GNU GPL, version 2 or,
5 // at your option, any later version. See the LICENSE.txt file for the text of
7 //-----------------------------------------------------------------------------
8 // utilities requiring Posix library functions
9 //-----------------------------------------------------------------------------
12 #define _POSIX_C_SOURCE 199309L // need nanosleep()
17 #include "util_posix.h"
26 static void nsleep(uint64_t n
) {
27 struct timespec timeout
;
28 timeout
.tv_sec
= n
/1000000000;
29 timeout
.tv_nsec
= n
%1000000000;
30 while (nanosleep(&timeout
, &timeout
) && errno
== EINTR
);
33 void msleep(uint32_t n
) {
38 // a milliseconds timer for performance measurement
41 #include <sys/types.h>
43 // WORKAROUND FOR MinGW (some versions - use if normal code does not compile)
44 // It has no _ftime_s and needs explicit inclusion of timeb.h
45 #include <sys/timeb.h>
48 return 1000 * t
.time
+ t
.millitm
;
50 // NORMAL CODE (use _ftime_s)
55 // return 1000 * t.time + t.millitm;
59 clock_gettime(CLOCK_MONOTONIC
, &t
);
60 return (t
.tv_sec
* 1000 + t
.tv_nsec
/ 1000000);