BDE 4.39.x Production Release
Loading...
Searching...
No Matches
bdls_filesystemutil_unixplatform.h
Go to the documentation of this file.
1/// @file bdls_filesystemutil_unixplatform.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bdls_filesystemutil_unixplatform.h -*-C++-*-
8#ifndef INCLUDED_BDLS_FILESYSTEMUTIL_UNIXPLATFORM
9#define INCLUDED_BDLS_FILESYSTEMUTIL_UNIXPLATFORM
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup bdls_filesystemutil_unixplatform bdls_filesystemutil_unixplatform
15/// @brief Provide Unix timestamp and offset type width detection macros.
16/// @addtogroup bdl
17/// @{
18/// @addtogroup bdls
19/// @{
20/// @addtogroup bdls_filesystemutil_unixplatform
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bdls_filesystemutil_unixplatform-purpose"> Purpose</a>
25/// * <a href="#bdls_filesystemutil_unixplatform-macros"> Macros </a>
26/// * <a href="#bdls_filesystemutil_unixplatform-description"> Description </a>
27/// * <a href="#bdls_filesystemutil_unixplatform-nanosecond-support-macros"> Nanosecond Support Macros </a>
28/// * <a href="#bdls_filesystemutil_unixplatform-byte-quantity-macros"> Byte Quantity Macros </a>
29/// * <a href="#bdls_filesystemutil_unixplatform-byte-quantity-macro-selection"> Byte Quantity Macro Selection </a>
30///
31/// # Purpose {#bdls_filesystemutil_unixplatform-purpose}
32/// Provide Unix timestamp and offset type width detection macros.
33///
34/// # Macros {#bdls_filesystemutil_unixplatform-macros}
35///
36/// - BDLS_FILESYSTEMUTIL_UNIXPLATFORM_64_BIT_OFF: 1 if `off_t` is 64 bits, else
37/// - BDLS_FILESYSTEMUTIL_UNIXPLATFORM_64_BIT_OFF64: 1 if `off64_t` exists, else
38/// - BDLS_FILESYSTEMUTIL_UNIXPLATFORM_32_BIT_OFF: 1 (`off_t` is 32 bits)
39///
40/// BDLS_FILESYSTEMUTIL_UNIXPLATFORM_STAT_NS_MEMBER: The `stat` nanosecond
41/// member name
42///
43/// @see bdls_filesystemutil, bdls_filesystemutil_unixplatform,
44/// bdls_filesystemutil_transitionalunixplatform
45///
46/// # Description {#bdls_filesystemutil_unixplatform-description}
47/// This subordinate component to @ref bdls_filesystemutil provides:
48///
49/// a) a set of macros for detecting the most appropriate type to use for byte
50/// quantities, and most appropriate set of functions to use for file
51/// operations, on Unix platforms, and
52///
53/// b) a macro which specifies the name of the member variable, within a `stat`
54/// structure, that holds the nanosecond part of the file timestamp.
55///
56/// ## Nanosecond Support Macros {#bdls_filesystemutil_unixplatform-nanosecond-support-macros}
57///
58///
59/// This component defines the following Macros if the `stat` structure defined
60/// in `sys/stat.h` contains the `st_mtim.tv_nsec` member. This is determined
61/// by the feature tests specified in POSIX.1-2008 - see
62/// https://linux.die.net/man/2/fstat.
63///
64/// `BDLS_FILESYSTEMUTIL_UNIXPLATFORM_STAT_NS_MEMBER`: This macro is defined to
65/// be the name of the member of the `stat` structure that contains the
66/// nanosecond part of the timestamp value.
67///
68/// ## Byte Quantity Macros {#bdls_filesystemutil_unixplatform-byte-quantity-macros}
69///
70///
71/// This component defines exactly 1 of 3 macros depending on the current
72/// platform configuration, which are used to determine which offset type and
73/// associated set of file-system functions a program should use on Unix. These
74/// macros are:
75///
76/// `BDLS_FILESYSTEMUTIL_UNIXPLATFORM_64_BIT_OFF`: The presence of this macro
77/// definition indicates that the platform natively supports large (64-bit)
78/// file operations, and that the `off_t` type provided by the `sys/types.h`
79/// header is 64-bit.
80///
81/// `BDLS_FILESYSTEMUTIL_UNIXPLATFORM_64_BIT_OFF64`: The presence of this macro
82/// definition indicates that the platform *does* *not* natively support large
83/// (64-bit) file operations, but that it does support the
84/// "transitional-compilation environment" that provides non-standard large
85/// file types and operations. Specifically, this indicates that the platform
86/// supports a 64-bit `off64_t` type, and provides associated `xxx64` file
87/// operations. For more information about the transitional-compilation
88/// environment, see the component documentation of
89/// {@ref bdls_filesystemutil_transitionaluniximputil }.
90///
91/// `BDLS_FILESYSTEMUTIL_UNIXPLATFORM_32_BIT_OFF`: The presence of this macro
92/// definition indicates that the platform does not natively support large
93/// (64-bit) file operations, nor is it configured to provide the
94/// transitional-compilation environment. Specifically, this indicates that
95/// the platform provides a 32-bit `off_t` type and associated 32-bit file
96/// operations. If this macro is defined, a program may be unable to operate
97/// on files larger than approximately 2 Gigabytes.
98///
99/// ## Byte Quantity Macro Selection {#bdls_filesystemutil_unixplatform-byte-quantity-macro-selection}
100///
101///
102/// Which of the 3 macros this component defines depends upon the capabilities
103/// of the platform's configuration. There are 4 criteria used to determine
104/// which macro is defined, and they are
105///
106/// * the operating system,
107/// * whether the CPU is 32 or 64-bit,
108/// * whether a `_FILE_OFFSET_BITS` macro is defined to `64`, and
109/// * whether the transitional-compilation environment is enabled
110///
111/// The set of possible combinations of these criteria, and consequently which
112/// macros are defined, is specified in the table below. The legend for this
113/// table is the following:
114///
115/// `OS`:
116/// Short for "Operating System". This column lists the operating system
117/// associated with the platform.
118///
119/// `Mode`:
120/// Either `32` or `64`. This column lists the number of bits in a machine
121/// word associated with the platform. A program compiled for an x86
122/// processor would be `32`, and one compiled for an x86_64 processor would
123/// be `64`, for example.
124///
125/// `FOB=64`:
126/// Short for "File-Offset Bits == 64". This column lists whether or not the
127/// `_FILE_OFFSET_BITS` macro is defined to the value `64`, or is otherwise
128/// defined to another value or undefined. A value of `Yes` indicates
129/// `_FILE_OFFSET_BITS` is defined to `64`, and a value of `No` indicates
130/// that it is not. Note that this macro is not a part of any Unix standard,
131/// but nevertheless is supported by several Unixes. On most Unix platforms,
132/// defining `_FILE_OFFSET_BITS` to a value other than `64` has no meaning.
133///
134/// `LF`:
135/// Short for `Large File Source`. This column lists whether or not a macro
136/// is defined that indicates the current program is compiled in the
137/// "Transitional-Compilation Environment." A value of `Yes` indicates the
138/// transitional-compilation environment is enabled, and a value of `No`
139/// indicates that it is not. Different macros enable this environment on
140/// different Unixes, if they support it. This environment is enabled on AIX
141/// if the `_LARGE_FILE` macro is defined, and it is enabled on Linux and
142/// Solaris if the `_LARGEFILE64_SOURCE` macro is defined. : Neither
143/// Cygwin, Darwin, nor FreeBSD support this environment, because they
144/// natively support large (64-bit) file operations in all compilation modes.
145///
146/// `Off Type`:
147/// Short for "Offset Type". This column lists the type that a program
148/// should use to represent file offsets on Unix platforms. The offset type
149/// should be `off_t` (64-bit) if the program natively supports large
150/// (64-bit) file operations, `off64_t` if the program does not natively
151/// support these operations, but provides the transitional-compilation
152/// environment, and `off_t` (32-bit) if the program neither natively support
153/// large (64-bit) file operations nor provides the transitional-compilation
154/// environment. Note that a 32-bit `off_t` is used as a "last resort" when
155/// no 64-bit offset type is available on the platform. A program may be
156/// unable to operate on files larger than approximately 2 Gigabytes if a
157/// 32-bit `off_t` is used.
158///
159/// `Off Bits`:
160/// This column lists the number of bits used in the offset type to represent
161/// a byte quantity. A value of `64` indicates that the offset type has 64
162/// bits, and a value of `32` indicates that the offset type has 32 bits.
163///
164/// `Macro Defined`:
165/// This column lists which macro provided by this component is defined, in
166/// order to indicate the offset type and set of file-system functions that a
167/// program should use on Unix. A value of `*_32_BIT_OFF` indicates that the
168/// `BDLS_FILESYSTEMUTIL_UNIXPLATFORM_32_BIT_OFF` macro is defined, and that
169/// a program should use the `off_t` offset type and associated file-system
170/// functions, a value of "*<u>64</u>BIT_OFF" indicates that the
171/// `BDLS_FILESYSTEMUTIL_UNIXPLATFORM_64_BIT_OFF` macro is defined, and that
172/// a program should use the `off_t` offset type and associated file-system
173/// functions, and a value of `*_64_BIT_OFF64` indicates that the
174/// `BDLS_FILESYSTEMUTIL_UNIXPLATFORM_64_BIT_OFF64` macro is defined, and
175/// that a program should use the `off64_t` offset type, and associated
176/// file-system functions from the transitional-compilation environment.
177///
178/// The table follows. Note that a value of `N/A` in any cell of the table
179/// indicates that the value of that cell does affect the determination of the
180/// value of the associated `Off Type`, `Off-Type Bits` and `Macro Defined`
181/// cells.
182///
183/// @code
184/// |---------|------|--------|-----|----------|----------|---------------|
185/// | OS | Mode | FOB=64 | LF | Off Type | Off Bits | Macro Defined |
186/// |=========+======+========+=====+==========+==========+===============|
187/// | AIX | 32 | N/A | No | 'off64_t'| 64 | *_64_BIT_OFF64|
188/// | AIX | 32 | N/A | Yes | 'off_t' | 64 | *_64_BIT_OFF |
189/// | AIX | 64 | N/A | N/A | 'off_t' | 64 | *_64_BIT_OFF |
190/// | Cygiwn | N/A | N/A | N/A | 'off_t' | 64 | *_64_BIT_OFF |
191/// | Darwin | N/A | N/A | N/A | 'off_t' | 64 | *_64_BIT_OFF |
192/// | FreeBSD | N/A | N/A | N/A | 'off_t' | 64 | *_64_BIT_OFF |
193/// | Linux | 32 | No | No | 'off_t' | 32 | *_32_BIT_OFF |
194/// | Linux | 32 | No | Yes | 'off64_t'| 64 | *_64_BIT_OFF64|
195/// | Linux | 32 | Yes | N/A | 'off_t' | 64 | *_64_BIT_OFF |
196/// | Linux | 64 | N/A | N/A | 'off_t' | 64 | *_64_BIT_OFF |
197/// | Solaris | 32 | No | No | 'off_t' | 32 | *_32_BIT_OFF |
198/// | Solaris | 32 | No | Yes | 'off64_t'| 64 | *_64_BIT_OFF64|
199/// | Solaris | 32 | Yes | N/A | 'off_t' | 64 | *_64_BIT_OFF |
200/// | Solaris | 64 | N/A | N/A | 'off_t' | 64 | *_64_BIT_OFF |
201/// |---------+------+--------+-----+----------+----------+---------------+
202/// @endcode
203/// @}
204/** @} */
205/** @} */
206
207/** @addtogroup bdl
208 * @{
209 */
210/** @addtogroup bdls
211 * @{
212 */
213/** @addtogroup bdls_filesystemutil_unixplatform
214 * @{
215 */
216
217#include <bsls_platform.h>
218
219#if defined(BSLS_PLATFORM_OS_UNIX)
220
221#include <unistd.h>
222
223 // 32-Bit AIX with '_LARGE_FILE'
224
225 #if defined(BSLS_PLATFORM_OS_AIX) \
226 && defined(BSLS_PLATFORM_CPU_32_BIT) \
227 && defined(_LARGE_FILE)
228
229 #define BDLS_FILESYSTEMUTIL_UNIXPLATFORM_64_BIT_OFF 1
230
231 // 32-Bit AIX
232
233 #elif defined(BSLS_PLATFORM_OS_AIX) \
234 && defined(BSLS_PLATFORM_CPU_32_BIT)
235
236 #define BDLS_FILESYSTEMUTIL_UNIXPLATFORM_64_BIT_OFF64 1
237
238 // 64-Bit AIX
239
240 #elif defined(BSLS_PLATFORM_OS_AIX) \
241 && defined(BSLS_PLATFORM_CPU_64_BIT)
242
243 #define BDLS_FILESYSTEMUTIL_UNIXPLATFORM_64_BIT_OFF 1
244
245 // Cygwin
246
247 #elif defined(BSLS_PLATFORM_OS_CYGWIN)
248
249 #define BDLS_FILESYSTEMUTIL_UNIXPLATFORM_64_BIT_OFF 1
250
251 // Darwin
252
253 #elif defined(BSLS_PLATFORM_OS_DARWIN)
254
255 #define BDLS_FILESYSTEMUTIL_UNIXPLATFORM_64_BIT_OFF 1
256
257 // FreeBSD
258
259 #elif defined(BSLS_PLATFORM_OS_FREEBSD)
260
261 #define BDLS_FILESYSTEMUTIL_UNIXPLATFORM_64_BIT_OFF 1
262
263 // 32-Bit Linux with '_FILE_OFFSET_BITS = 64'
264
265 #elif defined(BSLS_PLATFORM_OS_LINUX) \
266 && defined(BSLS_PLATFORM_CPU_32_BIT) \
267 && defined(_FILE_OFFSET_BITS) \
268 && _FILE_OFFSET_BITS == 64
269
270 #define BDLS_FILESYSTEMUTIL_UNIXPLATFORM_64_BIT_OFF 1
271
272 // 32-Bit Linux with '_LARGEFILE64_SOURCE'
273
274 #elif defined(BSLS_PLATFORM_OS_LINUX) \
275 && defined(BSLS_PLATFORM_CPU_32_BIT) \
276 && defined(_LARGEFILE64_SOURCE)
277
278 #define BDLS_FILESYSTEMUTIL_UNIXPLATFORM_64_BIT_OFF64 1
279
280 // 32-Bit Linux
281
282 #elif defined(BSLS_PLATFORM_OS_LINUX) \
283 && defined(BSLS_PLATFORM_CPU_32_BIT)
284
285 #define BDLS_FILESYSTEMUTIL_UNIXPLATFORM_32_BIT_OFF 1
286
287 // 64-Bit Linux
288
289 #elif defined(BSLS_PLATFORM_OS_LINUX) \
290 && defined(BSLS_PLATFORM_CPU_64_BIT)
291
292 #define BDLS_FILESYSTEMUTIL_UNIXPLATFORM_64_BIT_OFF 1
293
294 // 32-Bit Solaris with '_FILE_OFFSET_BITS = 64'
295
296 #elif defined(BSLS_PLATFORM_OS_SOLARIS) \
297 && defined(BSLS_PLATFORM_CPU_32_BIT) \
298 && defined(_FILE_OFFSET_BITS) \
299 && _FILE_OFFSET_BITS == 64
300
301 #define BDLS_FILESYSTEMUTIL_UNIXPLATFORM_64_BIT_OFF 1
302
303 // 32-Bit Solaris with '_LARGEFILE64_SOURCE'
304
305 #elif defined(BSLS_PLATFORM_OS_SOLARIS) \
306 && defined(BSLS_PLATFORM_CPU_32_BIT) \
307 && defined(_LARGEFILE64_SOURCE)
308
309 #define BDLS_FILESYSTEMUTIL_UNIXPLATFORM_64_BIT_OFF64 1
310
311 // 32-Bit Solaris
312
313 #elif defined(BSLS_PLATFORM_OS_SOLARIS) \
314 && defined(BSLS_PLATFORM_CPU_32_BIT)
315
316 #define BDLS_FILESYSTEMUTIL_UNIXPLATFORM_32_BIT_OFF 1
317
318 // 64-Bit Solaris
319
320 #elif defined(BSLS_PLATFORM_OS_SOLARIS) \
321 && defined(BSLS_PLATFORM_CPU_64_BIT)
322
323 #define BDLS_FILESYSTEMUTIL_UNIXPLATFORM_64_BIT_OFF 1
324
325 #else
326 #error "'bdls_filesystemutil_unixplatform.h' does not support this Unix."
327 #endif
328
329#if defined(BSLS_PLATFORM_OS_SOLARIS) || \
330 defined(BSLS_PLATFORM_OS_AIX) || \
331 defined(BSLS_PLATFORM_OS_LINUX)
332
333 #define BDLS_FILESYSTEMUTIL_UNIXPLATFORM_STAT_NS_MEMBER st_mtim.tv_nsec
334
335#elif defined(BSLS_PLATFORM_OS_DARWIN)
336
337 #define BDLS_FILESYSTEMUTIL_UNIXPLATFORM_STAT_NS_MEMBER st_mtimespec.tv_nsec
338
339#endif
340
341#endif
342#endif
343
344// ----------------------------------------------------------------------------
345// Copyright 2020 Bloomberg Finance L.P.
346//
347// Licensed under the Apache License, Version 2.0 (the "License");
348// you may not use this file except in compliance with the License.
349// You may obtain a copy of the License at
350//
351// http://www.apache.org/licenses/LICENSE-2.0
352//
353// Unless required by applicable law or agreed to in writing, software
354// distributed under the License is distributed on an "AS IS" BASIS,
355// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
356// See the License for the specific language governing permissions and
357// limitations under the License.
358// ----------------------------- END-OF-FILE ----------------------------------
359
360/** @} */
361/** @} */
362/** @} */
#define BSLS_IDENT(str)
BSLS_IDENT() - insert string into .comment binary segment (if supported)
Definition bsls_ident.h:238