From 207aab6acf214e05572c772e19a53ad4bff151f0 Mon Sep 17 00:00:00 2001 From: Brad King Date: Mon, 31 Aug 2009 13:00:55 -0400 Subject: [PATCH] Define kwsys_ios_binary macro for std::ios::binary The 'binary' openmode does not exist on all compilers. We define macro _ios_binary, where is the KWSys namespace, to refer to std::ios::binary if it exists and 0 otherwise. Sample usage: kwsys_ios::ifstream fin(fn, kwsys_ios::ios::in | kwsys_ios_binary); --- Source/kwsys/CMakeLists.txt | 5 +++++ Source/kwsys/Configure.hxx.in | 12 ++++++++++++ Source/kwsys/kwsysPlatformTestsCXX.cxx | 11 +++++++++++ Source/kwsys/testIOS.cxx | 9 +++++++++ 4 files changed, 37 insertions(+) diff --git a/Source/kwsys/CMakeLists.txt b/Source/kwsys/CMakeLists.txt index 00d301e6f..07d54cad8 100644 --- a/Source/kwsys/CMakeLists.txt +++ b/Source/kwsys/CMakeLists.txt @@ -447,6 +447,11 @@ ELSE(KWSYS_IOS_USE_ANSI AND NOT WATCOM) KWSYS_PLATFORM_CXX_TEST(KWSYS_STL_STRING_HAVE_ISTREAM "Checking whether stl string has istream operator>>" DIRECT) ENDIF(KWSYS_IOS_USE_ANSI AND NOT WATCOM) +SET(KWSYS_PLATFORM_CXX_TEST_DEFINES + -DKWSYS_IOS_USE_ANSI=${KWSYS_IOS_USE_ANSI} + -DKWSYS_IOS_HAVE_STD=${KWSYS_IOS_HAVE_STD}) +KWSYS_PLATFORM_CXX_TEST(KWSYS_IOS_HAVE_BINARY + "Checking whether ios has binary openmode" DIRECT) SET(KWSYS_PLATFORM_CXX_TEST_DEFINES) KWSYS_PLATFORM_CXX_TEST(KWSYS_CXX_HAS_NULL_TEMPLATE_ARGS diff --git a/Source/kwsys/Configure.hxx.in b/Source/kwsys/Configure.hxx.in index 9e0653dcc..572d710d7 100644 --- a/Source/kwsys/Configure.hxx.in +++ b/Source/kwsys/Configure.hxx.in @@ -32,6 +32,9 @@ /* Whether old C++ header is to be used. */ #define @KWSYS_NAMESPACE@_IOS_USE_STRSTREA_H @KWSYS_IOS_USE_STRSTREA_H@ +/* Whether C++ streams support the ios::binary openmode. */ +#define @KWSYS_NAMESPACE@_IOS_HAVE_BINARY @KWSYS_IOS_HAVE_BINARY@ + /* Whether STL is in std namespace. */ #define @KWSYS_NAMESPACE@_STL_HAVE_STD @KWSYS_STL_HAVE_STD@ @@ -63,6 +66,13 @@ # define @KWSYS_NAMESPACE@_ios @KWSYS_NAMESPACE@_ios #endif +/* Define the ios::binary openmode macro. */ +#if @KWSYS_NAMESPACE@_IOS_HAVE_BINARY +# define @KWSYS_NAMESPACE@_ios_binary @KWSYS_NAMESPACE@_ios::ios::binary +#else +# define @KWSYS_NAMESPACE@_ios_binary 0 +#endif + /* Whether the cstddef header is available. */ #define @KWSYS_NAMESPACE@_CXX_HAS_CSTDDEF @KWSYS_CXX_HAS_CSTDDEF@ @@ -133,6 +143,7 @@ # define kwsys_stl @KWSYS_NAMESPACE@_stl # define kwsys_ios @KWSYS_NAMESPACE@_ios # define kwsys @KWSYS_NAMESPACE@ +# define kwsys_ios_binary @KWSYS_NAMESPACE@_ios_binary # endif # define KWSYS_NAME_IS_KWSYS @KWSYS_NAMESPACE@_NAME_IS_KWSYS # define KWSYS_STL_HAVE_STD @KWSYS_NAMESPACE@_STL_HAVE_STD @@ -141,6 +152,7 @@ # define KWSYS_IOS_USE_SSTREAM @KWSYS_NAMESPACE@_IOS_USE_SSTREAM # define KWSYS_IOS_USE_STRSTREAM_H @KWSYS_NAMESPACE@_IOS_USE_STRSTREAM_H # define KWSYS_IOS_USE_STRSTREA_H @KWSYS_NAMESPACE@_IOS_USE_STRSTREA_H +# define KWSYS_IOS_HAVE_BINARY @KWSYS_NAMESPACE@_IOS_HAVE_BINARY # define KWSYS_STAT_HAS_ST_MTIM @KWSYS_NAMESPACE@_STAT_HAS_ST_MTIM # define KWSYS_CXX_HAS_CSTDDEF @KWSYS_NAMESPACE@_CXX_HAS_CSTDDEF # define KWSYS_STL_STRING_HAVE_OSTREAM @KWSYS_NAMESPACE@_STL_STRING_HAVE_OSTREAM diff --git a/Source/kwsys/kwsysPlatformTestsCXX.cxx b/Source/kwsys/kwsysPlatformTestsCXX.cxx index 3d5550dd6..502e2d88b 100644 --- a/Source/kwsys/kwsysPlatformTestsCXX.cxx +++ b/Source/kwsys/kwsysPlatformTestsCXX.cxx @@ -294,6 +294,17 @@ int main() } #endif +#ifdef TEST_KWSYS_IOS_HAVE_BINARY +int test_binary(int, ...) +{ + return 0; +} +int main() +{ + return test_binary(1, kwsys_ios::ios::binary); +} +#endif + #ifdef TEST_KWSYS_IOS_HAS_ISTREAM_LONG_LONG int test_istream(kwsys_ios::istream& is, long long& x) { diff --git a/Source/kwsys/testIOS.cxx b/Source/kwsys/testIOS.cxx index 5b65d20b5..283910927 100644 --- a/Source/kwsys/testIOS.cxx +++ b/Source/kwsys/testIOS.cxx @@ -1,6 +1,7 @@ #include "kwsysPrivate.h" #include KWSYS_HEADER(stl/vector) #include KWSYS_HEADER(ios/sstream) +#include KWSYS_HEADER(ios/fstream) #include KWSYS_HEADER(ios/iostream) // Work-around CMake dependency scanning limitation. This must @@ -9,6 +10,7 @@ # include "kwsys_stl_string.hxx.in" # include "kwsys_stl_vector.h.in" # include "kwsys_ios_sstream.h.in" +# include "kwsys_ios_fstream.h.in" # include "kwsys_ios_iostream.h.in" #endif @@ -142,6 +144,13 @@ int testIOS(int, char*[]) return 1; } + // Just try to compile this. + if(x == 12345) + { + kwsys_ios::ifstream fin("/does_not_exist", + kwsys_ios::ios::in | kwsys_ios_binary); + } + kwsys_ios::cout << "IOS tests passed" << kwsys_ios::endl; return 0; }