]>
git.saurik.com Git - apple/security.git/blob - OSX/libsecurity_cryptkit/ckutils/ckutilsPlatform.h
2 * Platform-dependent stuff for ckutils
5 #ifndef _CKU_PLATFORM_H_
6 #define _CKU_PLATFORM_H_
11 /* use this for linux compatibility testing */
16 * Make sure endianness is defined...
18 #if !defined(__BIG_ENDIAN__) && !defined(__LITTLE_ENDIAN__)
20 #define __BIG_ENDIAN__ 1
21 #elif defined(i386) || defined(i486) || defined(__i386__) || defined(__i486__)
22 #define __LITTLE_ENDIAN__ 1
24 #error Platform dependent work needed
30 #define SRAND(x) srandom(x)
31 #define RAND() random()
36 #define SRAND(x) srand(x)
38 #define bcopy(s, d, l) memmove(d, s, l)
39 #define bzero(s, l) memset(s, 0, l)
40 #define bcmp(s, d, l) memcmp(s, d, l)
46 * Standard I/O redirects for WINNT.
48 #define open(f, b, c) _open(f, b, c)
49 #define close(f) _close(f)
50 #define read(f, b, c) _read(f, b, c)
51 #define write(f, b, c) _write(f, b, c)
52 #define fstat(f, b) _fstat(f, b)
54 #define O_RDONLY _O_RDONLY
55 #define O_WRONLY _O_WRONLY
56 #define O_CREAT _O_CREAT
57 #define O_TRUNC _O_TRUNC
62 * Platform-dependent timestamp stuff. For now we assume that each platform
63 * has some kind of struct which maintains a high-resolution clock and
64 * a function which fills that struct with the current time.
70 #define PLAT_TIME UnsignedWide
71 #define PLAT_GET_TIME(pt) Microseconds(&pt)
72 #define PLAT_GET_US(start,end) (end.lo - start.lo)
78 #define PLAT_TIME struct timeval
79 #define PLAT_GET_TIME(pt) gettimeofday(&pt, NULL)
80 #define PLAT_GET_US(start,end) \
81 ( ( ( (end.tv_sec & 0xff) * 1000000) + end.tv_usec) - \
82 ( ( (start.tv_sec & 0xff) * 1000000) + start.tv_usec) )
86 #include <kern/time_stamp.h>
88 #define PLAT_TIME struct tsval
89 #define PLAT_GET_TIME(pt) kern_timestamp(&pt)
90 #define PLAT_GET_US(start,end) (end.low_val - start.low_val)
93 #elif defined(__MACH__) && defined(__APPLE__)
94 #include <CoreFoundation/CoreFoundation.h>
95 /* time as a double */
96 #define PLAT_TIME CFAbsoluteTime
97 #define PLAT_GET_TIME(pt) pt = CFAbsoluteTimeGetCurrent()
98 #define PLAT_GET_US(start,end) \
99 ((end - start) * 1000000.0)
100 #define PLAT_GET_NS(start,end) \
101 ((end - start) * 1000000000.0)
103 #error Platform dependent work needed
106 #endif /* _CKU_PLATFORM_H_ */