]> git.ipfire.org Git - thirdparty/openssl.git/blame - e_os.h
Move PRIu64, OSSLzu to e_os.h
[thirdparty/openssl.git] / e_os.h
CommitLineData
b6cff313
RS
1/*
2 * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
0f113f3e 3 *
b6cff313
RS
4 * Licensed under the OpenSSL license (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
d02b48c6
RE
8 */
9
10#ifndef HEADER_E_OS_H
0f113f3e 11# define HEADER_E_OS_H
d02b48c6 12
0f113f3e 13# include <openssl/opensslconf.h>
06018c46 14
0f113f3e
MC
15# include <openssl/e_os2.h>
16/*
17 * <openssl/e_os2.h> contains what we can justify to make visible to the
18 * outside; this file e_os.h is not part of the exported interface.
19 */
fa470a84 20
d02b48c6
RE
21#ifdef __cplusplus
22extern "C" {
23#endif
24
58964a49 25/* Used to checking reference counts, most while doing perl5 stuff :-) */
f3f1cf84 26# if defined(OPENSSL_NO_STDIO)
f3f1cf84
RS
27# if defined(REF_PRINT)
28# error "REF_PRINT requires stdio"
29# endif
0f113f3e 30# endif
f3f1cf84 31
43708c15
RS
32/*
33 * We need a format operator for some client tools for uint64_t. If inttypes.h
34 * isn't available or did not define it, just go with hard-coded.
35 */
36# if defined(OPENSSL_SYS_UEFI)
37# define PRIu64 "Lu"
38# endif
39# ifndef PRIu64
40# ifdef SIXTY_FOUR_BIT_LONG
41# define PRIu64 "lu"
42# else
43# define PRIu64 "llu"
44# endif
45# endif
46
47/* Format specifier for printing size_t */
48# if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L)
49# define OSSLzu "zu"
50# else
51# ifdef THIRTY_TWO_BIT
52# define OSSLzu "u"
53# else
54# define OSSLzu PRIu64
55# endif
56# endif
57
463a7b8c 58# if !defined(NDEBUG) && !defined(OPENSSL_NO_STDIO)
f3f1cf84 59# define REF_ASSERT_ISNT(test) \
040d43b3 60 (void)((test) ? (OPENSSL_die("refcount error", __FILE__, __LINE__), 1) : 0)
f3f1cf84
RS
61# else
62# define REF_ASSERT_ISNT(i)
984d6c60 63# endif
f3f1cf84
RS
64# ifdef REF_PRINT
65# define REF_PRINT_COUNT(a, b) \
66 fprintf(stderr, "%p:%4d:%s\n", b, b->references, a)
67# else
68# define REF_PRINT_COUNT(a, b)
984d6c60 69# endif
58964a49 70
a773b52a 71# define osslargused(x) (void)x
040d43b3 72# define OPENSSL_CONF "openssl.cnf"
a773b52a 73
0f113f3e
MC
74# ifndef DEVRANDOM
75/*
76 * set this to a comma-separated list of 'random' device files to try out. My
77 * default, we will try to read at least one of these files
78 */
79# define DEVRANDOM "/dev/urandom","/dev/random","/dev/srandom"
80# endif
0423f812 81# if !defined(OPENSSL_NO_EGD) && !defined(DEVRANDOM_EGD)
0f113f3e
MC
82/*
83 * set this to a comma-separated list of 'egd' sockets to try out. These
84 * sockets will be tried in the order listed in case accessing the device
85 * files listed in DEVRANDOM did not return enough entropy.
86 */
87# define DEVRANDOM_EGD "/var/run/egd-pool","/dev/egd-pool","/etc/egd-pool","/etc/entropy"
88# endif
d02b48c6 89
0f113f3e 90# if defined(OPENSSL_SYS_VXWORKS)
3e83e686
RL
91# define NO_SYS_PARAM_H
92# define NO_CHMOD
93# define NO_SYSLOG
0f113f3e
MC
94# endif
95
d02b48c6
RE
96/********************************************************************
97 The Microsoft section
98 ********************************************************************/
0f113f3e 99# if defined(OPENSSL_SYS_WIN32) && !defined(WIN32)
b8384651 100# define WIN32
0f113f3e
MC
101# endif
102# if defined(OPENSSL_SYS_WINDOWS) && !defined(WINDOWS)
cf1b7d96 103# define WINDOWS
0f113f3e
MC
104# endif
105# if defined(OPENSSL_SYS_MSDOS) && !defined(MSDOS)
cf1b7d96 106# define MSDOS
0f113f3e 107# endif
d02b48c6 108
4d60c7e1 109# if (defined(MSDOS) || defined(OPENSSL_SYS_UEFI)) && !defined(GETPID_IS_MEANINGLESS)
9a1e34e5 110# define GETPID_IS_MEANINGLESS
0f113f3e 111# endif
9a1e34e5 112
0f113f3e
MC
113# ifdef WIN32
114# define NO_SYS_UN_H
115# define get_last_sys_error() GetLastError()
116# define clear_sys_error() SetLastError(0)
117# if !defined(WINNT)
118# define WIN_CONSOLE_BUG
119# endif
120# else
121# define get_last_sys_error() errno
122# define clear_sys_error() errno=0
123# endif
58964a49 124
0f113f3e
MC
125# if defined(WINDOWS)
126# define get_last_socket_error() WSAGetLastError()
127# define clear_socket_error() WSASetLastError(0)
128# define readsocket(s,b,n) recv((s),(b),(n),0)
129# define writesocket(s,b,n) send((s),(b),(n),0)
130# elif defined(__DJGPP__)
131# define WATT32
2c25ebd1 132# define WATT32_NO_OLDIES
0f113f3e
MC
133# define get_last_socket_error() errno
134# define clear_socket_error() errno=0
135# define closesocket(s) close_s(s)
136# define readsocket(s,b,n) read_s(s,b,n)
137# define writesocket(s,b,n) send(s,b,n,0)
138# elif defined(OPENSSL_SYS_VMS)
139# define get_last_socket_error() errno
140# define clear_socket_error() errno=0
141# define ioctlsocket(a,b,c) ioctl(a,b,c)
142# define closesocket(s) close(s)
143# define readsocket(s,b,n) recv((s),(b),(n),0)
144# define writesocket(s,b,n) send((s),(b),(n),0)
145# elif defined(OPENSSL_SYS_VXWORKS)
146# define get_last_socket_error() errno
147# define clear_socket_error() errno=0
148# define ioctlsocket(a,b,c) ioctl((a),(b),(int)(c))
149# define closesocket(s) close(s)
150# define readsocket(s,b,n) read((s),(b),(n))
151# define writesocket(s,b,n) write((s),(char *)(b),(n))
0f113f3e
MC
152# else
153# define get_last_socket_error() errno
154# define clear_socket_error() errno=0
155# define ioctlsocket(a,b,c) ioctl(a,b,c)
156# define closesocket(s) close(s)
157# define readsocket(s,b,n) read((s),(b),(n))
158# define writesocket(s,b,n) write((s),(b),(n))
159# endif
58964a49 160
0f113f3e 161# if (defined(WINDOWS) || defined(MSDOS))
d02b48c6 162
f642ebc1 163# ifdef __DJGPP__
0f113f3e
MC
164# include <unistd.h>
165# include <sys/stat.h>
166# include <sys/socket.h>
2c25ebd1 167# include <sys/un.h>
0f113f3e
MC
168# include <tcp.h>
169# include <netdb.h>
170# define _setmode setmode
171# define _O_TEXT O_TEXT
172# define _O_BINARY O_BINARY
2c25ebd1
RL
173# define HAS_LFN_SUPPORT(name) (pathconf((name), _PC_NAME_MAX) > 12)
174# undef DEVRANDOM_EGD /* Neither MS-DOS nor FreeDOS provide 'egd' sockets. */
0f113f3e
MC
175# undef DEVRANDOM
176# define DEVRANDOM "/dev/urandom\x24"
177# endif /* __DJGPP__ */
f642ebc1 178
0056ef5d 179# ifndef S_IFDIR
0f113f3e 180# define S_IFDIR _S_IFDIR
0056ef5d 181# endif
6e064240 182
0056ef5d 183# ifndef S_IFMT
0f113f3e 184# define S_IFMT _S_IFMT
0056ef5d 185# endif
6e064240 186
f642ebc1 187# if !defined(WINNT) && !defined(__DJGPP__)
0f113f3e 188# define NO_SYSLOG
0056ef5d
RL
189# endif
190# define NO_DIRENT
d02b48c6 191
d02b48c6 192# ifdef WINDOWS
0f113f3e 193# if !defined(_WIN32_WCE) && !defined(_WIN32_WINNT)
e476f942 194 /*
0f113f3e
MC
195 * Defining _WIN32_WINNT here in e_os.h implies certain "discipline."
196 * Most notably we ought to check for availability of each specific
0ee05b73
AP
197 * routine that was introduced after denoted _WIN32_WINNT with
198 * GetProcAddress(). Normally newer functions are masked with higher
199 * _WIN32_WINNT in SDK headers. So that if you wish to use them in
200 * some module, you'd need to override _WIN32_WINNT definition in
201 * the target module in order to "reach for" prototypes, but replace
202 * calls to new functions with indirect calls. Alternatively it
203 * might be possible to achieve the goal by /DELAYLOAD-ing .DLLs
204 * and check for current OS version instead.
0f113f3e 205 */
0ee05b73 206# define _WIN32_WINNT 0x0501
0f113f3e 207# endif
2469e76b 208# if defined(_WIN32_WINNT) || defined(_WIN32_WCE)
61aa2134
AP
209 /*
210 * Just like defining _WIN32_WINNT including winsock2.h implies
8711efb4 211 * certain "discipline" for maintaining [broad] binary compatibility.
61aa2134
AP
212 * As long as structures are invariant among Winsock versions,
213 * it's sufficient to check for specific Winsock2 API availability
214 * at run-time [DSO_global_lookup is recommended]...
215 */
0f113f3e
MC
216# include <winsock2.h>
217# include <ws2tcpip.h>
8711efb4 218 /* yes, they have to be #included prior to <windows.h> */
0f113f3e
MC
219# endif
220# include <windows.h>
221# include <stdio.h>
222# include <stddef.h>
223# include <errno.h>
224# if defined(_WIN32_WCE) && !defined(EACCES)
225# define EACCES 13
226# endif
227# include <string.h>
228# ifdef _WIN64
229# define strlen(s) _strlen31(s)
1875e6db 230/* cut strings to 2GB */
55c7a4cf 231static __inline unsigned int _strlen31(const char *str)
0f113f3e
MC
232{
233 unsigned int len = 0;
234 while (*str && len < 0x80000000U)
235 str++, len++;
236 return len & 0x7FFFFFFF;
237}
238# endif
239# include <malloc.h>
240# if defined(_MSC_VER) && _MSC_VER<=1200 && defined(_MT) && defined(isspace)
e527201f 241 /* compensate for bug in VC6 ctype.h */
0f113f3e
MC
242# undef isspace
243# undef isdigit
244# undef isalnum
245# undef isupper
246# undef isxdigit
247# endif
248# if defined(_MSC_VER) && !defined(_WIN32_WCE) && !defined(_DLL) && defined(stdin)
249# if _MSC_VER>=1300 && _MSC_VER<1600
250# undef stdin
251# undef stdout
252# undef stderr
253FILE *__iob_func();
254# define stdin (&__iob_func()[0])
255# define stdout (&__iob_func()[1])
256# define stderr (&__iob_func()[2])
257# elif _MSC_VER<1300 && defined(I_CAN_LIVE_WITH_LNK4049)
258# undef stdin
259# undef stdout
260# undef stderr
261 /*
262 * pre-1300 has __p__iob(), but it's available only in msvcrt.lib,
263 * or in other words with /MD. Declaring implicit import, i.e. with
264 * _imp_ prefix, works correctly with all compiler options, but
265 * without /MD results in LINK warning LNK4049: 'locally defined
266 * symbol "__iob" imported'.
e527201f 267 */
0f113f3e
MC
268extern FILE *_imp___iob;
269# define stdin (&_imp___iob[0])
270# define stdout (&_imp___iob[1])
271# define stderr (&_imp___iob[2])
e527201f 272# endif
0f113f3e 273# endif
d02b48c6 274# endif
0f113f3e
MC
275# include <io.h>
276# include <fcntl.h>
d02b48c6 277
0bf23d9b 278# ifdef OPENSSL_SYS_WINCE
0f113f3e 279# define OPENSSL_NO_POSIX_IO
0bf23d9b
RL
280# endif
281
be7b4458 282# define EXIT(n) exit(n)
d02b48c6 283# define LIST_SEPARATOR_CHAR ';'
0056ef5d 284# ifndef X_OK
0f113f3e 285# define X_OK 0
0056ef5d
RL
286# endif
287# ifndef W_OK
0f113f3e 288# define W_OK 2
0056ef5d
RL
289# endif
290# ifndef R_OK
0f113f3e 291# define R_OK 4
0056ef5d 292# endif
0bf23d9b 293# ifdef OPENSSL_SYS_WINCE
0f113f3e 294# define DEFAULT_HOME ""
0bf23d9b 295# else
0f113f3e 296# define DEFAULT_HOME "C:"
0bf23d9b 297# endif
d02b48c6 298
86d21d0b 299/* Avoid Visual Studio 13 GetVersion deprecated problems */
0f113f3e
MC
300# if defined(_MSC_VER) && _MSC_VER>=1800
301# define check_winnt() (1)
302# define check_win_minplat(x) (1)
303# else
304# define check_winnt() (GetVersion() < 0x80000000)
305# define check_win_minplat(x) (LOBYTE(LOWORD(GetVersion())) >= (x))
306# endif
f511b25a 307
0f113f3e 308# else /* The non-microsoft world */
d02b48c6 309
cf1b7d96 310# ifdef OPENSSL_SYS_VMS
0f113f3e
MC
311# define VMS 1
312 /*
313 * some programs don't include stdlib, so exit() and others give implicit
314 * function warnings
315 */
316# include <stdlib.h>
317# if defined(__DECC)
318# include <unistd.h>
319# else
320# include <unixlib.h>
321# endif
0f113f3e 322# define LIST_SEPARATOR_CHAR ','
0c61e299 323 /* We don't have any well-defined random devices on VMS, yet... */
0f113f3e 324# undef DEVRANDOM
1d97c843
TH
325 /*-
326 We need to do this since VMS has the following coding on status codes:
511e596b
RL
327
328 Bits 0-2: status type: 0 = warning, 1 = success, 2 = error, 3 = info ...
329 The important thing to know is that odd numbers are considered
0f113f3e 330 good, while even ones are considered errors.
511e596b
RL
331 Bits 3-15: actual status number
332 Bits 16-27: facility number. 0 is considered "unknown"
333 Bits 28-31: control bits. If bit 28 is set, the shell won't try to
334 output the message (which, for random codes, just looks ugly)
335
336 So, what we do here is to change 0 to 1 to get the default success status,
337 and everything else is shifted up to fit into the status number field, and
f625d383 338 the status is tagged as an error, which is what is wanted here.
c3944a99
RL
339
340 Finally, we add the VMS C facility code 0x35a000, because there are some
341 programs, such as Perl, that will reinterpret the code back to something
342 POSIXly. 'man perlvms' explains it further.
f625d383 343
c3944a99
RL
344 NOTE: the perlvms manual wants to turn all codes 2 to 255 into success
345 codes (status type = 1). I couldn't disagree more. Fortunately, the
346 status type doesn't seem to bother Perl.
511e596b
RL
347 -- Richard Levitte
348 */
f625d383
RL
349# define EXIT(n) exit((n) ? (((n) << 3) | 2 | 0x10000000 | 0x35a000) : 1)
350
0f113f3e 351# define NO_SYS_PARAM_H
c168a027 352# define NO_SYS_UN_H
4d8743f4 353
b8f304f7
RL
354# define DEFAULT_HOME "SYS$LOGIN:"
355
d02b48c6 356# else
06018c46 357 /* !defined VMS */
0f113f3e
MC
358# ifdef OPENSSL_UNISTD
359# include OPENSSL_UNISTD
360# else
361# include <unistd.h>
362# endif
363# ifndef NO_SYS_TYPES_H
364# include <sys/types.h>
365# endif
366# ifdef OPENSSL_SYS_WIN32_CYGWIN
367# include <io.h>
368# include <fcntl.h>
369# endif
370
0f113f3e 371# define LIST_SEPARATOR_CHAR ':'
0f113f3e 372# define EXIT(n) exit(n)
d02b48c6 373# endif
d02b48c6 374
0f113f3e 375# endif
7d7d2cbc 376
d02b48c6
RE
377/*************/
378
0f113f3e 379# ifdef USE_SOCKETS
ffbc5b57
DW
380# ifdef OPENSSL_NO_SOCK
381# elif defined(WINDOWS) || defined(MSDOS)
37b1f8bd 382 /* windows world */
ffbc5b57 383# if !defined(__DJGPP__)
0f113f3e
MC
384# if defined(_WIN32_WCE) && _WIN32_WCE<410
385# define getservbyname _masked_declaration_getservbyname
386# endif
387# if !defined(IPPROTO_IP)
a6efc2d1 388 /* winsock[2].h was included already? */
0f113f3e
MC
389# include <winsock.h>
390# endif
391# ifdef getservbyname
392# undef getservbyname
63d3a9c5 393 /* this is used to be wcecompat/include/winsock_extras.h */
0f113f3e
MC
394struct servent *PASCAL getservbyname(const char *, const char *);
395# endif
63d3a9c5 396
0f113f3e 397# ifdef _WIN64
1875e6db
AP
398/*
399 * Even though sizeof(SOCKET) is 8, it's safe to cast it to int, because
400 * the value constitutes an index in per-process table of limited size
b13fdc48
AP
401 * and not a real pointer. And we also depend on fact that all processors
402 * Windows run on happen to be two's-complement, which allows to
403 * interchange INVALID_SOCKET and -1.
1875e6db 404 */
0f113f3e
MC
405# define socket(d,t,p) ((int)socket(d,t,p))
406# define accept(s,f,l) ((int)accept(s,f,l))
d02b48c6 407# endif
0f113f3e 408# else
0f113f3e 409# endif
d02b48c6 410
0f113f3e 411# else
d02b48c6 412
0f113f3e
MC
413# ifndef NO_SYS_PARAM_H
414# include <sys/param.h>
415# endif
416# ifdef OPENSSL_SYS_VXWORKS
417# include <time.h>
418# endif
419
420# include <netdb.h>
421# if defined(OPENSSL_SYS_VMS_NODECC)
422# include <socket.h>
423# include <in.h>
424# include <inet.h>
425# else
426# include <sys/socket.h>
427# ifndef NO_SYS_UN_H
428# ifdef OPENSSL_SYS_VXWORKS
429# include <streams/un.h>
430# else
431# include <sys/un.h>
432# endif
433# ifndef UNIX_PATH_MAX
434# define UNIX_PATH_MAX sizeof(((struct sockaddr_un *)NULL)->sun_path)
435# endif
a545c6f6 436# endif
0f113f3e 437# ifdef FILIO_H
f6739c3d 438# include <sys/filio.h> /* FIONBIO in some SVR4, e.g. unixware, solaris */
0f113f3e
MC
439# endif
440# include <netinet/in.h>
441# include <arpa/inet.h>
28a0841b 442# include <netinet/tcp.h>
0f113f3e
MC
443# endif
444
445# ifdef OPENSSL_SYS_AIX
446# include <sys/select.h>
447# endif
448
449# ifdef __QNX__
450# include <sys/select.h>
451# endif
452
2f2c805a
AP
453# ifndef VMS
454# include <sys/ioctl.h>
0f113f3e 455# else
2f2c805a
AP
456 /* ioctl is only in VMS > 7.0 and when socketshr is not used */
457# if !defined(TCPIP_TYPE_SOCKETSHR) && defined(__VMS_VER) && (__VMS_VER > 70000000)
0f113f3e 458# include <sys/ioctl.h>
d02b48c6 459# endif
0f113f3e 460# endif
d02b48c6 461
0f113f3e
MC
462# ifdef VMS
463# include <unixio.h>
464# if defined(TCPIP_TYPE_SOCKETSHR)
465# include <socketshr.h>
d02b48c6 466# endif
0f113f3e
MC
467# endif
468
0f113f3e
MC
469# ifndef INVALID_SOCKET
470# define INVALID_SOCKET (-1)
471# endif /* INVALID_SOCKET */
d02b48c6 472# endif
a6dab873 473
0f113f3e
MC
474/*
475 * Some IPv6 implementations are broken, disable them in known bad versions.
a6dab873
DSH
476 */
477# if !defined(OPENSSL_USE_IPV6)
0f113f3e
MC
478# if defined(AF_INET6) && !defined(NETWARE_CLIB)
479# define OPENSSL_USE_IPV6 1
480# else
481# define OPENSSL_USE_IPV6 0
482# endif
a6dab873
DSH
483# endif
484
0f113f3e 485# endif
d02b48c6 486
0f113f3e
MC
487# ifndef OPENSSL_EXIT
488# if defined(MONOLITH) && !defined(OPENSSL_C)
489# define OPENSSL_EXIT(n) return(n)
490# else
491# define OPENSSL_EXIT(n) do { EXIT(n); return(n); } while(0)
492# endif
1c3e4a36 493# endif
1c3e4a36 494
d02b48c6
RE
495/***********************************************/
496
0f113f3e 497# if defined(OPENSSL_SYS_WINDOWS)
e6fa67fa
RL
498# define strcasecmp _stricmp
499# define strncasecmp _strnicmp
dc6b5c7b
RL
500# if (_MSC_VER >= 1310)
501# define open _open
502# define fdopen _fdopen
503# define close _close
8d95ca36
M
504# ifndef strdup
505# define strdup _strdup
506# endif
dc6b5c7b
RL
507# define unlink _unlink
508# endif
7233bea2
RL
509# else
510# include <strings.h>
0f113f3e 511# endif
3bfd99bf 512
6a89a25c 513/* vxworks */
0f113f3e
MC
514# if defined(OPENSSL_SYS_VXWORKS)
515# include <ioLib.h>
516# include <tickLib.h>
517# include <sysLib.h>
6a89a25c 518
0f113f3e 519# define TTY_STRUCT int
6a89a25c 520
0f113f3e 521# define sleep(a) taskDelay((a) * sysClkRateGet())
6a89a25c 522
0f113f3e
MC
523# include <vxWorks.h>
524# include <sockLib.h>
525# include <taskLib.h>
6a89a25c 526
0f113f3e 527# define getpid taskIdSelf
6a89a25c 528
0f113f3e
MC
529/*
530 * NOTE: these are implemented by helpers in database app! if the database is
531 * not linked, we need to implement them elswhere
532 */
6a89a25c
RL
533struct hostent *gethostbyname(const char *name);
534struct hostent *gethostbyaddr(const char *addr, int length, int type);
535struct servent *getservbyname(const char *name, const char *proto);
536
0f113f3e 537# endif
6a89a25c
RL
538/* end vxworks */
539
b6eb9827
DSH
540#define OSSL_NELEM(x) (sizeof(x)/sizeof(x[0]))
541
43c56417
KR
542#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
543# define CRYPTO_memcmp memcmp
544#endif
545
d02b48c6
RE
546#ifdef __cplusplus
547}
548#endif
549
550#endif