BRL-CAD
bio.h
Go to the documentation of this file.
1 /* B I O . H
2  * BRL-CAD
3  *
4  * Copyright (c) 2008-2024 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 /* strict mode may not declare fileno() */
44 # if !defined(fileno) && !defined(__cplusplus)
45 extern int fileno(FILE *stream);
46 # endif
47 
48 #if defined(_WIN32) && !defined(__CYGWIN__)
49 
50 # ifdef WIN32_LEAN_AND_MEAN
51 # undef WIN32_LEAN_AND_MEAN
52 # endif
53 # define WIN32_LEAN_AND_MEAN 434144 /* don't want winsock.h */
54 
55 # ifdef NOMINMAX
56 # undef NOMINMAX
57 # endif
58 # define NOMINMAX 434144 /* don't break std::min and std::max */
59 
60 # include <windows.h>
61 
62 # undef WIN32_LEAN_AND_MEAN /* unset to not interfere with calling apps */
63 # undef NOMINMAX
64 # include <io.h>
65 
66 # undef rad1 /* Win32 radio button 1 */
67 # undef rad2 /* Win32 radio button 2 */
68 # undef small /* defined as part of the Microsoft Interface Definition Language (MIDL) */
69 
70 #else
71 
72 # include <unistd.h>
73 
74 /* provide a stub so we don't need to wrap all setmode() calls */
75 static inline int setmode(int UNUSED(a), int UNUSED(b)) {return 42;}
76 static int (* volatile setmode_func)(int, int) = setmode; /* quell use */
77 #endif
78 
79 /* needed for testing O_TEMPORARY and O_BINARY */
80 #include <fcntl.h>
81 
82 /* _O_TEMPORARY on Windows removes file when last descriptor is closed */
83 #ifndef O_TEMPORARY
84 # define O_TEMPORARY 0
85 #endif
86 
87 /* _O_BINARY on Windows indicates whether to use binary or text (default) I/O */
88 #ifndef O_BINARY
89 # define O_BINARY 0
90 #endif
91 
92 /* the S_IS* macros should replace the S_IF*'s
93  already defined in C99 compliant compilers
94  this is the work-around for older compilers */
95 #ifndef S_ISBLK
96 # ifdef S_IFBLK
97 # define S_ISBLK(mode) (((mode) & S_IFMT) == S_IFBLK)
98 # else
99 # define S_ISBLK(mode) (0)
100 # endif
101 #endif
102 #ifndef S_ISCHR
103 # ifdef S_IFCHR
104 # define S_ISCHR(mode) (((mode) & S_IFMT) == S_IFCHR)
105 # else
106 # define S_ISCHR(mode) (0)
107 # endif
108 #endif
109 #ifndef S_ISDIR
110 # ifdef S_IFDIR
111 # define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
112 # else
113 # define S_ISDIR(mode) (0)
114 # endif
115 #endif
116 #ifndef S_ISFIFO
117 # ifdef S_IFIFO
118 # define S_ISFIFO(mode) (((mode) & S_IFMT) == S_IFIFO)
119 # else
120 # define S_ISFIFO(mode) (0)
121 # endif
122 #endif
123 #ifndef S_ISLNK
124 # ifdef S_IFLNK
125 # define S_ISLNK(mode) (((mode) & S_IFMT) == S_IFLNK)
126 # else
127 # define S_ISLNK(mode) (0)
128 # endif
129 #endif
130 #ifndef S_ISREG
131 # ifdef S_IFREG
132 # define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG)
133 # else
134 # define S_ISREG(mode) (0)
135 # endif
136 #endif
137 #ifndef S_ISSOCK
138 # ifdef S_IFSOCK
139 # define S_ISSOCK(mode) (((mode) & S_IFMT) == S_IFSOCK)
140 # else
141 # define S_ISSOCK(mode) (0)
142 # endif
143 #endif
144 
145 #endif /* BIO_H */
146 
147 /** @} */
148 
149 /*
150  * Local Variables:
151  * tab-width: 8
152  * mode: C
153  * indent-tabs-mode: t
154  * c-file-style: "stroustrup"
155  * End:
156  * ex: shiftwidth=4 tabstop=8
157  */
#define UNUSED(parameter)
Definition: common.h:335