Skip to content

Commit c15df7e

Browse files
committed
Detect sys/mman.h and make it optional
1 parent 6ceea8b commit c15df7e

File tree

4 files changed

+21
-10
lines changed

4 files changed

+21
-10
lines changed

config.h.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,9 @@
154154
// Define to 1 if you have the <sys/types.h> header file.
155155
#undef HAVE_SYS_TYPES_H
156156

157+
// Define to 1 if you have the <sys/mman.h> header file.
158+
#undef HAVE_SYS_MMAN_H
159+
157160
// Define to 1 if you have the <time.h> header file.
158161
#undef HAVE_TIME_H
159162

configure

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ seds=[s/#define \(WITHOUT_LIBSTDCPP\) 1/#undef \1/;s/\(NOLIBSTDCPP\)/#\1/]
5656
# Header files
5757
HEADERS="assert.h ctype.h errno.h fcntl.h float.h inttypes.h limits.h stdio.h
5858
locale.h alloca.h signal.h stdarg.h stddef.h sys/stat.h sys/types.h stdint.h
59-
stdlib.h string.h time.h unistd.h math.h stdlib.h";
59+
stdlib.h string.h time.h unistd.h math.h stdlib.h sys/mman.h";
6060

6161
# Libraries
6262
LIBS="supc++ gcc_eh SystemStubs"

fstream.cc

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010
#include <unistd.h>
1111
#include <errno.h>
1212
#include <sys/stat.h>
13-
#include <sys/mman.h>
1413
#include <sys/ioctl.h>
14+
#if HAVE_SYS_MMAN_H
15+
#include <sys/mman.h>
16+
#endif
1517

1618
namespace ustl {
1719

@@ -224,6 +226,16 @@ int fstream::fcntl (const char* rname, int request, long argument)
224226
return (rv);
225227
}
226228

229+
void fstream::set_nonblock (bool v)
230+
{
231+
int curf = max (0, fcntl (FCNTLID (F_GETFL)));
232+
if (v) curf |= O_NONBLOCK;
233+
else curf &= ~O_NONBLOCK;
234+
fcntl (FCNTLID (F_SETFL), curf);
235+
}
236+
237+
#if HAVE_SYS_MMAN_H
238+
227239
/// Memory-maps the file and returns a link to it.
228240
memlink fstream::mmap (off_t n, off_t offset)
229241
{
@@ -248,12 +260,6 @@ void fstream::msync (memlink& l)
248260
set_and_throw (failbit, "msync");
249261
}
250262

251-
void fstream::set_nonblock (bool v)
252-
{
253-
int curf = max (0, fcntl (FCNTLID (F_GETFL)));
254-
if (v) curf |= O_NONBLOCK;
255-
else curf &= ~O_NONBLOCK;
256-
fcntl (FCNTLID (F_SETFL), curf);
257-
}
263+
#endif
258264

259265
} // namespace ustl

fstream.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,12 @@ class fstream : public ios_base {
4444
int fcntl (const char* rname, int request, long argument = 0);
4545
inline int fcntl (const char* rname, int request, int argument) { return (fstream::fcntl (rname, request, long(argument))); }
4646
inline int fcntl (const char* rname, int request, void* argument) { return (fstream::fcntl (rname, request, intptr_t(argument))); }
47+
void set_nonblock (bool v = true);
48+
#if HAVE_SYS_MMAN_H
4749
memlink mmap (off_t n, off_t offset = 0);
4850
void munmap (memlink& l);
4951
void msync (memlink& l);
50-
void set_nonblock (bool v = true);
52+
#endif
5153
inline int fd (void) const { return (m_fd); }
5254
inline bool is_open (void) const { return (fd() >= 0); }
5355
inline off_t tellg (void) const { return (pos()); }

0 commit comments

Comments
 (0)