diff --git a/ppremake/acconfig.h b/ppremake/acconfig.h index 76ba765d4e..a1d06dea8a 100644 --- a/ppremake/acconfig.h +++ b/ppremake/acconfig.h @@ -20,6 +20,9 @@ /* Define if the C++ iostream library supports ios::binary. */ #undef HAVE_IOS_BINARY +/* Define if fstream::open() accepts a third parameter for umask. */ +#undef HAVE_OPEN_MASK + /* Define if we're compiling with Cygwin. */ #undef HAVE_CYGWIN diff --git a/ppremake/acinclude.m4 b/ppremake/acinclude.m4 index 8d0ddeb10d..dfaea1f033 100644 --- a/ppremake/acinclude.m4 +++ b/ppremake/acinclude.m4 @@ -9,7 +9,7 @@ if test $have_iostream = yes; then AC_TRY_COMPILE([ #include ],[ - int x; x = ios::binary; + int x; x = std::ios::binary; ], ac_cv_ios_binary=yes, ac_cv_ios_binary=no) else AC_TRY_COMPILE([ @@ -25,6 +25,30 @@ if test $ac_cv_ios_binary = yes; then fi ]) +AC_DEFUN(AC_OPEN_MASK, +[AC_CACHE_CHECK([for third umask parameter to open], + ac_cv_open_mask, +[ +if test $have_iostream = yes; then + AC_TRY_COMPILE([ +#include + ],[ + std::ofstream x; x.open("foo", std::ios::out, 0666); + ], ac_cv_open_mask=yes, ac_cv_open_mask=no) +else + AC_TRY_COMPILE([ +#include + ],[ + ofstream x; x.open("foo", ios::out, 0666); + ], ac_cv_open_mask=yes, ac_cv_open_mask=no) +fi + +]) +if test $ac_cv_open_mask = yes; then + AC_DEFINE(HAVE_OPEN_MASK) +fi +]) + AC_DEFUN(AC_NAMESPACE, [AC_CACHE_CHECK([for compiler namespace support], diff --git a/ppremake/configure.in b/ppremake/configure.in index 11f6ae877a..8f1c130784 100644 --- a/ppremake/configure.in +++ b/ppremake/configure.in @@ -54,6 +54,8 @@ dnl Now we can test some C++-specific features. AC_LANG_CPLUSPLUS AC_HEADER_IOSTREAM AC_NAMESPACE +AC_IOS_BINARY +AC_OPEN_MASK AC_LANG_C diff --git a/ppremake/filename.cxx b/ppremake/filename.cxx index 97b9683adf..e6ed230ca7 100644 --- a/ppremake/filename.cxx +++ b/ppremake/filename.cxx @@ -1158,7 +1158,7 @@ bool Filename:: open_read(ifstream &stream) const { assert(is_text() || is_binary()); - int open_mode = ios::in; + ios::openmode open_mode = ios::in; #ifdef HAVE_IOS_BINARY // For some reason, some systems (like Irix) don't define @@ -1189,7 +1189,7 @@ bool Filename:: open_write(ofstream &stream) const { assert(is_text() || is_binary()); - int open_mode = ios::out; + ios::openmode open_mode = ios::out; #ifdef HAVE_IOS_BINARY // For some reason, some systems (like Irix) don't define @@ -1201,10 +1201,10 @@ open_write(ofstream &stream) const { stream.clear(); string os_specific = to_os_specific(); -#ifdef WIN32_VC - stream.open(os_specific.c_str(), open_mode); -#else +#ifdef HAVE_OPEN_MASK stream.open(os_specific.c_str(), open_mode, 0666); +#else + stream.open(os_specific.c_str(), open_mode); #endif return (!stream.fail()); @@ -1225,7 +1225,7 @@ bool Filename:: open_append(ofstream &stream) const { assert(is_text() || is_binary()); - int open_mode = ios::app; + ios::openmode open_mode = ios::app; #ifdef HAVE_IOS_BINARY // For some reason, some systems (like Irix) don't define @@ -1237,10 +1237,10 @@ open_append(ofstream &stream) const { stream.clear(); string os_specific = to_os_specific(); -#ifdef WIN32_VC - stream.open(os_specific.c_str(), open_mode); -#else +#ifdef HAVE_OPEN_MASK stream.open(os_specific.c_str(), open_mode, 0666); +#else + stream.open(os_specific.c_str(), open_mode); #endif return (!stream.fail()); @@ -1261,7 +1261,7 @@ bool Filename:: open_read_write(fstream &stream) const { assert(is_text() || is_binary()); - int open_mode = ios::in | ios::out; + ios::openmode open_mode = ios::in | ios::out; #ifdef HAVE_IOS_BINARY // For some reason, some systems (like Irix) don't define @@ -1273,10 +1273,10 @@ open_read_write(fstream &stream) const { stream.clear(); string os_specific = to_os_specific(); -#ifdef WIN32_VC - stream.open(os_specific.c_str(), open_mode); -#else +#ifdef HAVE_OPEN_MASK stream.open(os_specific.c_str(), open_mode, 0666); +#else + stream.open(os_specific.c_str(), open_mode); #endif return (!stream.fail()); diff --git a/ppremake/ppCommandFile.cxx b/ppremake/ppCommandFile.cxx index 299de0fa9a..c4f87cc5c5 100644 --- a/ppremake/ppCommandFile.cxx +++ b/ppremake/ppCommandFile.cxx @@ -1230,7 +1230,7 @@ handle_end_command() { // there, if there is one. nest->_output << ends; - const char *generated_file = nest->_output.str(); + string generated_file = nest->_output.str(); if (!compare_output(generated_file, nest->_params, (nest->_flags & OF_notouch) != 0)) { return false; diff --git a/ppremake/ppCommandFile.h b/ppremake/ppCommandFile.h index a9bd714666..3985497bce 100644 --- a/ppremake/ppCommandFile.h +++ b/ppremake/ppCommandFile.h @@ -167,7 +167,7 @@ private: WriteState *_write_state; PPScope *_scope; string _params; - ostrstream _output; + ostringstream _output; vector _words; int _flags; BlockNesting *_next; @@ -185,9 +185,9 @@ private: vector _saved_lines; - friend PPCommandFile::IfNesting; - friend PPCommandFile::WriteState; - friend PPCommandFile::BlockNesting; + friend class PPCommandFile::IfNesting; + friend class PPCommandFile::WriteState; + friend class PPCommandFile::BlockNesting; }; diff --git a/ppremake/ppScope.cxx b/ppremake/ppScope.cxx index e60b2fd652..011a9e19c5 100644 --- a/ppremake/ppScope.cxx +++ b/ppremake/ppScope.cxx @@ -3128,10 +3128,10 @@ expand_function(const string &funcname, PPScope nested_scope(_named_scopes); nested_scope.define_formals(funcname, sub->_formals, params); - // This won't compile on VC++ with the new iostream library. It has - // only ostringstream, which is functionally equivalent but has a - // slightly different interface. - ostrstream ostr; + // This won't compile older C++ libraries that do not have + // ostrstring. (The earlier interface was ostrstream, which is + // functionally equivalent but slightly different.) + ostringstream ostr; PPCommandFile command(&nested_scope); command.set_output(&ostr); @@ -3151,14 +3151,14 @@ expand_function(const string &funcname, // Now get the output. We split it into words and then reconnect // it, to replace all whitespace with spaces. - ostr << ends; - char *str = ostr.str(); + // ostr << ends; + string str = ostr.str(); vector results; tokenize_whitespace(str, results); string result = repaste(results, " "); - delete[] str; + // delete[] str; return result; } diff --git a/ppremake/ppremake.h b/ppremake/ppremake.h index 07e77556b0..09fecb0600 100644 --- a/ppremake/ppremake.h +++ b/ppremake/ppremake.h @@ -20,7 +20,7 @@ #ifdef HAVE_IOSTREAM #include #include -#include +#include #else #include #include