BDE 4.14.0 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 timstamp 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 timstamp 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-complation
88/// environment, see the component documentation of
89/// {`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 critera, 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,
142/// Solaris, and SunOS if the `_LARGEFILE64_SOURCE` macro is defined.
143/// Neither Cygwin, Darwin, nor FreeBSD support this environment, because
144/// they natively support large (64-bit) file operations in all compilation
145/// modes.
146///
147/// `Off Type`:
148/// Short for "Offset Type". This column lists the type that a program
149/// should use to represent file offsets on Unix platforms. The offset type
150/// should be `off_t` (64-bit) if the program natively supports large
151/// (64-bit) file operations, `off64_t` if the program does not natively
152/// support these operations, but provides the transitional-compilation
153/// environment, and `off_t` (32-bit) if the program neither natively support
154/// large (64-bit) file operations nor provides the transitional-compilation
155/// environment. Note that a 32-bit `off_t` is used as a "last resort" when
156/// no 64-bit offset type is available on the platform. A program may be
157/// unable to operate on files larger than approximately 2 Gigabytes if a
158/// 32-bit `off_t` is used.
159///
160/// `Off Bits`:
161/// This column lists the number of bits used in the offset type to represent
162/// a byte quantity. A value of `64` indicates that the offset type has 64
163/// bits, and a value of `32` indicates that the offset type has 32 bits.
164///
165/// `Macro Defined`:
166/// This column lists which macro provided by this component is defined, in
167/// order to indicate the offset type and set of file-system functions that a
168/// program should use on Unix. A value of `*_32_BIT_OFF` indicates that the
169/// `BDLS_FILESYSTEMUTIL_UNIXPLATFORM_32_BIT_OFF` macro is defined, and that
170/// a program should use the `off_t` offset type and associated file-system
171/// functions, a value of "*<u>64</u>BIT_OFF" indicates that the
172/// `BDLS_FILESYSTEMUTIL_UNIXPLATFORM_64_BIT_OFF` macro is defined, and that
173/// a program should use the `off_t` offset type and associated file-system
174/// tunctions, and a value of `*_64_BIT_OFF64` indicates that the
175/// `BDLS_FILESYSTEMUTIL_UNIXPLATFORM_64_BIT_OFF64` macro is defined, and
176/// that a program should use the `off64_t` offset type, and associated
177/// file-system functions from the transitional-compilation environment.
178///
179/// The table follows. Note that a value of `N/A` in any cell of the table
180/// indicates that the value of that cell does affect the determination of the
181/// value of the associated `Off Type`, `Off-Type Bits` and `Macro Defined`
182/// cells.
183///
184/// @code
185/// |---------|------|--------|-----|----------|----------|---------------|
186/// | OS | Mode | FOB=64 | LF | Off Type | Off Bits | Macro Defined |
187/// |=========+======+========+=====+==========+==========+===============|
188/// | AIX | 32 | N/A | No | 'off64_t'| 64 | *_64_BIT_OFF64|
189/// | AIX | 32 | N/A | Yes | 'off_t' | 64 | *_64_BIT_OFF |
190/// | AIX | 64 | N/A | N/A | 'off_t' | 64 | *_64_BIT_OFF |
191/// | Cygiwn | N/A | N/A | N/A | 'off_t' | 64 | *_64_BIT_OFF |
192/// | Darwin | N/A | N/A | N/A | 'off_t' | 64 | *_64_BIT_OFF |
193/// | FreeBSD | N/A | N/A | N/A | 'off_t' | 64 | *_64_BIT_OFF |
194/// | Linux | 32 | No | No | 'off_t' | 32 | *_32_BIT_OFF |
195/// | Linux | 32 | No | Yes | 'off64_t'| 64 | *_64_BIT_OFF64|
196/// | Linux | 32 | Yes | N/A | 'off_t' | 64 | *_64_BIT_OFF |
197/// | Linux | 64 | N/A | N/A | 'off_t' | 64 | *_64_BIT_OFF |
198/// | SunOS | 32 | No | No | 'off_t' | 32 | *_32_BIT_OFF |
199/// | SunOS | 32 | No | Yes | 'off64_t'| 64 | *_64_BIT_OFF64|
200/// | SunOS | 32 | Yes | N/A | 'off_t' | 64 | *_64_BIT_OFF |
201/// | SunOS | 64 | N/A | N/A | 'off_t' | 64 | *_64_BIT_OFF |
202/// | Solaris | 32 | No | No | 'off_t' | 32 | *_32_BIT_OFF |
203/// | Solaris | 32 | No | Yes | 'off64_t'| 64 | *_64_BIT_OFF64|
204/// | Solaris | 32 | Yes | N/A | 'off_t' | 64 | *_64_BIT_OFF |
205/// | Solaris | 64 | N/A | N/A | 'off_t' | 64 | *_64_BIT_OFF |
206/// |---------+------+--------+-----+----------+----------+---------------+
207/// @endcode
208/// @}
209/** @} */
210/** @} */
211
212/** @addtogroup bdl
213 * @{
214 */
215/** @addtogroup bdls
216 * @{
217 */
218/** @addtogroup bdls_filesystemutil_unixplatform
219 * @{
220 */
221
222#include <bsls_platform.h>
223
224#if defined(BSLS_PLATFORM_OS_UNIX)
225
226#include <unistd.h>
227
228 // 32-Bit AIX with '_LARGE_FILE'
229
230 #if defined(BSLS_PLATFORM_OS_AIX) \
231 && defined(BSLS_PLATFORM_CPU_32_BIT) \
232 && defined(_LARGE_FILE)
233
234 #define BDLS_FILESYSTEMUTIL_UNIXPLATFORM_64_BIT_OFF 1
235
236 // 32-Bit AIX
237
238 #elif defined(BSLS_PLATFORM_OS_AIX) \
239 && defined(BSLS_PLATFORM_CPU_32_BIT)
240
241 #define BDLS_FILESYSTEMUTIL_UNIXPLATFORM_64_BIT_OFF64 1
242
243 // 64-Bit AIX
244
245 #elif defined(BSLS_PLATFORM_OS_AIX) \
246 && defined(BSLS_PLATFORM_CPU_64_BIT)
247
248 #define BDLS_FILESYSTEMUTIL_UNIXPLATFORM_64_BIT_OFF 1
249
250 // Cygwin
251
252 #elif defined(BSLS_PLATFORM_OS_CYGWIN)
253
254 #define BDLS_FILESYSTEMUTIL_UNIXPLATFORM_64_BIT_OFF 1
255
256 // Darwin
257
258 #elif defined(BSLS_PLATFORM_OS_DARWIN)
259
260 #define BDLS_FILESYSTEMUTIL_UNIXPLATFORM_64_BIT_OFF 1
261
262 // FreeBSD
263
264 #elif defined(BSLS_PLATFORM_OS_FREEBSD)
265
266 #define BDLS_FILESYSTEMUTIL_UNIXPLATFORM_64_BIT_OFF 1
267
268 // 32-Bit Linux with '_FILE_OFFSET_BITS = 64'
269
270 #elif defined(BSLS_PLATFORM_OS_LINUX) \
271 && defined(BSLS_PLATFORM_CPU_32_BIT) \
272 && defined(_FILE_OFFSET_BITS) \
273 && _FILE_OFFSET_BITS == 64
274
275 #define BDLS_FILESYSTEMUTIL_UNIXPLATFORM_64_BIT_OFF 1
276
277 // 32-Bit Linux with '_LARGEFILE64_SOURCE'
278
279 #elif defined(BSLS_PLATFORM_OS_LINUX) \
280 && defined(BSLS_PLATFORM_CPU_32_BIT) \
281 && defined(_LARGEFILE64_SOURCE)
282
283 #define BDLS_FILESYSTEMUTIL_UNIXPLATFORM_64_BIT_OFF64 1
284
285 // 32-Bit Linux
286
287 #elif defined(BSLS_PLATFORM_OS_LINUX) \
288 && defined(BSLS_PLATFORM_CPU_32_BIT)
289
290 #define BDLS_FILESYSTEMUTIL_UNIXPLATFORM_32_BIT_OFF 1
291
292 // 64-Bit Linux
293
294 #elif defined(BSLS_PLATFORM_OS_LINUX) \
295 && defined(BSLS_PLATFORM_CPU_64_BIT)
296
297 #define BDLS_FILESYSTEMUTIL_UNIXPLATFORM_64_BIT_OFF 1
298
299 // 32-Bit SunOS with '_FILE_OFFSET_BITS = 64'
300
301 #elif defined(BSLS_PLATFORM_OS_SUNOS) \
302 && defined(BSLS_PLATFORM_CPU_32_BIT) \
303 && defined(_FILE_OFFSET_BITS) \
304 && _FILE_OFFSET_BITS == 64
305
306 #define BDLS_FILESYSTEMUTIL_UNIXPLATFORM_64_BIT_OFF 1
307
308 // 32-Bit SunOS with '_LARGEFILE64_SOURCE'
309
310 #elif defined(BSLS_PLATFORM_OS_SUNOS) \
311 && defined(BSLS_PLATFORM_CPU_32_BIT) \
312 && defined(_LARGEFILE64_SOURCE)
313
314 #define BDLS_FILESYSTEMUTIL_UNIXPLATFORM_64_BIT_OFF64 1
315
316 // 32-Bit SunOS
317
318 #elif defined(BSLS_PLATFORM_OS_SUNOS) \
319 && defined(BSLS_PLATFORM_CPU_32_BIT)
320
321 #define BDLS_FILESYSTEMUTIL_UNIXPLATFORM_32_BIT_OFF 1
322
323 // 64-Bit SunOS
324
325 #elif defined(BSLS_PLATFORM_OS_SUNOS) \
326 && defined(BSLS_PLATFORM_CPU_64_BIT)
327
328 #define BDLS_FILESYSTEMUTIL_UNIXPLATFORM_64_BIT_OFF 1
329
330 // 32-Bit Solaris with '_FILE_OFFSET_BITS = 64'
331
332 #elif defined(BSLS_PLATFORM_OS_SOLARIS) \
333 && defined(BSLS_PLATFORM_CPU_32_BIT) \
334 && defined(_FILE_OFFSET_BITS) \
335 && _FILE_OFFSET_BITS == 64
336
337 #define BDLS_FILESYSTEMUTIL_UNIXPLATFORM_64_BIT_OFF 1
338
339 // 32-Bit Solaris with '_LARGEFILE64_SOURCE'
340
341 #elif defined(BSLS_PLATFORM_OS_SOLARIS) \
342 && defined(BSLS_PLATFORM_CPU_32_BIT) \
343 && defined(_LARGEFILE64_SOURCE)
344
345 #define BDLS_FILESYSTEMUTIL_UNIXPLATFORM_64_BIT_OFF64 1
346
347 // 32-Bit Solaris
348
349 #elif defined(BSLS_PLATFORM_OS_SOLARIS) \
350 && defined(BSLS_PLATFORM_CPU_32_BIT)
351
352 #define BDLS_FILESYSTEMUTIL_UNIXPLATFORM_32_BIT_OFF 1
353
354 // 64-Bit Solaris
355
356 #elif defined(BSLS_PLATFORM_OS_SOLARIS) \
357 && defined(BSLS_PLATFORM_CPU_64_BIT)
358
359 #define BDLS_FILESYSTEMUTIL_UNIXPLATFORM_64_BIT_OFF 1
360
361 #else
362 #error "'bdls_filesystemutil_unixplatform.h' does not support this Unix."
363 #endif
364
365#if defined(BSLS_PLATFORM_OS_SOLARIS) || \
366 defined(BSLS_PLATFORM_OS_AIX) || \
367 defined(BSLS_PLATFORM_OS_LINUX)
368
369 #define BDLS_FILESYSTEMUTIL_UNIXPLATFORM_STAT_NS_MEMBER st_mtim.tv_nsec
370
371#elif defined(BSLS_PLATFORM_OS_DARWIN)
372
373 #define BDLS_FILESYSTEMUTIL_UNIXPLATFORM_STAT_NS_MEMBER st_mtimespec.tv_nsec
374
375#endif
376
377#endif
378#endif
379
380// ----------------------------------------------------------------------------
381// Copyright 2020 Bloomberg Finance L.P.
382//
383// Licensed under the Apache License, Version 2.0 (the "License");
384// you may not use this file except in compliance with the License.
385// You may obtain a copy of the License at
386//
387// http://www.apache.org/licenses/LICENSE-2.0
388//
389// Unless required by applicable law or agreed to in writing, software
390// distributed under the License is distributed on an "AS IS" BASIS,
391// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
392// See the License for the specific language governing permissions and
393// limitations under the License.
394// ----------------------------- END-OF-FILE ----------------------------------
395
396/** @} */
397/** @} */
398/** @} */
#define BSLS_IDENT(str)
Definition bsls_ident.h:195