|
Boost-Commit : |
From: technews_at_[hidden]
Date: 2007-12-26 14:42:37
Author: turkanis
Date: 2007-12-26 14:42:37 EST (Wed, 26 Dec 2007)
New Revision: 42308
URL: http://svn.boost.org/trac/boost/changeset/42308
Log:
attempt to resolve ticket #824
Added:
branches/iostreams_dev/boost/iostreams/detail/config/rtl.hpp (contents, props changed)
Text files modified:
branches/iostreams_dev/libs/iostreams/src/file_descriptor.cpp | 57 ++++++++++++---------------------------
1 files changed, 18 insertions(+), 39 deletions(-)
Added: branches/iostreams_dev/boost/iostreams/detail/config/rtl.hpp
==============================================================================
--- (empty file)
+++ branches/iostreams_dev/boost/iostreams/detail/config/rtl.hpp 2007-12-26 14:42:37 EST (Wed, 26 Dec 2007)
@@ -0,0 +1,58 @@
+/*
+ * Distributed under the Boost Software License, Version 1.0.(See accompanying
+ * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.)
+ *
+ * See http://www.boost.org/libs/iostreams for documentation.
+ *
+ * Defines preprocessor symbols expanding to the names of functions in the
+ * C runtime library used to access file descriptors and to the type used
+ * to store file offsets for seeking.
+ *
+ * File: boost/iostreams/detail/config/rtl.hpp
+ * Date: Wed Dec 26 11:58:11 MST 2007
+ *
+ * Copyright: 2007 CodeRage
+ * Author: Jonathan Turkanis
+ */
+
+#ifndef BOOST_IOSTREAMS_DETAIL_CONFIG_RTL_HPP_INCLUDED
+#define BOOST_IOSTREAMS_DETAIL_CONFIG_RTL_HPP_INCLUDED
+
+#include <boost/config.hpp>
+#include <boost/iostreams/detail/config/windows_posix.hpp>
+
+// Handle open, close, read, and write
+#if defined(__BORLANDC__)
+# define BOOST_IOSTREAMS_RTL(x) BOOST_JOIN(_rtl_, x)
+#else
+# if defined(BOOST_IOSTREAMS_WINDOWS) && !defined(__CYGWIN__)
+# define BOOST_IOSTREAMS_RTL(x) BOOST_JOIN(_, x)
+# else
+# define BOOST_IOSTREAMS_RTL(x) ::x
+# endif
+#endif
+#define BOOST_IOSTREAMS_FD_OPEN BOOST_IOSTREAMS_RTL(open)
+#define BOOST_IOSTREAMS_FD_CLOSE BOOST_IOSTREAMS_RTL(close)
+#define BOOST_IOSTREAMS_FD_READ BOOST_IOSTREAMS_RTL(read)
+#define BOOST_IOSTREAMS_FD_WRITE BOOST_IOSTREAMS_RTL(write)
+
+// Handle lseek
+#if defined(BOOST_IOSTREAMS_WINDOWS) && !defined(__CYGWIN__)
+# if defined(BOOST_MSVC) || defined(__MSVCRT__) // MSVC, MinGW
+# define BOOST_IOSTREAMS_FD_SEEK _lseeki64
+# define BOOST_IOSTREAMS_FD_OFFSET __int64
+# else // Borland, Metrowerks, ...
+# define BOOST_IOSTREAMS_FD_SEEK lseek
+# define BOOST_IOSTREAMS_FD_OFFSET long
+# endif
+#else // Non-windows
+# if defined(_LARGEFILE64_SOURCE) || defined(BOOST_IOSTREAMS_HAS_LSEEK64)
+# define BOOST_IOSTREAMS_FD_SEEK lseek64 // GCC for some 32-bit *nix
+# define BOOST_IOSTREAMS_FD_OFFSET off64_t
+# else // Cygwin, Darwin, ...
+# define BOOST_IOSTREAMS_FD_SEEK lseek
+# define BOOST_IOSTREAMS_FD_OFFSET off_t
+# endif
+#endif
+
+#endif // #ifndef BOOST_IOSTREAMS_DETAIL_CONFIG_RTL_HPP_INCLUDED
Modified: branches/iostreams_dev/libs/iostreams/src/file_descriptor.cpp
==============================================================================
--- branches/iostreams_dev/libs/iostreams/src/file_descriptor.cpp (original)
+++ branches/iostreams_dev/libs/iostreams/src/file_descriptor.cpp 2007-12-26 14:42:37 EST (Wed, 26 Dec 2007)
@@ -1,4 +1,4 @@
-// (C) Copyright Jonathan Turkanis 2003.
+// (C) Copyright Jonathan Turkanis 2003-2007.
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.)
@@ -13,11 +13,12 @@
#define BOOST_IOSTREAMS_SOURCE
#include <cassert>
-#include <boost/config.hpp> // BOOST_JOIN
+#include <boost/config.hpp> // BOOST_JOIN
#include <boost/iostreams/detail/error.hpp>
#include <boost/iostreams/detail/config/dyn_link.hpp>
+#include <boost/iostreams/detail/config/rtl.hpp> // BOOST_IOSTREAMS_FD_XXX
#include <boost/iostreams/detail/config/windows_posix.hpp>
-#include <boost/iostreams/detail/ios.hpp> // openmodes, failure.
+#include <boost/iostreams/detail/ios.hpp> // openmodes, failure.
#include <boost/iostreams/device/file_descriptor.hpp>
#include <boost/integer_traits.hpp>
@@ -40,17 +41,6 @@
# include <unistd.h> // low-level file i/o.
#endif
-// Names of runtime library routines vary.
-#if defined(__BORLANDC__)
-# define BOOST_RTL(x) BOOST_JOIN(_rtl_, x)
-#else
-# if defined(BOOST_IOSTREAMS_WINDOWS) && !defined(__CYGWIN__)
-# define BOOST_RTL(x) BOOST_JOIN(_, x)
-# else
-# define BOOST_RTL(x) ::x
-# endif
-#endif
-
namespace boost { namespace iostreams {
//------------------Implementation of file_descriptor-------------------------//
@@ -135,7 +125,7 @@
// Open file.
- int fd = BOOST_RTL(open)(path.c_str(), oflag, pmode);
+ int fd = BOOST_IOSTREAMS_FD_OPEN(path.c_str(), oflag, pmode);
if (fd == -1) {
throw BOOST_IOSTREAMS_FAILURE("bad open");
} else {
@@ -156,7 +146,7 @@
}
#endif
errno = 0;
- std::streamsize result = BOOST_RTL(read)(pimpl_->fd_, s, n);
+ std::streamsize result = BOOST_IOSTREAMS_FD_READ(pimpl_->fd_, s, n);
if (errno != 0)
throw detail::bad_read();
return result == 0 ? -1 : result;
@@ -181,7 +171,7 @@
return n;
}
#endif
- int amt = BOOST_RTL(write)(pimpl_->fd_, s, n);
+ int amt = BOOST_IOSTREAMS_FD_WRITE(pimpl_->fd_, s, n);
if (amt < n)
throw detail::bad_write(); // Handles blocking fd's only.
return n;
@@ -215,32 +205,21 @@
}
}
#endif // #ifdef BOOST_IOSTREAMS_WINDOWS
-
-#ifndef BOOST_IOSTREAMS_HAS_LSEEK64
- if ( off > integer_traits<long>::const_max ||
- off < integer_traits<long>::const_min )
+ if ( off > integer_traits<BOOST_IOSTREAMS_FD_OFFSET>::const_max ||
+ off < integer_traits<BOOST_IOSTREAMS_FD_OFFSET>::const_min )
{
throw BOOST_IOSTREAMS_FAILURE("bad offset");
}
-#endif
-
stream_offset result =
- #ifdef BOOST_IOSTREAMS_HAS_LSEEK64
- lseek64
- #else
- lseek
- #endif
- ( pimpl_->fd_,
- #ifdef BOOST_IOSTREAMS_HAS_LSEEK64
- off,
- #else
- static_cast<long>(off),
- #endif
- way == BOOST_IOS::beg ?
+ BOOST_IOSTREAMS_FD_SEEK(
+ pimpl_->fd_,
+ static_cast<BOOST_IOSTREAMS_FD_OFFSET>(off),
+ ( way == BOOST_IOS::beg ?
SEEK_SET :
- way == BOOST_IOS::cur ?
- SEEK_CUR :
- SEEK_END );
+ way == BOOST_IOS::cur ?
+ SEEK_CUR :
+ SEEK_END )
+ );
if (result == -1)
throw detail::bad_seek();
return offset_to_position(result);
@@ -260,7 +239,7 @@
}
#endif
if (i.fd_ != -1) {
- if (BOOST_RTL(close)(i.fd_) == -1)
+ if (BOOST_IOSTREAMS_FD_CLOSE(i.fd_) == -1)
throw BOOST_IOSTREAMS_FAILURE("bad close");
i.fd_ = -1;
i.flags_ = 0;
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk