BRL-CAD
bio.h
Go to the documentation of this file.
1/* B I O . H
2 * BRL-CAD
3 *
4 * Copyright (c) 2008-2022 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)
45extern 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# define setmode(a, b) /* poof */
76#endif
77
78/* needed for testing O_TEMPORARY and O_BINARY */
79#include <fcntl.h>
80
81/* _O_TEMPORARY on Windows removes file when last descriptor is closed */
82#ifndef O_TEMPORARY
83# define O_TEMPORARY 0
84#endif
85
86/* _O_BINARY on Windows indicates whether to use binary or text (default) I/O */
87#ifndef O_BINARY
88# define O_BINARY 0
89#endif
90
91/* the S_IS* macros should replace the S_IF*'s
92 already defined in C99 compliant compilers
93 this is the work-around for older compilers */
94#ifndef S_ISBLK
95# ifdef S_IFBLK
96# define S_ISBLK(mode) (((mode) & S_IFMT) == S_IFBLK)
97# else
98# define S_ISBLK(mode) (0)
99# endif
100#endif
101#ifndef S_ISCHR
102# ifdef S_IFCHR
103# define S_ISCHR(mode) (((mode) & S_IFMT) == S_IFCHR)
104# else
105# define S_ISCHR(mode) (0)
106# endif
107#endif
108#ifndef S_ISDIR
109# ifdef S_IFDIR
110# define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
111# else
112# define S_ISDIR(mode) (0)
113# endif
114#endif
115#ifndef S_ISFIFO
116# ifdef S_IFIFO
117# define S_ISFIFO(mode) (((mode) & S_IFMT) == S_IFIFO)
118# else
119# define S_ISFIFO(mode) (0)
120# endif
121#endif
122#ifndef S_ISLNK
123# ifdef S_IFLNK
124# define S_ISLNK(mode) (((mode) & S_IFMT) == S_IFLNK)
125# else
126# define S_ISLNK(mode) (0)
127# endif
128#endif
129#ifndef S_ISREG
130# ifdef S_IFREG
131# define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG)
132# else
133# define S_ISREG(mode) (0)
134# endif
135#endif
136#ifndef S_ISSOCK
137# ifdef S_IFSOCK
138# define S_ISSOCK(mode) (((mode) & S_IFMT) == S_IFSOCK)
139# else
140# define S_ISSOCK(mode) (0)
141# endif
142#endif
143
144#endif /* BIO_H */
145
146/** @} */
147
148/*
149 * Local Variables:
150 * tab-width: 8
151 * mode: C
152 * indent-tabs-mode: t
153 * c-file-style: "stroustrup"
154 * End:
155 * ex: shiftwidth=4 tabstop=8
156 */