BRL-CAD
Loading...
Searching...
No Matches
bio.h
Go to the documentation of this file.
1/* B I O . H
2 * BRL-CAD
3 *
4 * Copyright (c) 2008-2026 United States Government as represented by
5 * the U.S. Army Research Laboratory.
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public License
9 * version 2.1 as published by the Free Software Foundation.
10 *
11 * This library is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this file; see the file named COPYING for more
18 * information.
19 */
20/** @addtogroup bu_bio
21 *
22 * @brief
23 * BRL-CAD system compatibility wrapper header that provides declarations for
24 * native and standard system INPUT/OUTPUT routines.
25 *
26 * This header is commonly used in lieu of including the following: stdio.h,
27 * io.h, fcntl, unistd.h, and windows.h
28 *
29 * The logic in this header should not rely on common.h's HAVE_* defines and
30 * should not be including the common.h header. This is intended to be a
31 * stand-alone portability header intended to be independent of build system,
32 * reusable by external projects.
33 */
34
35/** @{ */
36/** @file bio.h */
37
38#ifndef BIO_H
39#define BIO_H
40
41#include <stdio.h>
42
43#if defined(_WIN32) && !defined(__CYGWIN__) && !defined(__MSYS__)
44
45# ifdef WIN32_LEAN_AND_MEAN
46# undef WIN32_LEAN_AND_MEAN
47# endif
48# define WIN32_LEAN_AND_MEAN 434144 /* don't want winsock.h */
49
50# ifdef NOMINMAX
51# undef NOMINMAX
52# endif
53# define NOMINMAX 434144 /* don't break std::min and std::max */
54
55# include <windows.h>
56
57# undef WIN32_LEAN_AND_MEAN /* unset to not interfere with calling apps */
58# undef NOMINMAX
59# include <io.h>
60
61# undef rad1 /* Win32 radio button 1 */
62# undef rad2 /* Win32 radio button 2 */
63# undef small /* defined as part of the Microsoft Interface Definition Language (MIDL) */
64
65#else
66
67/* strict mode may not declare fileno(). Ensure a consistent C linkage
68 * declaration for both C and C++ consumers, but do not attempt to add
69 * any project-specific dll-export/import attributes here so this header
70 * remains a standalone portability shim. On Windows fileno() is always
71 * declared by <stdio.h> (with CRT dll-import linkage), so redeclaring it
72 * here would conflict - skip the declaration on that platform. */
73# if !defined(fileno)
74# ifdef __cplusplus
75extern "C" {
76# endif
77int fileno(FILE *stream);
78# ifdef __cplusplus
79}
80# endif
81# endif
82
83# include <unistd.h>
84
85/* provide a stub so we don't need to wrap all setmode() calls */
86static inline int setmode(int UNUSED(a), int UNUSED(b)) {return 42;}
87static int (* volatile setmode_func)(int, int) = setmode; /* quell use */
88#endif
89
90/* needed for testing O_TEMPORARY and O_BINARY */
91#include <fcntl.h>
92
93/* _O_TEMPORARY on Windows removes file when last descriptor is closed */
94#ifndef O_TEMPORARY
95# define O_TEMPORARY 0
96#endif
97
98/* _O_BINARY on Windows indicates whether to use binary or text (default) I/O.
99 * Map the POSIX O_BINARY name to the Windows-specific _O_BINARY constant so
100 * that code can use O_BINARY portably. On POSIX systems all I/O is binary by
101 * default, so define O_BINARY as 0 there (no flag needed). */
102#ifndef O_BINARY
103# ifdef _O_BINARY
104# define O_BINARY _O_BINARY
105# else
106# define O_BINARY 0
107# endif
108#endif
109
110#endif /* BIO_H */
111
112/** @} */
113
114/*
115 * Local Variables:
116 * tab-width: 8
117 * mode: C
118 * indent-tabs-mode: t
119 * c-file-style: "stroustrup"
120 * End:
121 * ex: shiftwidth=4 tabstop=8
122 */
int fileno(FILE *stream)
#define UNUSED(parameter)
Definition common.h:367