1/**
2 * @copyright
3 * ====================================================================
4 *    Licensed to the Apache Software Foundation (ASF) under one
5 *    or more contributor license agreements.  See the NOTICE file
6 *    distributed with this work for additional information
7 *    regarding copyright ownership.  The ASF licenses this file
8 *    to you under the Apache License, Version 2.0 (the
9 *    "License"); you may not use this file except in compliance
10 *    with the License.  You may obtain a copy of the License at
11 *
12 *      http://www.apache.org/licenses/LICENSE-2.0
13 *
14 *    Unless required by applicable law or agreed to in writing,
15 *    software distributed under the License is distributed on an
16 *    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 *    KIND, either express or implied.  See the License for the
18 *    specific language governing permissions and limitations
19 *    under the License.
20 * ====================================================================
21 * @endcopyright
22 *
23 * @file svn_dep_compat.h
24 * @brief Compatibility macros and functions.
25 * @since New in 1.5.0.
26 */
27
28#ifndef SVN_DEP_COMPAT_H
29#define SVN_DEP_COMPAT_H
30
31#include <apr_version.h>
32#include <apr_errno.h>
33
34#ifdef __cplusplus
35extern "C" {
36#endif /* __cplusplus */
37
38/**
39 * We assume that 'int' and 'unsigned' are at least 32 bits wide.
40 * This also implies that long (rev numbers) is 32 bits or wider.
41 *
42 * @since New in 1.9.
43 */
44#if    defined(APR_HAVE_LIMITS_H) \
45    && !defined(SVN_ALLOW_SHORT_INTS) \
46    && (INT_MAX < 0x7FFFFFFFl)
47#error int is shorter than 32 bits and may break Subversion. Define SVN_ALLOW_SHORT_INTS to skip this check.
48#endif
49
50/**
51 * We assume that 'char' is 8 bits wide.  The critical interfaces are
52 * our repository formats and RA encodings.  E.g. a 32 bit wide char may
53 * mess up UTF8 parsing, how we interpret size values etc.
54 *
55 * @since New in 1.9.
56 */
57#if    defined(CHAR_BIT) \
58    && !defined(SVN_ALLOW_NON_8_BIT_CHARS) \
59    && (CHAR_BIT != 8)
60#error char is not 8 bits and may break Subversion. Define SVN_ALLOW_NON_8_BIT_CHARS to skip this check.
61#endif
62
63/**
64 * Work around a platform dependency issue. apr_thread_rwlock_trywrlock()
65 * will make APR_STATUS_IS_EBUSY() return TRUE if the lock could not be
66 * acquired under Unix. Under Windows, this will not work. So, provide
67 * a more portable substitute.
68 *
69 * @since New in 1.8.
70 */
71#ifdef WIN32
72#define SVN_LOCK_IS_BUSY(x) \
73    (APR_STATUS_IS_EBUSY(x) || (x) == APR_FROM_OS_ERROR(WAIT_TIMEOUT))
74#else
75#define SVN_LOCK_IS_BUSY(x) APR_STATUS_IS_EBUSY(x)
76#endif
77
78/**
79 * Indicate whether we are running on a POSIX platform.  This has
80 * implications on the way e.g. fsync() works.
81 *
82 * For details on this check, see
83 * http://nadeausoftware.com/articles/2012/01/c_c_tip_how_use_compiler_predefined_macros_detect_operating_system#POSIX
84 *
85 * @since New in 1.10.
86 */
87#ifndef SVN_ON_POSIX
88#if    !defined(_WIN32) \
89    && (   defined(__unix__) \
90        || defined(__unix) \
91        || (defined(__APPLE__) && defined(__MACH__)))  /* UNIX-style OS? */
92#  include <unistd.h>
93#  if defined(_POSIX_VERSION)
94#    define SVN_ON_POSIX
95#  endif
96#endif
97#endif
98
99/**
100 * APR keeps a few interesting defines hidden away in its private
101 * headers apr_arch_file_io.h, so we redefined them here.
102 *
103 * @since New in 1.9
104 */
105#ifndef APR_FREADONLY
106#define APR_FREADONLY 0x10000000
107#endif
108#ifndef APR_OPENINFO
109#define APR_OPENINFO  0x00100000
110#endif
111
112/**
113 * APR 1 has volatile qualifier bugs in some atomic prototypes that
114 * are fixed in APR 2:
115 *   https://issues.apache.org/bugzilla/show_bug.cgi?id=50731
116 * Subversion code should put the volatile qualifier in the correct
117 * place when declaring variables which means that casting at the call
118 * site is necessary when using APR 1.  No casts should be used with
119 * APR 2 as this allows the compiler to check that the variable has
120 * the correct volatile qualifier.
121 */
122#if APR_VERSION_AT_LEAST(2,0,0)
123#define svn_atomic_casptr(mem, with, cmp) \
124  apr_atomic_casptr((mem), (with), (cmp))
125#define svn_atomic_xchgptr(mem, val) \
126  apr_atomic_xchgptr((mem), (val))
127#else
128#define svn_atomic_casptr(mem, with, cmp) \
129  apr_atomic_casptr((void volatile **)(mem), (with), (cmp))
130#define svn_atomic_xchgptr(mem, val) \
131  apr_atomic_xchgptr((void volatile **)(mem), (val))
132#endif
133
134/**
135 * Check at compile time if the Serf version is at least a certain
136 * level.
137 * @param major The major version component of the version checked
138 * for (e.g., the "1" of "1.3.0").
139 * @param minor The minor version component of the version checked
140 * for (e.g., the "3" of "1.3.0").
141 * @param patch The patch level component of the version checked
142 * for (e.g., the "0" of "1.3.0").
143 *
144 * @since New in 1.5.
145 */
146#ifndef SERF_VERSION_AT_LEAST /* Introduced in Serf 0.1.1 */
147#define SERF_VERSION_AT_LEAST(major,minor,patch)                       \
148(((major) < SERF_MAJOR_VERSION)                                        \
149 || ((major) == SERF_MAJOR_VERSION && (minor) < SERF_MINOR_VERSION)    \
150 || ((major) == SERF_MAJOR_VERSION && (minor) == SERF_MINOR_VERSION && \
151     (patch) <= SERF_PATCH_VERSION))
152#endif /* SERF_VERSION_AT_LEAST */
153
154/**
155 * By default, if libsvn is built against one version of SQLite
156 * and then run using an older version, svn will error out:
157 *
158 *     svn: Couldn't perform atomic initialization
159 *     svn: SQLite compiled for 3.7.4, but running with 3.7.3
160 *
161 * That can be annoying when building on a modern system in order
162 * to deploy on a less modern one.  So these constants allow one
163 * to specify how old the system being deployed on might be.
164 * For example,
165 *
166 *     EXTRA_CFLAGS += -DSVN_SQLITE_MIN_VERSION_NUMBER=3007003
167 *     EXTRA_CFLAGS += '-DSVN_SQLITE_MIN_VERSION="3.7.3"'
168 *
169 * turns on code that works around infelicities in older versions
170 * as far back as 3.7.3 and relaxes the check at initialization time
171 * to permit them.
172 *
173 * @since New in 1.8.
174 */
175#ifndef SVN_SQLITE_MIN_VERSION_NUMBER
176#define SVN_SQLITE_MIN_VERSION_NUMBER SQLITE_VERSION_NUMBER
177#define SVN_SQLITE_MIN_VERSION SQLITE_VERSION
178#endif /* SVN_SQLITE_MIN_VERSION_NUMBER */
179
180/**
181 * Check at compile time if the SQLite version is at least a certain
182 * level.
183 * @param major The major version component of the version checked
184 * for (e.g., the "1" of "1.3.0").
185 * @param minor The minor version component of the version checked
186 * for (e.g., the "3" of "1.3.0").
187 * @param patch The patch level component of the version checked
188 * for (e.g., the "0" of "1.3.0").
189 *
190 * @since New in 1.6.
191 */
192#ifndef SQLITE_VERSION_AT_LEAST
193#define SQLITE_VERSION_AT_LEAST(major,minor,patch)                     \
194((major*1000000 + minor*1000 + patch) <= SVN_SQLITE_MIN_VERSION_NUMBER)
195#endif /* SQLITE_VERSION_AT_LEAST */
196
197/**
198 * Support for 'apr_escape_shell() which was introduced in APR 1.5.
199 */
200#if !APR_VERSION_AT_LEAST(1,5,0)
201/* from apr_escape.h */
202#define APR_ESCAPE_STRING      (-1)
203APR_DECLARE(apr_status_t) apr_escape_shell(char *escaped, const char *str,
204        apr_ssize_t slen, apr_size_t *len);
205#endif
206
207#ifdef __cplusplus
208}
209#endif /* __cplusplus */
210
211#endif /* SVN_DEP_COMPAT_H */
212