|
Boost-Commit : |
From: technews_at_[hidden]
Date: 2008-06-26 14:40:23
Author: turkanis
Date: 2008-06-26 14:40:23 EDT (Thu, 26 Jun 2008)
New Revision: 46737
URL: http://svn.boost.org/trac/boost/changeset/46737
Log:
changes to wide-character path and file timestampt support for POSIX and MinGW
Text files modified:
trunk/boost/iostreams/detail/path.hpp | 64 ++++++++++++++++++++++++++++++++++++---
trunk/boost/iostreams/device/mapped_file.hpp | 7 +++-
trunk/libs/iostreams/src/file_descriptor.cpp | 8 ++--
trunk/libs/iostreams/src/file_times.cpp | 21 ++++++++-----
trunk/libs/iostreams/src/mapped_file.cpp | 14 ++++----
trunk/libs/iostreams/test/Jamfile.v2 | 11 +++++-
6 files changed, 95 insertions(+), 30 deletions(-)
Modified: trunk/boost/iostreams/detail/path.hpp
==============================================================================
--- trunk/boost/iostreams/detail/path.hpp (original)
+++ trunk/boost/iostreams/detail/path.hpp 2008-06-26 14:40:23 EDT (Thu, 26 Jun 2008)
@@ -20,14 +20,20 @@
#ifndef BOOST_IOSTREAMS_DETAIL_PATH_HPP_INCLUDED
#define BOOST_IOSTREAMS_DETAIL_PATH_HPP_INCLUDED
+#include <cstring>
#include <string>
+#include <boost/iostreams/detail/config/wide_streams.hpp>
+#ifndef BOOST_IOSTREAMS_NO_WIDE_STREAMS
+# include <cwchar>
+#endif
#include <boost/static_assert.hpp>
#include <boost/type.hpp>
#include <boost/type_traits/is_same.hpp>
-
namespace boost { namespace iostreams { namespace detail {
+#ifndef BOOST_IOSTREAMS_NO_WIDE_STREAMS //------------------------------------//
+
class path {
public:
@@ -86,17 +92,18 @@
{
typedef typename Path::external_string_type string_type;
init(p, boost::type<string_type>());
+ return *this;
}
bool is_wide() const { return is_wide_; }
// Returns a representation of the underlying path as a std::string
// Requires: is_wide() returns false
- std::string to_string() const { return narrow_; }
+ const char* c_str() const { return narrow_.c_str(); }
// Returns a representation of the underlying path as a std::wstring
// Requires: is_wide() returns true
- std::wstring to_wstring() const { return wide_; }
+ const wchar_t* c_wstr() const { return wide_.c_str(); }
private:
// For wide-character paths, use a boost::filesystem::wpath instead of a
@@ -115,8 +122,8 @@
template<typename Path>
void init(const Path& p, boost::type<std::wstring>)
{
- wide_ = p.external_file_string();
narrow_.clear();
+ wide_ = p.external_file_string();
is_wide_ = true;
}
@@ -128,10 +135,55 @@
inline bool operator==(const path& lhs, const path& rhs)
{
return lhs.is_wide() ?
- rhs.is_wide() && lhs.to_wstring() == rhs.to_wstring() :
- !rhs.is_wide() && lhs.to_string() == rhs.to_string();
+ rhs.is_wide() && std::wcscmp(lhs.c_wstr(), rhs.c_wstr()) == 0 :
+ !rhs.is_wide() && std::strcmp(lhs.c_str(), rhs.c_str()) == 0;
}
+#else // #ifndef BOOST_IOSTREAMS_NO_WIDE_STREAMS //---------------------------//
+
+class path {
+public:
+ path() { }
+ path(const std::string& p) : path_(p) { }
+ path(const char* p) : path_(p) { }
+ template<typename Path>
+ path(const Path& p) : path_(p.external_file_string()) { }
+ path(const path& p) : path_(p.path_) { }
+ path& operator=(const path& other)
+ {
+ path_ = other.path_;
+ return *this;
+ }
+ path& operator=(const std::string& p)
+ {
+ path_ = p;
+ return *this;
+ }
+ path& operator=(const char* p)
+ {
+ path_ = p;
+ return *this;
+ }
+ template<typename Path>
+ path& operator=(const Path& p)
+ {
+ path_ = p.external_file_string();
+ return *this;
+ }
+ bool is_wide() const { return false; }
+ const char* c_str() const { return path_.c_str(); }
+ const wchar_t* c_wstr() const { return 0; }
+private:
+ std::string path_;
+};
+
+inline bool operator==(const path& lhs, const path& rhs)
+{
+ return std::strcmp(lhs.c_str(), rhs.c_str()) == 0 ;
+}
+
+#endif // #ifndef BOOST_IOSTREAMS_NO_WIDE_STREAMS //--------------------------//
+
} } } // End namespaces detail, iostreams, boost.
#endif // #ifndef BOOST_IOSTREAMS_DETAIL_PATH_HPP_INCLUDED
Modified: trunk/boost/iostreams/device/mapped_file.hpp
==============================================================================
--- trunk/boost/iostreams/device/mapped_file.hpp (original)
+++ trunk/boost/iostreams/device/mapped_file.hpp 2008-06-26 14:40:23 EDT (Thu, 26 Jun 2008)
@@ -19,6 +19,7 @@
#include <boost/iostreams/concepts.hpp>
#include <boost/iostreams/detail/config/auto_link.hpp>
#include <boost/iostreams/detail/config/dyn_link.hpp>
+#include <boost/iostreams/detail/config/wide_streams.hpp>
#include <boost/iostreams/detail/ios.hpp> // openmode, failure
#include <boost/iostreams/detail/path.hpp>
#include <boost/iostreams/operations_fwd.hpp>
@@ -108,8 +109,10 @@
typedef detail::mapped_file_params_base base_type;
// For wide paths, instantiate basic_mapped_file_params
- // with boost::filesystem::wpath
+ // with boost::filesystem::wpath
+#ifndef BOOST_IOSTREAMS_NO_WIDE_STREAMS
BOOST_STATIC_ASSERT((!is_same<Path, std::wstring>::value));
+#endif
// Default constructor
basic_mapped_file_params() { }
@@ -147,7 +150,7 @@
typedef detail::mapped_file_impl impl_type;
typedef basic_mapped_file_params<detail::path> param_type;
friend class mapped_file;
- friend class impl_type;
+ friend class detail::mapped_file_impl;
friend struct boost::iostreams::operations<mapped_file_source>;
public:
typedef char char_type;
Modified: trunk/libs/iostreams/src/file_descriptor.cpp
==============================================================================
--- trunk/libs/iostreams/src/file_descriptor.cpp (original)
+++ trunk/libs/iostreams/src/file_descriptor.cpp 2008-06-26 14:40:23 EDT (Thu, 26 Jun 2008)
@@ -127,14 +127,14 @@
}
HANDLE handle = p.is_wide() ?
- ::CreateFileW( p.to_wstring().c_str(),
+ ::CreateFileW( p.c_wstr(),
dwDesiredAccess,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL, // lpSecurityAttributes
dwCreationDisposition,
FILE_ATTRIBUTE_NORMAL,
NULL ) : // hTemplateFile
- ::CreateFileA( p.to_string().c_str(),
+ ::CreateFileA( p.c_str(),
dwDesiredAccess,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL, // lpSecurityAttributes
@@ -182,9 +182,9 @@
// Open file.
- int fd = BOOST_IOSTREAMS_FD_OPEN(path.c_str(), oflag, pmode);
+ int fd = BOOST_IOSTREAMS_FD_OPEN(p.c_str(), oflag, pmode);
if (fd == -1) {
- throw throw_system_failure("failed opening file");
+ throw system_failure("failed opening file");
} else {
handle_ = fd;
flags_ = close_on_exit;
Modified: trunk/libs/iostreams/src/file_times.cpp
==============================================================================
--- trunk/libs/iostreams/src/file_times.cpp (original)
+++ trunk/libs/iostreams/src/file_times.cpp 2008-06-26 14:40:23 EDT (Thu, 26 Jun 2008)
@@ -34,9 +34,12 @@
# include <sys/types.h> // struct stat.
#endif
+// Must come last
+#include <boost/iostreams/detail/config/disable_warnings.hpp>
+
namespace boost { namespace iostreams { namespace detail {
-time_t last_read_time(file_handle h)
+std::time_t last_read_time(file_handle h)
{
#ifdef BOOST_IOSTREAMS_WINDOWS
FILETIME ft_access;
@@ -55,7 +58,7 @@
return std::mktime(&tm);
#else
struct stat info;
- if (::fstat(handle_, &info) == -1)
+ if (::fstat(h, &info) == -1)
throw_system_failure("failed querying last access time");
return info.st_atime;
#endif
@@ -81,19 +84,19 @@
throw_system_failure("failed settting last access time");
#else
struct stat info;
- if (::fstat(handle_, &info) == -1)
+ if (::fstat(h, &info) == -1)
throw_system_failure("failed settting last access time");
struct timeval tv[2];
tv[0].tv_sec = tm;
tv[0].tv_usec = 0;
tv[1].tv_sec = info.st_mtime;
tv[1].tv_usec = 0;
- if (futimes(handle_, tv) != 0)
+ if (futimes(h, tv) != 0)
throw_system_failure("failed settting last access time");
#endif
}
-time_t last_write_time(file_handle h)
+std::time_t last_write_time(file_handle h)
{
#ifdef BOOST_IOSTREAMS_WINDOWS
FILETIME ft_modification;
@@ -112,7 +115,7 @@
return std::mktime(&tm);
#else
struct stat info;
- if (::fstat(handle_, &info) == -1)
+ if (::fstat(h, &info) == -1)
throw_system_failure("failed querying last modification time");
return info.st_mtime;
#endif
@@ -138,16 +141,18 @@
throw_system_failure("failed settting last modification time");
#else
struct stat info;
- if (::fstat(handle_, &info) == -1)
+ if (::fstat(h, &info) == -1)
throw_system_failure("failed settting last modification time");
struct timeval tv[2];
tv[0].tv_sec = info.st_atime;
tv[0].tv_usec = 0;
tv[1].tv_sec = tm;
tv[1].tv_usec = 0;
- if (futimes(handle_, tv) != 0)
+ if (futimes(h, tv) != 0)
throw_system_failure("failed settting last modification time");
#endif
}
} } } // End namespaces detail, iostreams, boost.
+
+#include <boost/iostreams/detail/config/enable_warnings.hpp>
Modified: trunk/libs/iostreams/src/mapped_file.cpp
==============================================================================
--- trunk/libs/iostreams/src/mapped_file.cpp (original)
+++ trunk/libs/iostreams/src/mapped_file.cpp 2008-06-26 14:40:23 EDT (Thu, 26 Jun 2008)
@@ -186,7 +186,7 @@
FILE_ATTRIBUTE_TEMPORARY;
handle_ = p.path.is_wide() ?
::CreateFileW(
- p.path.to_wstring().c_str(),
+ p.path.c_wstr(),
dwDesiredAccess,
FILE_SHARE_READ,
NULL,
@@ -194,7 +194,7 @@
dwFlagsandAttributes,
NULL ) :
::CreateFileA(
- p.path.to_string().c_str(),
+ p.path.c_str(),
dwDesiredAccess,
FILE_SHARE_READ,
NULL,
@@ -265,7 +265,7 @@
oflag |= O_LARGEFILE;
#endif
errno = 0;
- handle_ = ::open(p.path.to_string().c_str(), flags, S_IRWXU);
+ handle_ = ::open(p.path.c_str(), flags, S_IRWXU);
if (errno != 0)
cleanup_and_throw("failed opening file");
@@ -323,8 +323,8 @@
::MapViewOfFileEx(
mapped_handle_,
access,
- (DWORD) (params_.offset >> 32),
- (DWORD) (params_.offset & 0xffffffff),
+ (DWORD) (p.offset >> 32),
+ (DWORD) (p.offset & 0xffffffff),
size_ != max_length ? size_ : 0,
(LPVOID) p.hint );
if (!data)
@@ -332,12 +332,12 @@
#else
void* data =
::BOOST_IOSTREAMS_FD_MMAP(
- p.hint_,
+ const_cast<char*>(p.hint),
size_,
readonly ? PROT_READ : (PROT_READ | PROT_WRITE),
priv ? MAP_PRIVATE : MAP_SHARED,
handle_,
- params_.offset );
+ p.offset );
if (data == MAP_FAILED)
cleanup_and_throw("failed mapping file");
#endif
Modified: trunk/libs/iostreams/test/Jamfile.v2
==============================================================================
--- trunk/libs/iostreams/test/Jamfile.v2 (original)
+++ trunk/libs/iostreams/test/Jamfile.v2 2008-06-26 14:40:23 EDT (Thu, 26 Jun 2008)
@@ -40,7 +40,8 @@
[ test-iostreams close_test.cpp ]
[ test-iostreams
code_converter_test.cpp
- detail/utf8_codecvt_facet.cpp : <link>static ]
+ detail/utf8_codecvt_facet.cpp
+ ../src/file_times.cpp : <link>static ]
[ test-iostreams combine_test.cpp ]
[ test-iostreams compose_test.cpp ]
[ test-iostreams component_access_test.cpp ]
@@ -51,7 +52,8 @@
[ test-iostreams execute_test.cpp ]
[ test-iostreams file_test.cpp ]
[ test-iostreams file_descriptor_test.cpp
- ../src/file_descriptor.cpp : <link>static ]
+ ../src/file_descriptor.cpp
+ ../src/file_times.cpp : <link>static ]
[ test-iostreams filtering_stream_test.cpp ]
[ test-iostreams finite_state_filter_test.cpp ]
[ test-iostreams flush_test.cpp ]
@@ -61,7 +63,8 @@
[ test-iostreams invert_test.cpp ]
[ test-iostreams line_filter_test.cpp ]
[ test-iostreams mapped_file_test.cpp
- ../src/mapped_file.cpp : <link>static ]
+ ../src/mapped_file.cpp
+ ../src/file_times.cpp : <link>static ]
[ test-iostreams newline_test.cpp ]
[ test-iostreams null_test.cpp ]
[ test-iostreams operation_sequence_test.cpp ]
@@ -90,6 +93,7 @@
large_file_test.cpp
../src/file_descriptor.cpp
../src/mapped_file.cpp
+ ../src/file_times.cpp
: <define>LARGE_FILE_KEEP=$(LARGE_FILE_KEEP)
<link>static ] ;
}
@@ -100,6 +104,7 @@
large_file_test.cpp
../src/file_descriptor.cpp
../src/mapped_file.cpp
+ ../src/file_times.cpp
: <define>LARGE_FILE_TEMP=$(LARGE_FILE_TEMP)
<link>static ] ;
}
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