From f057f1160aa5ac837e34088e6cc78234cedcc1f0 Mon Sep 17 00:00:00 2001 From: "mcmullen%netscape.com" Date: Fri, 11 Dec 1998 01:42:04 +0000 Subject: [PATCH] Some more tweaks to suit various compilers and platforms. git-svn-id: svn://10.0.0.236/trunk@16198 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/base/public/nsFileSpec.h | 8 +- mozilla/base/public/nsFileStream.h | 86 +++++++++++----------- mozilla/base/src/nsFileSpec.cpp | 22 +++--- mozilla/base/src/nsFileStream.cpp | 32 ++++---- mozilla/base/src/unix/nsFileSpecUnix.cpp | 4 +- mozilla/base/src/windows/nsFileSpecWin.cpp | 30 +++----- mozilla/xpcom/io/nsFileSpec.cpp | 22 +++--- mozilla/xpcom/io/nsFileSpec.h | 8 +- mozilla/xpcom/io/nsFileSpecUnix.cpp | 4 +- mozilla/xpcom/io/nsFileSpecWin.cpp | 30 +++----- mozilla/xpcom/io/nsFileStream.cpp | 32 ++++---- mozilla/xpcom/io/nsFileStream.h | 86 +++++++++++----------- 12 files changed, 176 insertions(+), 188 deletions(-) diff --git a/mozilla/base/public/nsFileSpec.h b/mozilla/base/public/nsFileSpec.h index 80ba05a9072..8e89ecf492f 100644 --- a/mozilla/base/public/nsFileSpec.h +++ b/mozilla/base/public/nsFileSpec.h @@ -103,12 +103,10 @@ #ifndef _FILESPEC_H_ #define _FILESPEC_H_ -#include - //======================================================================================== // Compiler-specific macros, as needed //======================================================================================== -#if defined(__MWERKS__) || defined(XP_PC) +#if !defined(NS_USING_NAMESPACE) && (defined(__MWERKS__) || defined(XP_PC)) #define NS_USING_NAMESPACE #endif @@ -116,11 +114,13 @@ #define NS_NAMESPACE_PROTOTYPE #define NS_NAMESPACE namespace #define NS_NAMESPACE_END +#include using std::ostream; #else #define NS_NAMESPACE_PROTOTYPE static #define NS_NAMESPACE struct #define NS_NAMESPACE_END ; +#include #endif //=========================== End Compiler-specific macros =============================== @@ -206,7 +206,7 @@ class nsNativeFileSpec #ifdef XP_MAC FSSpec mSpec; OSErr mError; -#elif defined(XP_UNIX) || defined(XP_PC) +#else char* mPath; #endif }; // class nsNativeFileSpec diff --git a/mozilla/base/public/nsFileStream.h b/mozilla/base/public/nsFileStream.h index b7ef9f06a4c..88ce60a622c 100644 --- a/mozilla/base/public/nsFileStream.h +++ b/mozilla/base/public/nsFileStream.h @@ -72,8 +72,7 @@ #ifndef _FILESTREAM_H_ #define _FILESTREAM_H_ -#include - + #ifdef XP_MAC #include "pprio.h" // To get PR_ImportFile #else @@ -84,7 +83,7 @@ //======================================================================================== // Compiler-specific macros, as needed //======================================================================================== -#if defined(__MWERKS__) || defined(XP_PC) +#if !defined(NS_USING_NAMESPACE) && (defined(__MWERKS__) || defined(XP_PC)) #define NS_USING_NAMESPACE #endif @@ -92,6 +91,8 @@ #define NS_NAMESPACE_PROTOTYPE #define NS_NAMESPACE namespace #define NS_NAMESPACE_END +#define BASIC_STREAMBUF basic_streambuf +#include using std::ios_base; using std::basic_streambuf; using std::codecvt_base; @@ -103,9 +104,11 @@ using std::basic_iostream; using std::char_traits; #else +#include #define NS_NAMESPACE_PROTOTYPE static #define NS_NAMESPACE struct #define NS_NAMESPACE_END ; +#define BASIC_STREAMBUF streambuf #endif #ifdef __MWERKS__ @@ -135,7 +138,7 @@ NS_NAMESPACE nsFileStreamHelpers { NS_NAMESPACE_PROTOTYPE PRFileDesc* open( const nsFilePath& inFile, - ios_base::openmode mode, + ios::openmode mode, PRIntn accessMode); } NS_NAMESPACE_END // nsFileStreamHelpers @@ -147,7 +150,7 @@ NS_NAMESPACE nsFileStreamHelpers template class nsFileBufferT //======================================================================================== -: public basic_streambuf +: public BASIC_STREAMBUF { typedef codecvt_base::result result; @@ -169,7 +172,7 @@ public: bool is_open() const; filebuf_type* open( const nsFilePath& inFile, - ios_base::openmode mode, + ios::openmode mode, PRIntn accessMode); filebuf_type* close(); @@ -178,11 +181,11 @@ protected: virtual int_type pbackfail(int_type c=traits::eof()); virtual int_type underflow(); virtual pos_type seekoff( - off_type off, ios_base::seekdir way, - ios_base::openmode which=ios_base::in|ios_base::out); + off_type off, ios::seekdir way, + ios::openmode which=ios::in|ios::out); virtual pos_type seekpos(pos_type sp, - ios_base::openmode which=ios_base::in|ios_base::out); - virtual basic_streambuf* setbuf(char_type* s, streamsize n); + ios::openmode which=ios::in|ios::out); + virtual BASIC_STREAMBUF* setbuf(char_type* s, streamsize n); virtual int sync(); virtual int_type uflow(); virtual void imbue(const locale& loc); @@ -192,7 +195,7 @@ protected: private: PRFileDesc* mFileDesc; - ios_base::openmode mode_; + ios::openmode mode_; }; // class nsFileBufferT //======================================================================================== @@ -213,7 +216,7 @@ public: nsInputFileStreamT(); explicit nsInputFileStreamT( const nsFilePath& inFile, - ios_base::openmode mode=ios_base::in, + ios::openmode mode=ios::in, PRIntn accessMode = 0x00400); virtual ~nsInputFileStreamT(); @@ -222,7 +225,7 @@ public: inline bool is_open(); inline void open( const nsFilePath& inFile, - ios_base::openmode mode=ios_base::in, + ios::openmode mode=ios::in, PRIntn accessMode = 0x00400); inline void close(); @@ -248,7 +251,7 @@ public: nsOutputFileStreamT(); explicit nsOutputFileStreamT( const nsFilePath& inFile, - ios_base::openmode mode = ios_base::out|ios_base::trunc, + ios::openmode mode = ios::out|ios::trunc, PRIntn accessMode = 0x00200); virtual ~nsOutputFileStreamT(); @@ -257,7 +260,7 @@ public: inline bool is_open(); inline void open( const nsFilePath& inFile, - ios_base::openmode mode = ios_base::out|ios_base::trunc, + ios::openmode mode = ios::out|ios::trunc, PRIntn accessMode = 0x00200); inline void close(); @@ -272,7 +275,7 @@ private: //---------------------------------------------------------------------------------------- template inline nsFileBufferT::nsFileBufferT() - : basic_streambuf(), mFileDesc(NULL) + : BASIC_STREAMBUF(), mFileDesc(NULL) //---------------------------------------------------------------------------------------- { } @@ -280,7 +283,7 @@ inline nsFileBufferT::nsFileBufferT() //---------------------------------------------------------------------------------------- template inline nsFileBufferT::nsFileBufferT(PRFileDesc* pfarg) - : basic_streambuf(), mFileDesc(pfarg) + : BASIC_STREAMBUF(), mFileDesc(pfarg) //---------------------------------------------------------------------------------------- { } @@ -305,10 +308,9 @@ nsFileBufferT::is_open() const //---------------------------------------------------------------------------------------- template -nsFileBufferT::filebuf_type* -nsFileBufferT::open( +nsFileBufferT* nsFileBufferT::open( const nsFilePath& inFile, - ios_base::openmode mode, + ios::openmode mode, PRIntn accessMode) //---------------------------------------------------------------------------------------- { @@ -324,7 +326,7 @@ nsFileBufferT::open( //---------------------------------------------------------------------------------------- template -nsFileBufferT::filebuf_type* nsFileBufferT::close() +nsFileBufferT* nsFileBufferT::close() //---------------------------------------------------------------------------------------- { if (mFileDesc==PR_STDIN || mFileDesc==PR_STDOUT || mFileDesc==PR_STDERR) @@ -344,7 +346,7 @@ nsFileBufferT:: sync() //---------------------------------------------------------------------------------------- template -inline basic_streambuf* +inline BASIC_STREAMBUF* nsFileBufferT::setbuf(char_type*, streamsize) //---------------------------------------------------------------------------------------- { @@ -499,18 +501,18 @@ nsFileBufferT::showmanyc() template nsFileBufferT::pos_type nsFileBufferT::seekoff( off_type off, - ios_base::seekdir way, - ios_base::openmode /* which */) + ios::seekdir way, + ios::openmode /* which */) //---------------------------------------------------------------------------------------- { - if (!mFileDesc || ((way&ios_base::beg) && off<0) || ((way&ios_base::end) && off > 0)) + if (!mFileDesc || ((way&ios::beg) && off<0) || ((way&ios::end) && off > 0)) return pos_type(-1); PRSeekWhence poseek = PR_SEEK_CUR; switch (way) { - case ios_base::beg : poseek= PR_SEEK_SET; + case ios::beg : poseek= PR_SEEK_SET; break; - case ios_base::end : poseek= PR_SEEK_END; + case ios::end : poseek= PR_SEEK_END; break; } PRInt32 position = PR_Seek(mFileDesc, off, poseek); @@ -522,7 +524,7 @@ nsFileBufferT::pos_type nsFileBufferT::seekoff( //---------------------------------------------------------------------------------------- template nsFileBufferT::pos_type -nsFileBufferT::seekpos(pos_type sp, ios_base::openmode) +nsFileBufferT::seekpos(pos_type sp, ios::openmode) //---------------------------------------------------------------------------------------- { if (!mFileDesc || sp==pos_type(-1)) @@ -550,7 +552,7 @@ inline nsInputFileStreamT::nsInputFileStreamT() template inline nsInputFileStreamT::nsInputFileStreamT( const nsFilePath& inFile, - ios_base::openmode mode, + ios::openmode mode, PRIntn accessMode) //---------------------------------------------------------------------------------------- : basic_istream(&mBuffer) @@ -569,11 +571,11 @@ inline nsInputFileStreamT::~nsInputFileStreamT() //---------------------------------------------------------------------------------------- template -inline nsInputFileStreamT::filebuf_type* +inline nsFileBufferT* nsInputFileStreamT::rdbuf() const //---------------------------------------------------------------------------------------- { - return (filebuf_type*)&mBuffer; + return (nsFileBufferT*)&mBuffer; } //---------------------------------------------------------------------------------------- @@ -590,7 +592,7 @@ template inline void nsInputFileStreamT::open( const nsFilePath& inFile, - ios_base::openmode mode, + ios::openmode mode, PRIntn accessMode) //---------------------------------------------------------------------------------------- { @@ -624,7 +626,7 @@ inline nsOutputFileStreamT::nsOutputFileStreamT() template nsOutputFileStreamT::nsOutputFileStreamT( const nsFilePath& inFile, - ios_base::openmode mode, + ios::openmode mode, PRIntn accessMode) //---------------------------------------------------------------------------------------- : basic_ostream(&mBuffer) @@ -643,11 +645,11 @@ inline nsOutputFileStreamT::~nsOutputFileStreamT() //---------------------------------------------------------------------------------------- template -inline nsOutputFileStreamT::filebuf_type* +inline nsFileBufferT* nsOutputFileStreamT::rdbuf() const //---------------------------------------------------------------------------------------- { - return (filebuf_type*)&mBuffer; + return (nsFileBufferT*)&mBuffer; } //---------------------------------------------------------------------------------------- @@ -662,7 +664,7 @@ inline bool nsOutputFileStreamT:: is_open() template inline void nsOutputFileStreamT::open( const nsFilePath& inFile, - ios_base::openmode mode, + ios::openmode mode, PRIntn accessMode) //---------------------------------------------------------------------------------------- { @@ -696,7 +698,7 @@ public: nsIOFileStreamT(); explicit nsIOFileStreamT( const nsFilePath& inFile, - ios_base::openmode mode = ios_base::in|ios_base::out, + ios::openmode mode = ios::in|ios::out, PRIntn accessMode = 0x00600); virtual ~nsIOFileStreamT(); @@ -705,7 +707,7 @@ public: inline bool is_open(); inline void open( const nsFilePath& inFile, - ios_base::openmode mode = ios_base::in|ios_base::out, + ios::openmode mode = ios::in|ios::out, PRIntn accessMode = 0x00600); inline void close(); @@ -730,7 +732,7 @@ inline nsIOFileStreamT::nsIOFileStreamT() template inline nsIOFileStreamT::nsIOFileStreamT( const nsFilePath& inFile, - ios_base::openmode mode, + ios::openmode mode, PRIntn accessMode) //---------------------------------------------------------------------------------------- : mBuffer(), basic_iostream(&mBuffer) @@ -747,11 +749,11 @@ inline nsIOFileStreamT::~nsIOFileStreamT() //---------------------------------------------------------------------------------------- template -inline nsIOFileStreamT::filebuf_type* +inline nsFileBufferT* nsIOFileStreamT::rdbuf() const //---------------------------------------------------------------------------------------- { - return (filebuf_type*)&mBuffer; + return (nsFileBufferT*)&mBuffer; } //---------------------------------------------------------------------------------------- @@ -768,7 +770,7 @@ template inline void nsIOFileStreamT::open( const nsFilePath& inFile, - ios_base::openmode mode, + ios::openmode mode, PRIntn accessMode) //---------------------------------------------------------------------------------------- { diff --git a/mozilla/base/src/nsFileSpec.cpp b/mozilla/base/src/nsFileSpec.cpp index 7cf82c25a4e..b2a82794851 100644 --- a/mozilla/base/src/nsFileSpec.cpp +++ b/mozilla/base/src/nsFileSpec.cpp @@ -20,11 +20,15 @@ #include "prtypes.h" -#if DEBUG +#ifdef NS_USING_NAMESPACE +#include +#include +#include +#else #include -#endif - #include +#include +#endif #ifdef NS_USING_NAMESPACE using std::ends; @@ -44,7 +48,7 @@ NS_NAMESPACE nsFileSpecHelpers char*& ioPath, char inSeparator, const char* inLeafName); - NS_NAMESPACE_PROTOTYPE const char* GetLeaf(const char* inPath, char inSeparator); + NS_NAMESPACE_PROTOTYPE char* GetLeaf(const char* inPath, char inSeparator); // allocated NS_NAMESPACE_PROTOTYPE char* StringDup(const char* inString, int allocLength = 0); NS_NAMESPACE_PROTOTYPE char* AllocCat(const char* inString1, const char* inString2); NS_NAMESPACE_PROTOTYPE char* StringAssign(char*& ioString, const char* inOther); @@ -117,7 +121,7 @@ void nsFileSpecHelpers::LeafReplace( } // nsNativeFileSpec::SetLeafName //---------------------------------------------------------------------------------------- -const char* nsFileSpecHelpers::GetLeaf(const char* inPath, char inSeparator) +char* nsFileSpecHelpers::GetLeaf(const char* inPath, char inSeparator) // Returns a pointer to an allocated string representing the leaf. //---------------------------------------------------------------------------------------- { @@ -369,7 +373,7 @@ void nsNativeFileSpec::MakeUnique() // start with "Picture-1.jpg" after "Picture.jpg" exists char buf[nsFileSpecHelpers::kMaxFilenameLength + 1]; ostrstream newName(buf, nsFileSpecHelpers::kMaxFilenameLength); - newName << leafName << "-" << index << suffix << ends; + newName << leafName << "-" << index << suffix << '\0'; // should be: << std::ends; SetLeafName(newName.str()); // or: SetLeafName(buf) } if (*suffix) @@ -392,7 +396,7 @@ void nsNativeFileSpec::operator = (const nsFileURL& inURL) //---------------------------------------------------------------------------------------- nsNativeFileSpec::nsNativeFileSpec(const nsFilePath& inPath) //---------------------------------------------------------------------------------------- -: mPath(nsFileSpecHelpers::StringDup((char*)inPath)) +: mPath(nsFileSpecHelpers::StringDup((const char*)inPath)) { } #endif // XP_UNIX @@ -410,7 +414,7 @@ void nsNativeFileSpec::operator = (const nsFilePath& inPath) //---------------------------------------------------------------------------------------- nsNativeFileSpec::nsNativeFileSpec(const nsNativeFileSpec& inSpec) //---------------------------------------------------------------------------------------- -: mPath(nsFileSpecHelpers::StringDup((char*)inSpec)) +: mPath(nsFileSpecHelpers::StringDup((const char*)inSpec)) { } #endif //XP_UNIX @@ -445,7 +449,7 @@ void nsNativeFileSpec::operator = (const nsNativeFileSpec& inSpec) #if defined(XP_UNIX) || defined(XP_PC) //---------------------------------------------------------------------------------------- -nsNativeFileSpec::operator = (const char* inString) +void nsNativeFileSpec::operator = (const char* inString) //---------------------------------------------------------------------------------------- { mPath = nsFileSpecHelpers::StringAssign(mPath, inString); diff --git a/mozilla/base/src/nsFileStream.cpp b/mozilla/base/src/nsFileStream.cpp index 6a35185d4e7..d61508c3f18 100644 --- a/mozilla/base/src/nsFileStream.cpp +++ b/mozilla/base/src/nsFileStream.cpp @@ -29,25 +29,25 @@ //---------------------------------------------------------------------------------------- PRFileDesc* nsFileStreamHelpers::open( const nsFilePath& inFile, - ios_base::openmode mode, + ios::openmode mode, PRIntn accessMode) //---------------------------------------------------------------------------------------- { PRFileDesc* descriptor = 0; - const ios_base::openmode valid_modes[]= + const ios::openmode valid_modes[]= { - ios_base::out, - ios_base::out | ios_base::app, - ios_base::out | ios_base::trunc, - ios_base::in, - ios_base::in | ios_base::out, - ios_base::in | ios_base::out | ios_base::trunc, -// ios_base::out | ios_base::binary, -// ios_base::out | ios_base::app | ios_base::binary, -// ios_base::out | ios_base::trunc | ios_base::binary, -// ios_base::in | ios_base::binary, -// ios_base::in | ios_base::out | ios_base::binary, -// ios_base::in | ios_base::out | ios_base::trunc | ios_base::binary, + ios::out, + ios::out | ios::app, + ios::out | ios::trunc, + ios::in, + ios::in | ios::out, + ios::in | ios::out | ios::trunc, +// ios::out | ios::binary, +// ios::out | ios::app | ios::binary, +// ios::out | ios::trunc | ios::binary, +// ios::in | ios::binary, +// ios::in | ios::out | ios::binary, +// ios::in | ios::out | ios::trunc | ios::binary, 0 }; @@ -67,7 +67,7 @@ PRFileDesc* nsFileStreamHelpers::open( // "w+b", 0 }; int ind=0; - while (valid_modes[ind] && valid_modes[ind] != (mode&~ios_base::ate)) + while (valid_modes[ind] && valid_modes[ind] != (mode&~ios::ate)) ++ind; if (!nspr_modes[ind]) return 0; @@ -118,7 +118,7 @@ PRFileDesc* nsFileStreamHelpers::open( // Platforms other than Macintosh... if ((descriptor = PR_Open(inFile, nspr_modes[ind], accessMode)) != 0) #endif - if (mode&ios_base::ate && PR_Seek(descriptor, 0, PR_SEEK_END) >= 0) + if (mode&ios::ate && PR_Seek(descriptor, 0, PR_SEEK_END) >= 0) { PR_Close(descriptor); descriptor = 0; diff --git a/mozilla/base/src/unix/nsFileSpecUnix.cpp b/mozilla/base/src/unix/nsFileSpecUnix.cpp index e11b72906a9..357ee8d1ed6 100644 --- a/mozilla/base/src/unix/nsFileSpecUnix.cpp +++ b/mozilla/base/src/unix/nsFileSpecUnix.cpp @@ -23,14 +23,14 @@ void nsNativeFileSpec::SetLeafName(const char* inLeafName) //---------------------------------------------------------------------------------------- { - nsFileHelpers::LeafReplace(mPath, '/', inLeafName); + nsFileSpecHelpers::LeafReplace(mPath, '/', inLeafName); } // nsNativeFileSpec::SetLeafName //---------------------------------------------------------------------------------------- char* nsNativeFileSpec::GetLeafName() const //---------------------------------------------------------------------------------------- { - return nsFileHelpers::GetLeaf(mPath, '/'); + return nsFileSpecHelpers::GetLeaf(mPath, '/'); } // nsNativeFileSpec::GetLeafName //---------------------------------------------------------------------------------------- diff --git a/mozilla/base/src/windows/nsFileSpecWin.cpp b/mozilla/base/src/windows/nsFileSpecWin.cpp index b97d62871bb..9d0ddf2db62 100644 --- a/mozilla/base/src/windows/nsFileSpecWin.cpp +++ b/mozilla/base/src/windows/nsFileSpecWin.cpp @@ -31,18 +31,12 @@ nsNativeFileSpec::nsNativeFileSpec(const nsFilePath& inPath) void nsNativeFileSpec::operator = (const nsFilePath& inPath) //---------------------------------------------------------------------------------------- { - delete [] mPath; // Convert '/' to '\' - const char* str = (const char*)inSpec; - mPath = new char[1 + strlen(str); - const char* src = str; - char* dst = mPath; - for (const char* temp = str; *temp; src++,dst++) + nsFileSpecHelpers::StringAssign(mPath, inSpec.mPath); + for (const char* cp = mPath; *cp; cp++) { - if (*src == '/') - *dst = '\\'; - else - *dst = *src; + if (*cp == '/') + *cp = '\\'; } } // nsNativeFileSpec::operator = @@ -55,21 +49,15 @@ nsFilePath::nsFilePath(const nsNativeFileSpec& inSpec) } // nsFilePath::nsFilePath //---------------------------------------------------------------------------------------- -nsFilePath::operator = (const nsNativeFileSpec& inSpec) +void nsFilePath::operator = (const nsNativeFileSpec& inSpec) //---------------------------------------------------------------------------------------- { - delete [] mPath; // Convert '\' to '/' - const char* str = (const char*)inSpec; - mPath = new char[1 + strlen(str); - const char* src = str; - char* dst = mPath; - for (const char* temp = str; *temp; src++,dst++) + nsFileSpecHelpers::StringAssign(mPath, inSpec.mPath); + for (const char* cp = mPath; *cp; cp++) { - if (*src == '\\') - *dst = '/'; - else - *dst = *src; + if (*cp == '\\') + *cp = '/'; } } // nsFilePath::operator = diff --git a/mozilla/xpcom/io/nsFileSpec.cpp b/mozilla/xpcom/io/nsFileSpec.cpp index 7cf82c25a4e..b2a82794851 100644 --- a/mozilla/xpcom/io/nsFileSpec.cpp +++ b/mozilla/xpcom/io/nsFileSpec.cpp @@ -20,11 +20,15 @@ #include "prtypes.h" -#if DEBUG +#ifdef NS_USING_NAMESPACE +#include +#include +#include +#else #include -#endif - #include +#include +#endif #ifdef NS_USING_NAMESPACE using std::ends; @@ -44,7 +48,7 @@ NS_NAMESPACE nsFileSpecHelpers char*& ioPath, char inSeparator, const char* inLeafName); - NS_NAMESPACE_PROTOTYPE const char* GetLeaf(const char* inPath, char inSeparator); + NS_NAMESPACE_PROTOTYPE char* GetLeaf(const char* inPath, char inSeparator); // allocated NS_NAMESPACE_PROTOTYPE char* StringDup(const char* inString, int allocLength = 0); NS_NAMESPACE_PROTOTYPE char* AllocCat(const char* inString1, const char* inString2); NS_NAMESPACE_PROTOTYPE char* StringAssign(char*& ioString, const char* inOther); @@ -117,7 +121,7 @@ void nsFileSpecHelpers::LeafReplace( } // nsNativeFileSpec::SetLeafName //---------------------------------------------------------------------------------------- -const char* nsFileSpecHelpers::GetLeaf(const char* inPath, char inSeparator) +char* nsFileSpecHelpers::GetLeaf(const char* inPath, char inSeparator) // Returns a pointer to an allocated string representing the leaf. //---------------------------------------------------------------------------------------- { @@ -369,7 +373,7 @@ void nsNativeFileSpec::MakeUnique() // start with "Picture-1.jpg" after "Picture.jpg" exists char buf[nsFileSpecHelpers::kMaxFilenameLength + 1]; ostrstream newName(buf, nsFileSpecHelpers::kMaxFilenameLength); - newName << leafName << "-" << index << suffix << ends; + newName << leafName << "-" << index << suffix << '\0'; // should be: << std::ends; SetLeafName(newName.str()); // or: SetLeafName(buf) } if (*suffix) @@ -392,7 +396,7 @@ void nsNativeFileSpec::operator = (const nsFileURL& inURL) //---------------------------------------------------------------------------------------- nsNativeFileSpec::nsNativeFileSpec(const nsFilePath& inPath) //---------------------------------------------------------------------------------------- -: mPath(nsFileSpecHelpers::StringDup((char*)inPath)) +: mPath(nsFileSpecHelpers::StringDup((const char*)inPath)) { } #endif // XP_UNIX @@ -410,7 +414,7 @@ void nsNativeFileSpec::operator = (const nsFilePath& inPath) //---------------------------------------------------------------------------------------- nsNativeFileSpec::nsNativeFileSpec(const nsNativeFileSpec& inSpec) //---------------------------------------------------------------------------------------- -: mPath(nsFileSpecHelpers::StringDup((char*)inSpec)) +: mPath(nsFileSpecHelpers::StringDup((const char*)inSpec)) { } #endif //XP_UNIX @@ -445,7 +449,7 @@ void nsNativeFileSpec::operator = (const nsNativeFileSpec& inSpec) #if defined(XP_UNIX) || defined(XP_PC) //---------------------------------------------------------------------------------------- -nsNativeFileSpec::operator = (const char* inString) +void nsNativeFileSpec::operator = (const char* inString) //---------------------------------------------------------------------------------------- { mPath = nsFileSpecHelpers::StringAssign(mPath, inString); diff --git a/mozilla/xpcom/io/nsFileSpec.h b/mozilla/xpcom/io/nsFileSpec.h index 80ba05a9072..8e89ecf492f 100644 --- a/mozilla/xpcom/io/nsFileSpec.h +++ b/mozilla/xpcom/io/nsFileSpec.h @@ -103,12 +103,10 @@ #ifndef _FILESPEC_H_ #define _FILESPEC_H_ -#include - //======================================================================================== // Compiler-specific macros, as needed //======================================================================================== -#if defined(__MWERKS__) || defined(XP_PC) +#if !defined(NS_USING_NAMESPACE) && (defined(__MWERKS__) || defined(XP_PC)) #define NS_USING_NAMESPACE #endif @@ -116,11 +114,13 @@ #define NS_NAMESPACE_PROTOTYPE #define NS_NAMESPACE namespace #define NS_NAMESPACE_END +#include using std::ostream; #else #define NS_NAMESPACE_PROTOTYPE static #define NS_NAMESPACE struct #define NS_NAMESPACE_END ; +#include #endif //=========================== End Compiler-specific macros =============================== @@ -206,7 +206,7 @@ class nsNativeFileSpec #ifdef XP_MAC FSSpec mSpec; OSErr mError; -#elif defined(XP_UNIX) || defined(XP_PC) +#else char* mPath; #endif }; // class nsNativeFileSpec diff --git a/mozilla/xpcom/io/nsFileSpecUnix.cpp b/mozilla/xpcom/io/nsFileSpecUnix.cpp index e11b72906a9..357ee8d1ed6 100644 --- a/mozilla/xpcom/io/nsFileSpecUnix.cpp +++ b/mozilla/xpcom/io/nsFileSpecUnix.cpp @@ -23,14 +23,14 @@ void nsNativeFileSpec::SetLeafName(const char* inLeafName) //---------------------------------------------------------------------------------------- { - nsFileHelpers::LeafReplace(mPath, '/', inLeafName); + nsFileSpecHelpers::LeafReplace(mPath, '/', inLeafName); } // nsNativeFileSpec::SetLeafName //---------------------------------------------------------------------------------------- char* nsNativeFileSpec::GetLeafName() const //---------------------------------------------------------------------------------------- { - return nsFileHelpers::GetLeaf(mPath, '/'); + return nsFileSpecHelpers::GetLeaf(mPath, '/'); } // nsNativeFileSpec::GetLeafName //---------------------------------------------------------------------------------------- diff --git a/mozilla/xpcom/io/nsFileSpecWin.cpp b/mozilla/xpcom/io/nsFileSpecWin.cpp index b97d62871bb..9d0ddf2db62 100644 --- a/mozilla/xpcom/io/nsFileSpecWin.cpp +++ b/mozilla/xpcom/io/nsFileSpecWin.cpp @@ -31,18 +31,12 @@ nsNativeFileSpec::nsNativeFileSpec(const nsFilePath& inPath) void nsNativeFileSpec::operator = (const nsFilePath& inPath) //---------------------------------------------------------------------------------------- { - delete [] mPath; // Convert '/' to '\' - const char* str = (const char*)inSpec; - mPath = new char[1 + strlen(str); - const char* src = str; - char* dst = mPath; - for (const char* temp = str; *temp; src++,dst++) + nsFileSpecHelpers::StringAssign(mPath, inSpec.mPath); + for (const char* cp = mPath; *cp; cp++) { - if (*src == '/') - *dst = '\\'; - else - *dst = *src; + if (*cp == '/') + *cp = '\\'; } } // nsNativeFileSpec::operator = @@ -55,21 +49,15 @@ nsFilePath::nsFilePath(const nsNativeFileSpec& inSpec) } // nsFilePath::nsFilePath //---------------------------------------------------------------------------------------- -nsFilePath::operator = (const nsNativeFileSpec& inSpec) +void nsFilePath::operator = (const nsNativeFileSpec& inSpec) //---------------------------------------------------------------------------------------- { - delete [] mPath; // Convert '\' to '/' - const char* str = (const char*)inSpec; - mPath = new char[1 + strlen(str); - const char* src = str; - char* dst = mPath; - for (const char* temp = str; *temp; src++,dst++) + nsFileSpecHelpers::StringAssign(mPath, inSpec.mPath); + for (const char* cp = mPath; *cp; cp++) { - if (*src == '\\') - *dst = '/'; - else - *dst = *src; + if (*cp == '\\') + *cp = '/'; } } // nsFilePath::operator = diff --git a/mozilla/xpcom/io/nsFileStream.cpp b/mozilla/xpcom/io/nsFileStream.cpp index 6a35185d4e7..d61508c3f18 100644 --- a/mozilla/xpcom/io/nsFileStream.cpp +++ b/mozilla/xpcom/io/nsFileStream.cpp @@ -29,25 +29,25 @@ //---------------------------------------------------------------------------------------- PRFileDesc* nsFileStreamHelpers::open( const nsFilePath& inFile, - ios_base::openmode mode, + ios::openmode mode, PRIntn accessMode) //---------------------------------------------------------------------------------------- { PRFileDesc* descriptor = 0; - const ios_base::openmode valid_modes[]= + const ios::openmode valid_modes[]= { - ios_base::out, - ios_base::out | ios_base::app, - ios_base::out | ios_base::trunc, - ios_base::in, - ios_base::in | ios_base::out, - ios_base::in | ios_base::out | ios_base::trunc, -// ios_base::out | ios_base::binary, -// ios_base::out | ios_base::app | ios_base::binary, -// ios_base::out | ios_base::trunc | ios_base::binary, -// ios_base::in | ios_base::binary, -// ios_base::in | ios_base::out | ios_base::binary, -// ios_base::in | ios_base::out | ios_base::trunc | ios_base::binary, + ios::out, + ios::out | ios::app, + ios::out | ios::trunc, + ios::in, + ios::in | ios::out, + ios::in | ios::out | ios::trunc, +// ios::out | ios::binary, +// ios::out | ios::app | ios::binary, +// ios::out | ios::trunc | ios::binary, +// ios::in | ios::binary, +// ios::in | ios::out | ios::binary, +// ios::in | ios::out | ios::trunc | ios::binary, 0 }; @@ -67,7 +67,7 @@ PRFileDesc* nsFileStreamHelpers::open( // "w+b", 0 }; int ind=0; - while (valid_modes[ind] && valid_modes[ind] != (mode&~ios_base::ate)) + while (valid_modes[ind] && valid_modes[ind] != (mode&~ios::ate)) ++ind; if (!nspr_modes[ind]) return 0; @@ -118,7 +118,7 @@ PRFileDesc* nsFileStreamHelpers::open( // Platforms other than Macintosh... if ((descriptor = PR_Open(inFile, nspr_modes[ind], accessMode)) != 0) #endif - if (mode&ios_base::ate && PR_Seek(descriptor, 0, PR_SEEK_END) >= 0) + if (mode&ios::ate && PR_Seek(descriptor, 0, PR_SEEK_END) >= 0) { PR_Close(descriptor); descriptor = 0; diff --git a/mozilla/xpcom/io/nsFileStream.h b/mozilla/xpcom/io/nsFileStream.h index b7ef9f06a4c..88ce60a622c 100644 --- a/mozilla/xpcom/io/nsFileStream.h +++ b/mozilla/xpcom/io/nsFileStream.h @@ -72,8 +72,7 @@ #ifndef _FILESTREAM_H_ #define _FILESTREAM_H_ -#include - + #ifdef XP_MAC #include "pprio.h" // To get PR_ImportFile #else @@ -84,7 +83,7 @@ //======================================================================================== // Compiler-specific macros, as needed //======================================================================================== -#if defined(__MWERKS__) || defined(XP_PC) +#if !defined(NS_USING_NAMESPACE) && (defined(__MWERKS__) || defined(XP_PC)) #define NS_USING_NAMESPACE #endif @@ -92,6 +91,8 @@ #define NS_NAMESPACE_PROTOTYPE #define NS_NAMESPACE namespace #define NS_NAMESPACE_END +#define BASIC_STREAMBUF basic_streambuf +#include using std::ios_base; using std::basic_streambuf; using std::codecvt_base; @@ -103,9 +104,11 @@ using std::basic_iostream; using std::char_traits; #else +#include #define NS_NAMESPACE_PROTOTYPE static #define NS_NAMESPACE struct #define NS_NAMESPACE_END ; +#define BASIC_STREAMBUF streambuf #endif #ifdef __MWERKS__ @@ -135,7 +138,7 @@ NS_NAMESPACE nsFileStreamHelpers { NS_NAMESPACE_PROTOTYPE PRFileDesc* open( const nsFilePath& inFile, - ios_base::openmode mode, + ios::openmode mode, PRIntn accessMode); } NS_NAMESPACE_END // nsFileStreamHelpers @@ -147,7 +150,7 @@ NS_NAMESPACE nsFileStreamHelpers template class nsFileBufferT //======================================================================================== -: public basic_streambuf +: public BASIC_STREAMBUF { typedef codecvt_base::result result; @@ -169,7 +172,7 @@ public: bool is_open() const; filebuf_type* open( const nsFilePath& inFile, - ios_base::openmode mode, + ios::openmode mode, PRIntn accessMode); filebuf_type* close(); @@ -178,11 +181,11 @@ protected: virtual int_type pbackfail(int_type c=traits::eof()); virtual int_type underflow(); virtual pos_type seekoff( - off_type off, ios_base::seekdir way, - ios_base::openmode which=ios_base::in|ios_base::out); + off_type off, ios::seekdir way, + ios::openmode which=ios::in|ios::out); virtual pos_type seekpos(pos_type sp, - ios_base::openmode which=ios_base::in|ios_base::out); - virtual basic_streambuf* setbuf(char_type* s, streamsize n); + ios::openmode which=ios::in|ios::out); + virtual BASIC_STREAMBUF* setbuf(char_type* s, streamsize n); virtual int sync(); virtual int_type uflow(); virtual void imbue(const locale& loc); @@ -192,7 +195,7 @@ protected: private: PRFileDesc* mFileDesc; - ios_base::openmode mode_; + ios::openmode mode_; }; // class nsFileBufferT //======================================================================================== @@ -213,7 +216,7 @@ public: nsInputFileStreamT(); explicit nsInputFileStreamT( const nsFilePath& inFile, - ios_base::openmode mode=ios_base::in, + ios::openmode mode=ios::in, PRIntn accessMode = 0x00400); virtual ~nsInputFileStreamT(); @@ -222,7 +225,7 @@ public: inline bool is_open(); inline void open( const nsFilePath& inFile, - ios_base::openmode mode=ios_base::in, + ios::openmode mode=ios::in, PRIntn accessMode = 0x00400); inline void close(); @@ -248,7 +251,7 @@ public: nsOutputFileStreamT(); explicit nsOutputFileStreamT( const nsFilePath& inFile, - ios_base::openmode mode = ios_base::out|ios_base::trunc, + ios::openmode mode = ios::out|ios::trunc, PRIntn accessMode = 0x00200); virtual ~nsOutputFileStreamT(); @@ -257,7 +260,7 @@ public: inline bool is_open(); inline void open( const nsFilePath& inFile, - ios_base::openmode mode = ios_base::out|ios_base::trunc, + ios::openmode mode = ios::out|ios::trunc, PRIntn accessMode = 0x00200); inline void close(); @@ -272,7 +275,7 @@ private: //---------------------------------------------------------------------------------------- template inline nsFileBufferT::nsFileBufferT() - : basic_streambuf(), mFileDesc(NULL) + : BASIC_STREAMBUF(), mFileDesc(NULL) //---------------------------------------------------------------------------------------- { } @@ -280,7 +283,7 @@ inline nsFileBufferT::nsFileBufferT() //---------------------------------------------------------------------------------------- template inline nsFileBufferT::nsFileBufferT(PRFileDesc* pfarg) - : basic_streambuf(), mFileDesc(pfarg) + : BASIC_STREAMBUF(), mFileDesc(pfarg) //---------------------------------------------------------------------------------------- { } @@ -305,10 +308,9 @@ nsFileBufferT::is_open() const //---------------------------------------------------------------------------------------- template -nsFileBufferT::filebuf_type* -nsFileBufferT::open( +nsFileBufferT* nsFileBufferT::open( const nsFilePath& inFile, - ios_base::openmode mode, + ios::openmode mode, PRIntn accessMode) //---------------------------------------------------------------------------------------- { @@ -324,7 +326,7 @@ nsFileBufferT::open( //---------------------------------------------------------------------------------------- template -nsFileBufferT::filebuf_type* nsFileBufferT::close() +nsFileBufferT* nsFileBufferT::close() //---------------------------------------------------------------------------------------- { if (mFileDesc==PR_STDIN || mFileDesc==PR_STDOUT || mFileDesc==PR_STDERR) @@ -344,7 +346,7 @@ nsFileBufferT:: sync() //---------------------------------------------------------------------------------------- template -inline basic_streambuf* +inline BASIC_STREAMBUF* nsFileBufferT::setbuf(char_type*, streamsize) //---------------------------------------------------------------------------------------- { @@ -499,18 +501,18 @@ nsFileBufferT::showmanyc() template nsFileBufferT::pos_type nsFileBufferT::seekoff( off_type off, - ios_base::seekdir way, - ios_base::openmode /* which */) + ios::seekdir way, + ios::openmode /* which */) //---------------------------------------------------------------------------------------- { - if (!mFileDesc || ((way&ios_base::beg) && off<0) || ((way&ios_base::end) && off > 0)) + if (!mFileDesc || ((way&ios::beg) && off<0) || ((way&ios::end) && off > 0)) return pos_type(-1); PRSeekWhence poseek = PR_SEEK_CUR; switch (way) { - case ios_base::beg : poseek= PR_SEEK_SET; + case ios::beg : poseek= PR_SEEK_SET; break; - case ios_base::end : poseek= PR_SEEK_END; + case ios::end : poseek= PR_SEEK_END; break; } PRInt32 position = PR_Seek(mFileDesc, off, poseek); @@ -522,7 +524,7 @@ nsFileBufferT::pos_type nsFileBufferT::seekoff( //---------------------------------------------------------------------------------------- template nsFileBufferT::pos_type -nsFileBufferT::seekpos(pos_type sp, ios_base::openmode) +nsFileBufferT::seekpos(pos_type sp, ios::openmode) //---------------------------------------------------------------------------------------- { if (!mFileDesc || sp==pos_type(-1)) @@ -550,7 +552,7 @@ inline nsInputFileStreamT::nsInputFileStreamT() template inline nsInputFileStreamT::nsInputFileStreamT( const nsFilePath& inFile, - ios_base::openmode mode, + ios::openmode mode, PRIntn accessMode) //---------------------------------------------------------------------------------------- : basic_istream(&mBuffer) @@ -569,11 +571,11 @@ inline nsInputFileStreamT::~nsInputFileStreamT() //---------------------------------------------------------------------------------------- template -inline nsInputFileStreamT::filebuf_type* +inline nsFileBufferT* nsInputFileStreamT::rdbuf() const //---------------------------------------------------------------------------------------- { - return (filebuf_type*)&mBuffer; + return (nsFileBufferT*)&mBuffer; } //---------------------------------------------------------------------------------------- @@ -590,7 +592,7 @@ template inline void nsInputFileStreamT::open( const nsFilePath& inFile, - ios_base::openmode mode, + ios::openmode mode, PRIntn accessMode) //---------------------------------------------------------------------------------------- { @@ -624,7 +626,7 @@ inline nsOutputFileStreamT::nsOutputFileStreamT() template nsOutputFileStreamT::nsOutputFileStreamT( const nsFilePath& inFile, - ios_base::openmode mode, + ios::openmode mode, PRIntn accessMode) //---------------------------------------------------------------------------------------- : basic_ostream(&mBuffer) @@ -643,11 +645,11 @@ inline nsOutputFileStreamT::~nsOutputFileStreamT() //---------------------------------------------------------------------------------------- template -inline nsOutputFileStreamT::filebuf_type* +inline nsFileBufferT* nsOutputFileStreamT::rdbuf() const //---------------------------------------------------------------------------------------- { - return (filebuf_type*)&mBuffer; + return (nsFileBufferT*)&mBuffer; } //---------------------------------------------------------------------------------------- @@ -662,7 +664,7 @@ inline bool nsOutputFileStreamT:: is_open() template inline void nsOutputFileStreamT::open( const nsFilePath& inFile, - ios_base::openmode mode, + ios::openmode mode, PRIntn accessMode) //---------------------------------------------------------------------------------------- { @@ -696,7 +698,7 @@ public: nsIOFileStreamT(); explicit nsIOFileStreamT( const nsFilePath& inFile, - ios_base::openmode mode = ios_base::in|ios_base::out, + ios::openmode mode = ios::in|ios::out, PRIntn accessMode = 0x00600); virtual ~nsIOFileStreamT(); @@ -705,7 +707,7 @@ public: inline bool is_open(); inline void open( const nsFilePath& inFile, - ios_base::openmode mode = ios_base::in|ios_base::out, + ios::openmode mode = ios::in|ios::out, PRIntn accessMode = 0x00600); inline void close(); @@ -730,7 +732,7 @@ inline nsIOFileStreamT::nsIOFileStreamT() template inline nsIOFileStreamT::nsIOFileStreamT( const nsFilePath& inFile, - ios_base::openmode mode, + ios::openmode mode, PRIntn accessMode) //---------------------------------------------------------------------------------------- : mBuffer(), basic_iostream(&mBuffer) @@ -747,11 +749,11 @@ inline nsIOFileStreamT::~nsIOFileStreamT() //---------------------------------------------------------------------------------------- template -inline nsIOFileStreamT::filebuf_type* +inline nsFileBufferT* nsIOFileStreamT::rdbuf() const //---------------------------------------------------------------------------------------- { - return (filebuf_type*)&mBuffer; + return (nsFileBufferT*)&mBuffer; } //---------------------------------------------------------------------------------------- @@ -768,7 +770,7 @@ template inline void nsIOFileStreamT::open( const nsFilePath& inFile, - ios_base::openmode mode, + ios::openmode mode, PRIntn accessMode) //---------------------------------------------------------------------------------------- {