e8455a3b5540f3de8a0c13f7bb8f73e124894f93
[openafs.git] / src / crypto / hcrypto / roken.h
1 #ifndef OPENAFS_ROKEN_H
2 #define OPENAFS_ROKEN_H
3
4 #ifdef AFS_NT40_ENV
5 #include <windows.h>
6
7 #ifdef _MSC_VER
8 /* Declarations for Microsoft Visual C runtime in Windows */
9 #include <process.h>
10
11 #include <io.h>
12
13 #ifndef __BITS_TYPES_DEFINED__
14 #define __BITS_TYPES_DEFINED__
15
16 typedef __int8                  int8_t;
17 typedef __int16                 int16_t;
18 typedef __int32                 int32_t;
19 typedef __int64                 int64_t;
20 typedef unsigned __int8         uint8_t;
21 typedef unsigned __int16        uint16_t;
22 typedef unsigned __int32        uint32_t;
23 typedef unsigned __int64        uint64_t;
24 typedef uint8_t                 u_int8_t;
25 typedef uint16_t                u_int16_t;
26 typedef uint32_t                u_int32_t;
27 typedef uint64_t                u_int64_t;
28
29 #endif /* __BITS_TYPES_DEFINED__ */
30
31 #ifndef HAVE_SSIZE_T
32 #ifdef _WIN64
33 typedef __int64 ssize_t;
34 #else
35 typedef int ssize_t;
36 #endif
37 #endif
38
39 /* The MSVC implementation of snprintf is not C99 compliant.  */
40 #define snprintf    rk_snprintf
41 #define vsnprintf   rk_vsnprintf
42 #define vasnprintf  rk_vasnprintf
43 #define vasprintf   rk_vasprintf
44 #define asnprintf   rk_asnprintf
45 #define asprintf    rk_asprintf
46
47 #endif /* _MSC_VER */
48 #endif /* AFS_NT40_ENV */
49
50 #define rk_UNCONST(x) ((void *)(uintptr_t)(const void *)(x))
51
52 #ifndef min
53 #define min(a,b) (((a)<(b))?(a):(b))
54 #endif
55
56 #ifndef ROKEN_LIB_FUNCTION
57 #ifdef _WIN32
58 #define ROKEN_LIB_FUNCTION
59 #define ROKEN_LIB_CALL     __cdecl
60 #else
61 #define ROKEN_LIB_FUNCTION
62 #define ROKEN_LIB_CALL
63 #endif
64 #endif
65
66 #ifndef HAVE___ATTRIBUTE__
67 #define __attribute__(x)
68 #endif
69
70 typedef int rk_socket_t;
71
72 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
73     ct_memcmp(const void *, const void *, size_t);
74
75 ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL rk_cloexec(int);
76
77 ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL rk_cloexec_file(FILE *);
78
79 ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
80     net_write (rk_socket_t, const void *, size_t);
81
82 ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
83     net_read (rk_socket_t, void *, size_t);
84
85 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL issuid(void);
86
87 #if !defined(HAVE_SNPRINTF) || defined(NEED_SNPRINTF_PROTO)
88 #ifndef HAVE_SNPRINTF
89 #define snprintf rk_snprintf
90 #endif
91 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
92      rk_snprintf (char *, size_t, const char *, ...)
93      __attribute__ ((format (printf, 3, 4)));
94 #endif
95
96 #if !defined(HAVE_VSNPRINTF) || defined(NEED_VSNPRINTF_PROTO)
97 #ifndef HAVE_VSNPRINTF
98 #define vsnprintf rk_vsnprintf
99 #endif
100 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL 
101      rk_vsnprintf (char *, size_t, const char *, va_list)
102      __attribute__((format (printf, 3, 0)));
103 #endif
104
105 #if !defined(HAVE_ASPRINTF) || defined(NEED_ASPRINTF_PROTO)
106 #ifndef HAVE_ASPRINTF
107 #define asprintf rk_asprintf
108 #endif
109 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
110      rk_asprintf (char **, const char *, ...)
111      __attribute__ ((format (printf, 2, 3)));
112 #endif
113
114 #if !defined(HAVE_VASPRINTF) || defined(NEED_VASPRINTF_PROTO)
115 #ifndef HAVE_VASPRINTF
116 #define vasprintf rk_vasprintf
117 #endif
118 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
119     rk_vasprintf (char **, const char *, va_list)
120      __attribute__((format (printf, 2, 0)));
121 #endif
122
123 #if !defined(HAVE_ASNPRINTF) || defined(NEED_ASNPRINTF_PROTO)
124 #ifndef HAVE_ASNPRINTF
125 #define asnprintf rk_asnprintf
126 #endif
127 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
128     rk_asnprintf (char **, size_t, const char *, ...)
129      __attribute__ ((format (printf, 3, 4)));
130 #endif
131
132 #if !defined(HAVE_VASNPRINTF) || defined(NEED_VASNPRINTF_PROTO)
133 #ifndef HAVE_VASNPRINTF
134 #define vasnprintf rk_vasnprintf
135 #endif
136 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
137     vasnprintf (char **, size_t, const char *, va_list)
138      __attribute__((format (printf, 3, 0)));
139 #endif
140
141 #ifndef HAVE_STRLCPY
142 #define strlcpy rk_strlcpy
143 ROKEN_LIB_FUNCTION size_t ROKEN_LIB_CALL
144     strlcpy (char *, const char *, size_t);
145 #endif
146
147 #ifndef HAVE_DIRFD
148 # ifdef HAVE_DIR_DD_FD
149 #  define dirfd(x) ((x)->dd_fd)
150 # else
151 #  ifndef _WIN32 /* Windows code never calls dirfd */
152 #   error Missing dirfd() and ->dd_fd
153 #  endif
154 # endif
155 #endif
156
157 /* This is a bodge, but it's only used by the tests */
158 #define emalloc(x) malloc(x)
159
160 #ifndef HAVE_GETPROGNAME
161 ROKEN_LIB_FUNCTION const char * ROKEN_LIB_CALL getprogname(void);
162 #endif
163
164 #ifndef _PATH_DEVNULL
165 #define _PATH_DEVNULL "/dev/null"
166 #endif
167
168
169 #endif /* OPENAFS_ROKEN_H */