]> git.saurik.com Git - apple/security.git/blob - OSX/libsecurity_cryptkit/ckutils/ckutilsPlatform.h
Security-58286.270.3.0.1.tar.gz
[apple/security.git] / OSX / libsecurity_cryptkit / ckutils / ckutilsPlatform.h
1 /*
2 * Platform-dependent stuff for ckutils
3 */
4
5 #ifndef _CKU_PLATFORM_H_
6 #define _CKU_PLATFORM_H_
7
8 #include <string.h>
9 #include <stdlib.h>
10
11 /* use this for linux compatibility testing */
12 //#define linux 1
13 /* end linux test */
14
15 /*
16 * Make sure endianness is defined...
17 */
18 #if !defined(__BIG_ENDIAN__) && !defined(__LITTLE_ENDIAN__)
19 #if macintosh
20 #define __BIG_ENDIAN__ 1
21 #elif defined(i386) || defined(i486) || defined(__i386__) || defined(__i486__)
22 #define __LITTLE_ENDIAN__ 1
23 #else
24 #error Platform dependent work needed
25 #endif
26 #endif /* endian */
27
28 #ifdef NeXT
29 #import <libc.h>
30 #define SRAND(x) srandom(x)
31 #define RAND() random()
32 #else NeXT
33 /*
34 * Use stdlib only
35 */
36 #define SRAND(x) srand(x)
37 #define RAND() rand()
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)
41 #endif
42
43 #ifdef CK_NT_C_ONLY
44
45 /*
46 * Standard I/O redirects for WINNT.
47 */
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)
53
54 #define O_RDONLY _O_RDONLY
55 #define O_WRONLY _O_WRONLY
56 #define O_CREAT _O_CREAT
57 #define O_TRUNC _O_TRUNC
58
59 #endif CK_NT_C_ONLY
60
61 /*
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.
65 */
66 #if macintosh
67
68 #include <Timer.h>
69
70 #define PLAT_TIME UnsignedWide
71 #define PLAT_GET_TIME(pt) Microseconds(&pt)
72 #define PLAT_GET_US(start,end) (end.lo - start.lo)
73
74 #elif linux
75
76 #include <sys/time.h>
77
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) )
83
84 #elif NeXT
85
86 #include <kern/time_stamp.h>
87
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)
91
92
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)
102 #else
103 #error Platform dependent work needed
104 #endif
105
106 #endif /* _CKU_PLATFORM_H_ */