globus_connect_gridftp_server  16.17
openbsd_compat.h
1 /*
2  * Copyright The University of Chicago
3  *
4  * All Rights Reserved.
5  */
6 
7 #ifndef OPENBSD_COMPAT_H
8 #define OPENBSD_COMPAT_H
9 
10 
11 /* Everything defined here is something OpenBSD's libc supplies for free
12  and glibc, Apple libc or mingw-w64 may not. Nothing in here is specific
13  to MD5; it is the OpenBSD-source-in-a-foreign-tree shim. */
14 
15 #include "globus_i_gridftp_server_config.h"
16 
17 /* mingw-w64's <sys/types.h> takes the _SIGSET_T_ guard for itself but only
18  declares sigset_t when _POSIX is set, and globus_config.h does not set it
19  until later. Since the -include puts us ahead of everything, set it first
20  or globus_common_include.h's own <sys/types.h> becomes a no-op and
21  globus_thread.h has no sigset_t. */
22 #ifdef __MINGW32__
23 #ifndef _POSIX
24 #define _POSIX 1
25 #endif
26 #endif
27 
28 /* First, so that the tests below see whatever the platform does define. md5.c
29  includes <sys/types.h> itself; it is repeated here because that is where
30  <sys/cdefs.h> gets pulled in on the platforms that have one. */
31 #include <sys/types.h>
32 #include <stddef.h>
33 #include <stdint.h>
34 #include <string.h>
35 
36 /* DEF_WEAK() declares a weak alias for a libc-internal symbol in OpenBSD's
37  build. It has no meaning outside it. */
38 #ifndef DEF_WEAK
39 #define DEF_WEAK(x)
40 #endif
41 
42 /* md5.h wraps its declarations in these. They come from <sys/cdefs.h> on glibc
43  and Apple libc; mingw-w64 has no such definitions. */
44 #ifndef __BEGIN_DECLS
45 #define __BEGIN_DECLS
46 #endif
47 #ifndef __END_DECLS
48 #define __END_DECLS
49 #endif
50 
51 /* md5.h and md5.c spell their integer types the 4.4BSD way. glibc and Apple
52  libc provide them from <sys/types.h>, mingw-w64 does not. HAVE_U_INT8_T and
53  friends come from AC_CHECK_TYPES in configure.ac. */
54 #ifndef HAVE_U_INT8_T
55 typedef uint8_t u_int8_t;
56 #endif
57 #ifndef HAVE_U_INT32_T
58 typedef uint32_t u_int32_t;
59 #endif
60 #ifndef HAVE_U_INT64_T
61 typedef uint64_t u_int64_t;
62 #endif
63 
64 /* MD5Final() clears the context with explicit_bzero(). glibc has had it since
65  2.25; Apple libc and mingw-w64 have nothing by that name. Writing through a
66  volatile pointer is what keeps the stores from being optimized away, which
67  is the entire reason upstream does not just call memset().
68  HAVE_EXPLICIT_BZERO comes from AC_CHECK_FUNCS in configure.ac. */
69 #ifndef HAVE_EXPLICIT_BZERO
70 static inline void
71 explicit_bzero(void *buf, size_t len)
72 {
73  volatile unsigned char *p = (volatile unsigned char *) buf;
74 
75  while (len-- > 0)
76  {
77  *p++ = 0;
78  }
79 }
80 #endif
81 
82 #endif /* OPENBSD_COMPAT_H */