From ab3213f20d64669e9cad70e21d0d477a615c1267 Mon Sep 17 00:00:00 2001 From: "mcmullen%netscape.com" Date: Tue, 15 Dec 1998 22:45:09 +0000 Subject: [PATCH] Made all this build on Unix, using Macros up the wazoo git-svn-id: svn://10.0.0.236/trunk@16466 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/base/public/Makefile.in | 3 + mozilla/base/public/nsEscape.h | 2 +- mozilla/base/public/nsFileStream.h | 486 ++++++++++++++++++----------- mozilla/base/src/Makefile.in | 3 + mozilla/base/src/nsFileSpec.cpp | 15 +- mozilla/base/src/nsFileStream.cpp | 7 +- mozilla/base/tests/FilesTest.cpp | 7 +- mozilla/base/tests/Makefile.in | 2 +- mozilla/xpcom/io/nsEscape.h | 2 +- mozilla/xpcom/io/nsFileSpec.cpp | 15 +- mozilla/xpcom/io/nsFileStream.cpp | 7 +- mozilla/xpcom/io/nsFileStream.h | 486 ++++++++++++++++++----------- mozilla/xpcom/tests/FilesTest.cpp | 7 +- 13 files changed, 633 insertions(+), 409 deletions(-) diff --git a/mozilla/base/public/Makefile.in b/mozilla/base/public/Makefile.in index e0965cd74aa..173e990617e 100644 --- a/mozilla/base/public/Makefile.in +++ b/mozilla/base/public/Makefile.in @@ -26,6 +26,9 @@ DEFINES += -D_IMPL_NS_BASE EXPORTS = \ nsISizeOfHandler.h \ + nsEscape.h \ + nsFileSpec.h \ + nsFileStream.h \ $(NULL) EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS)) diff --git a/mozilla/base/public/nsEscape.h b/mozilla/base/public/nsEscape.h index 8cd14adb710..df27e76cc0e 100644 --- a/mozilla/base/public/nsEscape.h +++ b/mozilla/base/public/nsEscape.h @@ -21,7 +21,7 @@ #ifndef _ESCAPE_H_ #define _ESCAPE_H_ -#include "PRTypes.h" +#include "prtypes.h" /* valid mask values for NET_Escape() and NET_EscapedSize(). */ typedef enum { diff --git a/mozilla/base/public/nsFileStream.h b/mozilla/base/public/nsFileStream.h index 582f1275fd7..4be4f1552de 100644 --- a/mozilla/base/public/nsFileStream.h +++ b/mozilla/base/public/nsFileStream.h @@ -56,11 +56,11 @@ // (not the notorious and bug prone const char*), namely nsFilePath. See // nsFileSpec.h for more details. // -// 5. Fixes a two bugs that have been there for a long time, and -// are inevitable if you use NSPR alone: +// 5. Fixes a bug that have been there for a long time, and +// is inevitable if you use NSPR alone: // // The problem on platforms (Macintosh) in which a path does not fully -// specify a file. +// specify a file, because two volumes can have the same name. // // Not yet provided: // @@ -88,13 +88,38 @@ #define NS_USING_NAMESPACE #endif +#if !defined(NS_USING_STL) && (defined(__MWERKS__) || defined(XP_PC)) +#define NS_USING_STL +#endif + #ifdef NS_USING_NAMESPACE + #define NS_NAMESPACE_PROTOTYPE #define NS_NAMESPACE namespace #define NS_NAMESPACE_END -#define BASIC_STREAMBUF basic_streambuf -#define IOS_BASE ios_base + +#else +#define NS_NAMESPACE_PROTOTYPE static +#define NS_NAMESPACE struct +#define NS_NAMESPACE_END ; + +#endif // NS_USING_NAMESPACE + +#ifdef NS_USING_STL + +// Macintosh and Windows use this section. +// +// Here's where the party is. When Unix wants to join in (by supporting +// a build system with STL headers), what fun we'll have! Meanwhile, I've used +// macros to make this build on all our platforms. Unix doesn't have support for +// STL, and therefore we could not use the template forms of these classes on Unix. +// (it's a long story). Therefore, Unix supports no stream char types except 1-byte +// characters, and therefore nobody else does now either, until Unix catches up. + + +#define DEFINING_FILE_STREAM // templateers define this when this file is included. +#define IOS_BASE ios_base #include using std::ios_base; using std::basic_streambuf; @@ -106,18 +131,49 @@ using std::basic_ostream; using std::basic_iostream; using std::char_traits; - +#define TEMPLATE_DEF template +#define FILE_BUFFER_TYPE nsFileBufferT +#define INPUT_FILE_STREAM nsInputFileStreamT +#define OUTPUT_FILE_STREAM nsOutputFileStreamT +#define IO_FILE_STREAM nsIOFileStreamT +#define BASIC_STREAMBUF basic_streambuf +#define BASIC_ISTREAM basic_istream +#define BASIC_OSTREAM basic_ostream +#define BASIC_IOSTREAM basic_iostream +#define INT_TYPE FILE_BUFFER_TYPE::int_type +#define POS_TYPE FILE_BUFFER_TYPE::pos_type +#define OFF_TYPE FILE_BUFFER_TYPE::off_type +#define SEEK_DIR IOS_BASE::seekdir +#define EOF_VALUE traits::eof() + #else -#define NS_NAMESPACE_PROTOTYPE static -#define NS_NAMESPACE struct -#define NS_NAMESPACE_END ; -#define BASIC_STREAMBUF streambuf +// Unix uses this section until it supports STL. This means no locales, no traits, +// no wide chars, etc. Also, the stream classes are the original ARM-style ones, +// and are not templatized. + #define IOS_BASE ios - #include +#define TEMPLATE_DEF +#define FILE_BUFFER_TYPE nsFileBufferT +#define INPUT_FILE_STREAM nsInputFileStreamT +#define OUTPUT_FILE_STREAM nsOutputFileStreamT +#define IO_FILE_STREAM nsIOFileStreamT +#define BASIC_STREAMBUF streambuf +#define BASIC_ISTREAM istream +#define BASIC_OSTREAM ostream +#define BASIC_IOSTREAM iostream +#define INT_TYPE int +#define POS_TYPE long +#define OFF_TYPE long +#define SEEK_DIR ios::seek_dir +#define int_type int +#define pos_type long +#define off_type long +#define char_type char +#define EOF_VALUE EOF -#endif // NS_USING_NAMESPACE +#endif // NS_USING_STL #ifdef __MWERKS__ @@ -132,11 +188,12 @@ #else -// Fix me for thread-safety. +// Fix me, if necessary, for thread-safety. #define NS_READ_LOCK(mut) #define NS_WRITE_LOCK(mut) #endif // __MWERKS__ + //=========================== End Compiler-specific macros =============================== //======================================================================================== @@ -156,11 +213,12 @@ NS_NAMESPACE nsFileStreamHelpers //======================================================================================== //======================================================================================== -template +TEMPLATE_DEF class nsFileBufferT //======================================================================================== -: public BASIC_STREAMBUF +: public BASIC_STREAMBUF { +#ifdef NS_USING_STL typedef codecvt_base::result result; public: @@ -171,57 +229,61 @@ public: typedef traits traits_type; typedef typename traits::state_type state_type; - typedef nsFileBufferT filebuf_type; typedef codecvt ofacet_type; typedef codecvt ifacet_type; +#endif +public: nsFileBufferT(); nsFileBufferT(PRFileDesc* pfile_arg); virtual ~nsFileBufferT(); bool is_open() const; - filebuf_type* open( + FILE_BUFFER_TYPE* open( const nsFilePath& inFile, IOS_BASE::openmode mode, PRIntn accessMode); - filebuf_type* close(); + FILE_BUFFER_TYPE* close(); protected: - virtual int_type overflow(int_type c=traits::eof()); - virtual int_type pbackfail(int_type c=traits::eof()); + virtual int_type overflow(int_type c=EOF_VALUE); + virtual int_type pbackfail(int_type c=EOF_VALUE); virtual int_type underflow(); virtual pos_type seekoff( - off_type off, IOS_BASE::seekdir way, + off_type off, SEEK_DIR way, IOS_BASE::openmode which=IOS_BASE::in|IOS_BASE::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); + virtual BASIC_STREAMBUF* setbuf(char_type* s, streamsize n); virtual int sync(); virtual int_type uflow(); +#ifdef NS_USING_STL virtual void imbue(const locale& loc); +#endif virtual streamsize showmanyc(); virtual streamsize xsgetn(char_type* s, streamsize n); virtual streamsize xsputn(const char_type* s, streamsize n); private: PRFileDesc* mFileDesc; - IOS_BASE::openmode mode_; + IOS_BASE::openmode mode_; }; // class nsFileBufferT //======================================================================================== -template +TEMPLATE_DEF class nsInputFileStreamT //======================================================================================== -: public basic_istream +: public BASIC_ISTREAM { - typedef nsFileBufferT filebuf_type; - +#ifdef NS_USING_STL public: typedef charT char_type; typedef typename traits::pos_type pos_type; typedef typename traits::off_type off_type; typedef typename traits::int_type int_type; typedef traits traits_type; +#endif +public: nsInputFileStreamT(); explicit nsInputFileStreamT( const nsFilePath& inFile, @@ -230,7 +292,7 @@ public: virtual ~nsInputFileStreamT(); - filebuf_type* rdbuf() const; + FILE_BUFFER_TYPE* rdbuf() const; inline bool is_open(); inline void open( const nsFilePath& inFile, @@ -239,23 +301,25 @@ public: inline void close(); private: - filebuf_type mBuffer; + FILE_BUFFER_TYPE mBuffer; }; // class nsInputFileStreamT //======================================================================================== -template +TEMPLATE_DEF class nsOutputFileStreamT //======================================================================================== -: public basic_ostream +: public BASIC_OSTREAM { - typedef nsFileBufferT filebuf_type; - +#ifdef NS_USING_STL public: typedef charT char_type; typedef typename traits::pos_type pos_type; typedef typename traits::off_type off_type; typedef typename traits::int_type int_type; typedef traits traits_type; +#endif + +public: nsOutputFileStreamT(); explicit nsOutputFileStreamT( @@ -265,7 +329,7 @@ public: virtual ~nsOutputFileStreamT(); - filebuf_type* rdbuf() const; + FILE_BUFFER_TYPE* rdbuf() const; inline bool is_open(); inline void open( const nsFilePath& inFile, @@ -274,7 +338,7 @@ public: inline void close(); private: - filebuf_type mBuffer; + FILE_BUFFER_TYPE mBuffer; }; // class nsOutputFileStreamT //======================================================================================== @@ -282,33 +346,47 @@ private: //======================================================================================== //---------------------------------------------------------------------------------------- -template -inline nsFileBufferT::nsFileBufferT() - : BASIC_STREAMBUF(), mFileDesc(NULL) +TEMPLATE_DEF +inline FILE_BUFFER_TYPE::nsFileBufferT() + : BASIC_STREAMBUF(), mFileDesc(NULL) //---------------------------------------------------------------------------------------- { } //---------------------------------------------------------------------------------------- -template -inline nsFileBufferT::nsFileBufferT(PRFileDesc* pfarg) - : BASIC_STREAMBUF(), mFileDesc(pfarg) +TEMPLATE_DEF +inline FILE_BUFFER_TYPE::nsFileBufferT(PRFileDesc* pfarg) + : BASIC_STREAMBUF(), mFileDesc(pfarg) //---------------------------------------------------------------------------------------- { } //---------------------------------------------------------------------------------------- -template -inline nsFileBufferT::~nsFileBufferT() +TEMPLATE_DEF +inline FILE_BUFFER_TYPE* FILE_BUFFER_TYPE::close() +// Must precede the destructor because both are inline. +//---------------------------------------------------------------------------------------- +{ + if (mFileDesc==PR_STDIN || mFileDesc==PR_STDOUT || mFileDesc==PR_STDERR) + return this; + NS_WRITE_LOCK(_mutex); + return (mFileDesc && PR_Close(mFileDesc) == PR_SUCCESS) ? mFileDesc = 0, this : 0; +} + +#if defined(DEFINING_FILE_STREAM) +//---------------------------------------------------------------------------------------- +TEMPLATE_DEF +FILE_BUFFER_TYPE::~nsFileBufferT() //---------------------------------------------------------------------------------------- { close(); } +#endif // #if defined(DEFINING_FILE_STREAM) //---------------------------------------------------------------------------------------- -template +TEMPLATE_DEF inline bool -nsFileBufferT::is_open() const +FILE_BUFFER_TYPE::is_open() const //---------------------------------------------------------------------------------------- { NS_READ_LOCK(_mutex); @@ -316,8 +394,8 @@ nsFileBufferT::is_open() const } //---------------------------------------------------------------------------------------- -template -nsFileBufferT* nsFileBufferT::open( +TEMPLATE_DEF +inline FILE_BUFFER_TYPE* FILE_BUFFER_TYPE::open( const nsFilePath& inFile, IOS_BASE::openmode mode, PRIntn accessMode) @@ -331,42 +409,35 @@ nsFileBufferT* nsFileBufferT::open( return 0; mode_ = mode; return this; -} // nsFileBufferT::open +} // FILE_BUFFER_TYPE::open //---------------------------------------------------------------------------------------- -template -nsFileBufferT* nsFileBufferT::close() -//---------------------------------------------------------------------------------------- -{ - if (mFileDesc==PR_STDIN || mFileDesc==PR_STDOUT || mFileDesc==PR_STDERR) - return this; - NS_WRITE_LOCK(_mutex); - return (mFileDesc && PR_Close(mFileDesc) == PR_SUCCESS) ? mFileDesc = 0, this : 0; -} - -//---------------------------------------------------------------------------------------- -template -inline int -nsFileBufferT:: sync() +TEMPLATE_DEF +inline int FILE_BUFFER_TYPE:: sync() //---------------------------------------------------------------------------------------- { return (mFileDesc ? (int)PR_Sync(mFileDesc) : 0); } //---------------------------------------------------------------------------------------- -template -inline BASIC_STREAMBUF* -nsFileBufferT::setbuf(char_type*, streamsize) +TEMPLATE_DEF +inline BASIC_STREAMBUF* FILE_BUFFER_TYPE::setbuf(char_type*, streamsize) //---------------------------------------------------------------------------------------- { return (!mFileDesc) ? 0 : this; } +#if defined(DEFINING_FILE_STREAM) //---------------------------------------------------------------------------------------- -template -nsFileBufferT::int_type nsFileBufferT::overflow(int_type c) +TEMPLATE_DEF +INT_TYPE FILE_BUFFER_TYPE::overflow(int_type c) //---------------------------------------------------------------------------------------- { +#ifndef NS_USING_STL + char ch = c; + PRInt32 bytesWrit1 = PR_Write(mFileDesc, &ch, sizeof(ch)); + return bytesWrit1 < sizeof(ch) ? EOF_VALUE : c; +#else #ifdef NS_EXPLICIT_FUNC_TEMPLATE_ARG const ofacet_type& ft=use_facet(getloc()); #elif defined(XP_PC) @@ -376,13 +447,13 @@ nsFileBufferT::int_type nsFileBufferT::overflow(in #endif char_type ch = traits_type::to_char_type(c); if (!mFileDesc) - return traits_type::eof(); - if (traits_type::eq_int_type(c, traits::eof())) + return EOF_VALUE; + if (traits_type::eq_int_type(c, EOF_VALUE)) return traits_type::not_eof(c); if (ft.always_noconv()) { PRInt32 bytesWrit1 = PR_Write(mFileDesc, &ch, sizeof(ch)); - return bytesWrit1 < sizeof(ch) ? traits::eof() : c; + return bytesWrit1 < sizeof(ch) ? EOF_VALUE : c; } { // <- sic! state_type fst; @@ -394,36 +465,43 @@ nsFileBufferT::int_type nsFileBufferT::overflow(in codecvt_base::noconv) { PRInt32 bytesWrit2 = PR_Write(mFileDesc, &ch, sizeof(ch)); - return bytesWrit2 < sizeof(ch) ? traits::eof() : c; + return bytesWrit2 < sizeof(ch) ? EOF_VALUE : c; } if ((conv==codecvt_base::partial)||(conv==codecvt_base::error)) - return traits::eof(); + return EOF_VALUE; *ebuf=0; PRInt32 bytesWrit3 = strlen(buf); - return PR_Write(mFileDesc, buf, bytesWrit3) < bytesWrit3 ? traits_type::eof() : c; + return PR_Write(mFileDesc, buf, bytesWrit3) < bytesWrit3 ? EOF_VALUE : c; } +#endif } +#endif // #if defined(DEFINING_FILE_STREAM) //---------------------------------------------------------------------------------------- -template -inline nsFileBufferT::int_type nsFileBufferT::underflow() +TEMPLATE_DEF +inline INT_TYPE FILE_BUFFER_TYPE::underflow() //---------------------------------------------------------------------------------------- { if (!mFileDesc) - return traits_type::eof(); + return EOF_VALUE; char_type s; PRInt32 request = 1; if (1 != PR_Read(mFileDesc, &s, request)) - return traits_type::eof(); + return EOF_VALUE; PR_Seek(mFileDesc, -1, PR_SEEK_CUR); return (int_type)s; } +#if defined(DEFINING_FILE_STREAM) //---------------------------------------------------------------------------------------- -template -streamsize nsFileBufferT::xsputn(const char_type* s, streamsize n) +TEMPLATE_DEF +streamsize FILE_BUFFER_TYPE::xsputn(const char_type* s, streamsize n) //---------------------------------------------------------------------------------------- { +#ifndef NS_USING_STL + PRInt32 bytesWrit1 = PR_Write(mFileDesc, s, sizeof(char) * size_t(n)); + return bytesWrit1 < 0 ? 0 : (streamsize)bytesWrit1; +#else #ifdef NS_EXPLICIT_FUNC_TEMPLATE_ARG const ofacet_type& ft=use_facet(loc); #elif defined(XP_PC) @@ -432,98 +510,111 @@ streamsize nsFileBufferT::xsputn(const char_type* s, streamsize n const ofacet_type& ft=use_facet(getloc(), (ofacet_type*)0); #endif if (!mFileDesc || !n) - return 0; + return 0; if (ft.always_noconv()) { - PRInt32 bytesWrit1 = PR_Write(mFileDesc, s, sizeof(char) * size_t(n)); - return bytesWrit1 < 0 ? 0 : (streamsize)bytesWrit1; + PRInt32 bytesWrit1 = PR_Write(mFileDesc, s, sizeof(char) * size_t(n)); + return bytesWrit1 < 0 ? 0 : (streamsize)bytesWrit1; } { // <- sic! - state_type fst; - const char_type* end; - char buf[8]; - char* ebuf; - result conv; + state_type fst; + const char_type* end; + char buf[8]; + char* ebuf; + result conv; #ifdef NS_EXPLICIT_FUNC_TEMPLATE_ARG - if ((conv=use_facet(getloc()). + if ((conv=use_facet(getloc()). #elif defined(XP_PC) - if ((conv=use_facet(getloc(), (ofacet_type*)0, false). + if ((conv=use_facet(getloc(), (ofacet_type*)0, false). #else - if ((conv=use_facet(getloc(), (ofacet_type*)0). + if ((conv=use_facet(getloc(), (ofacet_type*)0). #endif - out(fst, s, s+n, end, buf, buf+7, ebuf))==codecvt_base::noconv) - return (streamsize)PR_Write(mFileDesc, s, sizeof(char) * size_t(n)); - if ((conv==codecvt_base::partial) ||(conv==codecvt_base::error)) - return 0; - *ebuf=0; - PRInt32 bytesWrit2 = strlen(buf); - bytesWrit2 = PR_Write(mFileDesc, buf, bytesWrit2); - return bytesWrit2 < 0 ? 0 : streamsize(bytesWrit2 / sizeof(char_type)); + out(fst, s, s+n, end, buf, buf+7, ebuf))==codecvt_base::noconv) + return (streamsize)PR_Write(mFileDesc, s, sizeof(char) * size_t(n)); + if ((conv==codecvt_base::partial) ||(conv==codecvt_base::error)) + return 0; + *ebuf=0; + PRInt32 bytesWrit2 = strlen(buf); + bytesWrit2 = PR_Write(mFileDesc, buf, bytesWrit2); + return bytesWrit2 < 0 ? 0 : streamsize(bytesWrit2 / sizeof(char_type)); } -} +#endif +} // FILE_BUFFER_TYPE::xsputn +#endif // #if defined(DEFINING_FILE_STREAM) //---------------------------------------------------------------------------------------- -template -inline nsFileBufferT::int_type - nsFileBufferT::pbackfail(int_type c) +TEMPLATE_DEF +inline INT_TYPE FILE_BUFFER_TYPE::pbackfail(int_type c) //---------------------------------------------------------------------------------------- { if (!mFileDesc) - return traits_type::eof(); + return EOF_VALUE; if (PR_Seek(mFileDesc, -1, PR_SEEK_CUR) < 0) - return traits_type::eof(); - return (traits::eq_int_type(c, traits_type::eof())) ? traits::not_eof(c) : c; + return EOF_VALUE; + #ifdef NS_USING_STL + return (traits::eq_int_type(c, EOF_VALUE)) ? traits::not_eof(c) : c; + #else + return c; + #endif } //---------------------------------------------------------------------------------------- -template -inline nsFileBufferT::int_type nsFileBufferT::uflow() +TEMPLATE_DEF +inline INT_TYPE FILE_BUFFER_TYPE::uflow() //---------------------------------------------------------------------------------------- { if (!mFileDesc) - return traits_type::eof(); + return EOF_VALUE; char_type s; if (1 != PR_Read(mFileDesc, &s, 1)) // attempt to read 1 byte, confirm 1 byte - return traits_type::eof(); + return EOF_VALUE; return (int_type)s; } //---------------------------------------------------------------------------------------- -template -inline streamsize nsFileBufferT::xsgetn(char_type* s, streamsize n) +TEMPLATE_DEF +inline streamsize FILE_BUFFER_TYPE::xsgetn(char_type* s, streamsize n) //---------------------------------------------------------------------------------------- { return mFileDesc ? (streamsize)PR_Read(mFileDesc, s, sizeof(char) * size_t(n)) : 0; } +#ifdef NS_USING_STL //---------------------------------------------------------------------------------------- -template -inline void nsFileBufferT::imbue(const locale& loc_arg) +TEMPLATE_DEF +inline void FILE_BUFFER_TYPE::imbue(const locale& loc_arg) //---------------------------------------------------------------------------------------- { #ifdef XP_MAC loc = loc_arg; #endif } +#endif //---------------------------------------------------------------------------------------- -template -inline streamsize -nsFileBufferT::showmanyc() +TEMPLATE_DEF +inline streamsize FILE_BUFFER_TYPE::showmanyc() //---------------------------------------------------------------------------------------- { return (streamsize)PR_Available(mFileDesc); } +#if defined(DEFINING_FILE_STREAM) //---------------------------------------------------------------------------------------- -template -nsFileBufferT::pos_type nsFileBufferT::seekoff( - off_type off, - IOS_BASE::seekdir way, +TEMPLATE_DEF +POS_TYPE FILE_BUFFER_TYPE::seekoff( + OFF_TYPE off, + SEEK_DIR way, IOS_BASE::openmode /* which */) //---------------------------------------------------------------------------------------- { - if (!mFileDesc || ((way&IOS_BASE::beg) && off<0) || ((way&IOS_BASE::end) && off > 0)) + if (!mFileDesc || +#ifdef NS_USING_STL + ((way&IOS_BASE::beg) && off<0) || ((way&IOS_BASE::end) && off > 0) +#else + ((way == IOS_BASE::beg) && off<0) || ((way == IOS_BASE::end) && off > 0) +#endif + ) return pos_type(-1); PRSeekWhence poseek = PR_SEEK_CUR; switch (way) @@ -538,16 +629,17 @@ nsFileBufferT::pos_type nsFileBufferT::seekoff( return pos_type(-1); return pos_type(position); } +#endif // #if defined(DEFINING_FILE_STREAM) +#if defined(DEFINING_FILE_STREAM) //---------------------------------------------------------------------------------------- -template -nsFileBufferT::pos_type -nsFileBufferT::seekpos(pos_type sp, IOS_BASE::openmode) +TEMPLATE_DEF +POS_TYPE FILE_BUFFER_TYPE::seekpos(pos_type sp, IOS_BASE::openmode) //---------------------------------------------------------------------------------------- { if (!mFileDesc || sp==pos_type(-1)) return -1; -#if defined(XP_PC) +#if defined(XP_PC) || defined(XP_UNIX) PRInt32 position = sp; #else PRInt32 position = sp.offset(); @@ -557,63 +649,63 @@ nsFileBufferT::seekpos(pos_type sp, IOS_BASE::openmode) return pos_type(-1); return position; } +#endif // #if defined(DEFINING_FILE_STREAM) //======================================================================================== // Implementation of nsInputFileStreamT //======================================================================================== //---------------------------------------------------------------------------------------- -template -inline nsInputFileStreamT::nsInputFileStreamT() - : basic_istream(&mBuffer) +TEMPLATE_DEF +inline INPUT_FILE_STREAM::nsInputFileStreamT() + : BASIC_ISTREAM(&mBuffer) //---------------------------------------------------------------------------------------- { // already inited } //---------------------------------------------------------------------------------------- -template -inline nsInputFileStreamT::nsInputFileStreamT( +TEMPLATE_DEF +inline INPUT_FILE_STREAM::nsInputFileStreamT( const nsFilePath& inFile, IOS_BASE::openmode mode, PRIntn accessMode) //---------------------------------------------------------------------------------------- - : basic_istream(&mBuffer) + : BASIC_ISTREAM(&mBuffer) { // already inited if (!mBuffer.open(inFile, openmode(mode|in), accessMode)) setstate(failbit); } +#if defined(DEFINING_FILE_STREAM) //---------------------------------------------------------------------------------------- -template -inline nsInputFileStreamT::~nsInputFileStreamT() +TEMPLATE_DEF +INPUT_FILE_STREAM::~nsInputFileStreamT() //---------------------------------------------------------------------------------------- { } +#endif // #if defined(DEFINING_FILE_STREAM) //---------------------------------------------------------------------------------------- -template -inline nsFileBufferT* -nsInputFileStreamT::rdbuf() const +TEMPLATE_DEF +inline FILE_BUFFER_TYPE* INPUT_FILE_STREAM::rdbuf() const //---------------------------------------------------------------------------------------- { - return (nsFileBufferT*)&mBuffer; + return (FILE_BUFFER_TYPE*)&mBuffer; } //---------------------------------------------------------------------------------------- -template -inline bool -nsInputFileStreamT:: is_open() +TEMPLATE_DEF +inline bool INPUT_FILE_STREAM:: is_open() //---------------------------------------------------------------------------------------- { return mBuffer.is_open(); } //---------------------------------------------------------------------------------------- -template -inline void -nsInputFileStreamT::open( +TEMPLATE_DEF +inline void INPUT_FILE_STREAM::open( const nsFilePath& inFile, IOS_BASE::openmode mode, PRIntn accessMode) @@ -624,8 +716,8 @@ nsInputFileStreamT::open( } //---------------------------------------------------------------------------------------- -template -inline void nsInputFileStreamT::close() +TEMPLATE_DEF +inline void INPUT_FILE_STREAM::close() //---------------------------------------------------------------------------------------- { if (!mBuffer.close()) @@ -637,55 +729,59 @@ inline void nsInputFileStreamT::close() //======================================================================================== //---------------------------------------------------------------------------------------- -template -inline nsOutputFileStreamT::nsOutputFileStreamT() - : basic_ostream(&mBuffer) +TEMPLATE_DEF +inline OUTPUT_FILE_STREAM::nsOutputFileStreamT() + : BASIC_OSTREAM(&mBuffer) //---------------------------------------------------------------------------------------- { // already inited } +#if defined(DEFINING_FILE_STREAM) //---------------------------------------------------------------------------------------- -template -nsOutputFileStreamT::nsOutputFileStreamT( +TEMPLATE_DEF +OUTPUT_FILE_STREAM::nsOutputFileStreamT( const nsFilePath& inFile, IOS_BASE::openmode mode, PRIntn accessMode) //---------------------------------------------------------------------------------------- -: basic_ostream(&mBuffer) +: BASIC_OSTREAM(&mBuffer) { // already inited if (!mBuffer.open(inFile, openmode(mode|out), accessMode)) setstate(failbit); } +#endif // #if defined(DEFINING_FILE_STREAM) +#if defined(DEFINING_FILE_STREAM) //---------------------------------------------------------------------------------------- -template -inline nsOutputFileStreamT::~nsOutputFileStreamT() +TEMPLATE_DEF +inline OUTPUT_FILE_STREAM::~nsOutputFileStreamT() //---------------------------------------------------------------------------------------- { } +#endif // #if defined(DEFINING_FILE_STREAM) //---------------------------------------------------------------------------------------- -template -inline nsFileBufferT* -nsOutputFileStreamT::rdbuf() const +TEMPLATE_DEF +inline FILE_BUFFER_TYPE* +OUTPUT_FILE_STREAM::rdbuf() const //---------------------------------------------------------------------------------------- { - return (nsFileBufferT*)&mBuffer; + return (FILE_BUFFER_TYPE*)&mBuffer; } //---------------------------------------------------------------------------------------- -template -inline bool nsOutputFileStreamT:: is_open() +TEMPLATE_DEF +inline bool OUTPUT_FILE_STREAM:: is_open() //---------------------------------------------------------------------------------------- { return mBuffer.is_open(); } //---------------------------------------------------------------------------------------- -template -inline void nsOutputFileStreamT::open( +TEMPLATE_DEF +inline void OUTPUT_FILE_STREAM::open( const nsFilePath& inFile, IOS_BASE::openmode mode, PRIntn accessMode) @@ -696,8 +792,8 @@ inline void nsOutputFileStreamT::open( } //---------------------------------------------------------------------------------------- -template -inline void nsOutputFileStreamT:: close() +TEMPLATE_DEF +inline void OUTPUT_FILE_STREAM:: close() //---------------------------------------------------------------------------------------- { if (!mBuffer.close()) @@ -705,19 +801,20 @@ inline void nsOutputFileStreamT:: close() } //======================================================================================== -template -class nsIOFileStreamT : public basic_iostream +TEMPLATE_DEF +class nsIOFileStreamT : public BASIC_IOSTREAM //======================================================================================== { - typedef nsFileBufferT filebuf_type; - +#ifdef NS_USING_STL public: typedef charT char_type; typedef typename traits::pos_type pos_type; typedef typename traits::off_type off_type; typedef typename traits::int_type int_type; typedef traits traits_type; +#endif +public: nsIOFileStreamT(); explicit nsIOFileStreamT( const nsFilePath& inFile, @@ -726,7 +823,7 @@ public: virtual ~nsIOFileStreamT(); - filebuf_type* rdbuf() const; + FILE_BUFFER_TYPE* rdbuf() const; inline bool is_open(); inline void open( const nsFilePath& inFile, @@ -735,7 +832,7 @@ public: inline void close(); private: - filebuf_type mBuffer; + FILE_BUFFER_TYPE mBuffer; }; // class nsIOFileStreamT //======================================================================================== @@ -743,55 +840,55 @@ private: //======================================================================================== //---------------------------------------------------------------------------------------- -template -inline nsIOFileStreamT::nsIOFileStreamT() +TEMPLATE_DEF +inline IO_FILE_STREAM::nsIOFileStreamT() //---------------------------------------------------------------------------------------- - : mBuffer(), basic_iostream(&mBuffer) + : mBuffer(), BASIC_IOSTREAM(&mBuffer) { // already inited } //---------------------------------------------------------------------------------------- -template -inline nsIOFileStreamT::nsIOFileStreamT( +TEMPLATE_DEF +inline IO_FILE_STREAM::nsIOFileStreamT( const nsFilePath& inFile, IOS_BASE::openmode mode, PRIntn accessMode) //---------------------------------------------------------------------------------------- - : mBuffer(), basic_iostream(&mBuffer) + : mBuffer(), BASIC_IOSTREAM(&mBuffer) { // already inited if (!mBuffer.open(inFile, mode, accessMode)) setstate(failbit); } -template -inline nsIOFileStreamT::~nsIOFileStreamT() +//---------------------------------------------------------------------------------------- +TEMPLATE_DEF +inline IO_FILE_STREAM::~nsIOFileStreamT() +//---------------------------------------------------------------------------------------- { } //---------------------------------------------------------------------------------------- -template -inline nsFileBufferT* -nsIOFileStreamT::rdbuf() const +TEMPLATE_DEF +inline FILE_BUFFER_TYPE* +IO_FILE_STREAM::rdbuf() const //---------------------------------------------------------------------------------------- { - return (nsFileBufferT*)&mBuffer; + return (FILE_BUFFER_TYPE*)&mBuffer; } //---------------------------------------------------------------------------------------- -template -inline bool -nsIOFileStreamT::is_open() +TEMPLATE_DEF +inline bool IO_FILE_STREAM::is_open() //---------------------------------------------------------------------------------------- { return mBuffer.is_open(); } //---------------------------------------------------------------------------------------- -template -inline void -nsIOFileStreamT::open( +TEMPLATE_DEF +inline void IO_FILE_STREAM::open( const nsFilePath& inFile, IOS_BASE::openmode mode, PRIntn accessMode) @@ -802,9 +899,8 @@ nsIOFileStreamT::open( } //---------------------------------------------------------------------------------------- -template -inline void -nsIOFileStreamT::close() +TEMPLATE_DEF +inline void IO_FILE_STREAM::close() //---------------------------------------------------------------------------------------- { if (!mBuffer.close()) @@ -815,6 +911,7 @@ nsIOFileStreamT::close() // Specializations of the stream templates //======================================================================================== +#ifdef NS_USING_STL typedef nsFileBufferT > nsFileBuffer; typedef nsInputFileStreamT > nsInputFileStream; typedef nsOutputFileStreamT > nsOutputFileStream; @@ -827,5 +924,14 @@ typedef nsOutputFileStreamT > nsWideOutputFileStre typedef nsIOFileStreamT > nsWideIOFileStream; #endif // NS_USING_WIDE_CHAR +#else + +typedef nsFileBufferT nsFileBuffer; +typedef nsInputFileStreamT nsInputFileStream; +typedef nsOutputFileStreamT nsOutputFileStream; +typedef nsIOFileStreamT nsIOFileStream; + +#endif + #endif /* _FILESTREAM_H_ */ diff --git a/mozilla/base/src/Makefile.in b/mozilla/base/src/Makefile.in index 908bd0c37a0..b7d3c0f3f33 100644 --- a/mozilla/base/src/Makefile.in +++ b/mozilla/base/src/Makefile.in @@ -35,6 +35,9 @@ CPPSRCS = \ nsByteBuffer.cpp \ nsCRT.cpp \ nsDeque.cpp \ + nsEscape.cpp \ + nsFileSpec.cpp \ + nsFileStream.cpp \ nsRBTree.cpp \ nsSizeOfHandler.cpp \ nsString.cpp \ diff --git a/mozilla/base/src/nsFileSpec.cpp b/mozilla/base/src/nsFileSpec.cpp index f7f86cdf745..873ebcada1d 100644 --- a/mozilla/base/src/nsFileSpec.cpp +++ b/mozilla/base/src/nsFileSpec.cpp @@ -66,7 +66,7 @@ char* nsFileSpecHelpers::StringDup( { if (!allocLength && inString) allocLength = strlen(inString); - char* newPath = inString || allocLength ? new char[allocLength + 1] : NULL; + char* newPath = inString || allocLength ? new char[allocLength + 1] : 0; if (!newPath) return NULL; strcpy(newPath, inString); @@ -80,7 +80,7 @@ char* nsFileSpecHelpers::AllocCat( //---------------------------------------------------------------------------------------- { if (!inString1) - return StringDup(inString2); + return inString2 ? StringDup(inString2) : (char*)NULL; if (!inString2) return StringDup(inString1); char* outString = StringDup(inString1, strlen(inString1) + strlen(inString2)); @@ -98,15 +98,16 @@ char* nsFileSpecHelpers::StringAssign( if (!inString2) { delete [] ioString; - ioString = NULL; + ioString = (char*)NULL; + return ioString; } - else if (!ioString || (ioString && strlen(inString2) > strlen(ioString))) + if (!ioString || (strlen(inString2) > strlen(ioString))) { delete [] ioString; ioString = StringDup(inString2); + return ioString; } - else - strcpy(ioString, inString2); + strcpy(ioString, inString2); return ioString; } // nsFileSpecHelpers::StringAssign @@ -157,7 +158,7 @@ char* nsFileSpecHelpers::GetLeaf(const char* inPath, char inSeparator) #elif defined(XP_MAC) #include "nsFileSpecMac.cpp" // Macintosh-specific implementations #elif defined(XP_UNIX) -#include "nsFileSpecUnix.cpp" // Unix-specific implementations +#include "unix/nsFileSpecUnix.cpp" // Unix-specific implementations #endif //======================================================================================== diff --git a/mozilla/base/src/nsFileStream.cpp b/mozilla/base/src/nsFileStream.cpp index 96e34b2465a..f74b46209e4 100644 --- a/mozilla/base/src/nsFileStream.cpp +++ b/mozilla/base/src/nsFileStream.cpp @@ -18,7 +18,12 @@ // First checked in on 98/12/08 by John R. McMullen. // Since nsFileStream.h is entirely templates, common code (such as open()) -// does not actually depend on the charT, can be placed here. +// which does not actually depend on the charT, can be placed here. + +#ifdef XP_UNIX +// Compile the un-inlined functions in this file only. +#define DEFINING_FILE_STREAM +#endif #include "nsFileStream.h" diff --git a/mozilla/base/tests/FilesTest.cpp b/mozilla/base/tests/FilesTest.cpp index 17271fe7b8b..396bec6f47e 100644 --- a/mozilla/base/tests/FilesTest.cpp +++ b/mozilla/base/tests/FilesTest.cpp @@ -1,7 +1,7 @@ #include "nsFileSpec.h" #include "nsFileStream.h" -#ifdef NS_USING_NAMESPACE +#ifdef NS_USING_STL #include using namespace std; #else @@ -10,7 +10,7 @@ NS_NAMESPACE FileTest { - void WriteStuff(ostream& s); + NS_NAMESPACE_PROTOTYPE void WriteStuff(ostream& s); } NS_NAMESPACE_END //---------------------------------------------------------------------------------------- @@ -56,9 +56,6 @@ void main() //---------------------------------------------------------------------------------------- { -#if !defined(DEBUG) || (DEBUG==0) -#error "This test only works with a DEBUG build." -#endif // Test of nsFileSpec cout << "WRITING TEST OUTPUT TO cout" << endl << endl; diff --git a/mozilla/base/tests/Makefile.in b/mozilla/base/tests/Makefile.in index 14b8aa6dc91..a2f8f2ee780 100644 --- a/mozilla/base/tests/Makefile.in +++ b/mozilla/base/tests/Makefile.in @@ -23,7 +23,7 @@ include $(DEPTH)/config/autoconf.mk REQUIRES = xpcom netlib -CPPSRCS = TestAtoms.cpp TestCRT.cpp +CPPSRCS = TestAtoms.cpp TestCRT.cpp FilesTest.cpp OBJS = $(CPPSRCS:.cpp=.o) diff --git a/mozilla/xpcom/io/nsEscape.h b/mozilla/xpcom/io/nsEscape.h index 8cd14adb710..df27e76cc0e 100644 --- a/mozilla/xpcom/io/nsEscape.h +++ b/mozilla/xpcom/io/nsEscape.h @@ -21,7 +21,7 @@ #ifndef _ESCAPE_H_ #define _ESCAPE_H_ -#include "PRTypes.h" +#include "prtypes.h" /* valid mask values for NET_Escape() and NET_EscapedSize(). */ typedef enum { diff --git a/mozilla/xpcom/io/nsFileSpec.cpp b/mozilla/xpcom/io/nsFileSpec.cpp index f7f86cdf745..873ebcada1d 100644 --- a/mozilla/xpcom/io/nsFileSpec.cpp +++ b/mozilla/xpcom/io/nsFileSpec.cpp @@ -66,7 +66,7 @@ char* nsFileSpecHelpers::StringDup( { if (!allocLength && inString) allocLength = strlen(inString); - char* newPath = inString || allocLength ? new char[allocLength + 1] : NULL; + char* newPath = inString || allocLength ? new char[allocLength + 1] : 0; if (!newPath) return NULL; strcpy(newPath, inString); @@ -80,7 +80,7 @@ char* nsFileSpecHelpers::AllocCat( //---------------------------------------------------------------------------------------- { if (!inString1) - return StringDup(inString2); + return inString2 ? StringDup(inString2) : (char*)NULL; if (!inString2) return StringDup(inString1); char* outString = StringDup(inString1, strlen(inString1) + strlen(inString2)); @@ -98,15 +98,16 @@ char* nsFileSpecHelpers::StringAssign( if (!inString2) { delete [] ioString; - ioString = NULL; + ioString = (char*)NULL; + return ioString; } - else if (!ioString || (ioString && strlen(inString2) > strlen(ioString))) + if (!ioString || (strlen(inString2) > strlen(ioString))) { delete [] ioString; ioString = StringDup(inString2); + return ioString; } - else - strcpy(ioString, inString2); + strcpy(ioString, inString2); return ioString; } // nsFileSpecHelpers::StringAssign @@ -157,7 +158,7 @@ char* nsFileSpecHelpers::GetLeaf(const char* inPath, char inSeparator) #elif defined(XP_MAC) #include "nsFileSpecMac.cpp" // Macintosh-specific implementations #elif defined(XP_UNIX) -#include "nsFileSpecUnix.cpp" // Unix-specific implementations +#include "unix/nsFileSpecUnix.cpp" // Unix-specific implementations #endif //======================================================================================== diff --git a/mozilla/xpcom/io/nsFileStream.cpp b/mozilla/xpcom/io/nsFileStream.cpp index 96e34b2465a..f74b46209e4 100644 --- a/mozilla/xpcom/io/nsFileStream.cpp +++ b/mozilla/xpcom/io/nsFileStream.cpp @@ -18,7 +18,12 @@ // First checked in on 98/12/08 by John R. McMullen. // Since nsFileStream.h is entirely templates, common code (such as open()) -// does not actually depend on the charT, can be placed here. +// which does not actually depend on the charT, can be placed here. + +#ifdef XP_UNIX +// Compile the un-inlined functions in this file only. +#define DEFINING_FILE_STREAM +#endif #include "nsFileStream.h" diff --git a/mozilla/xpcom/io/nsFileStream.h b/mozilla/xpcom/io/nsFileStream.h index 582f1275fd7..4be4f1552de 100644 --- a/mozilla/xpcom/io/nsFileStream.h +++ b/mozilla/xpcom/io/nsFileStream.h @@ -56,11 +56,11 @@ // (not the notorious and bug prone const char*), namely nsFilePath. See // nsFileSpec.h for more details. // -// 5. Fixes a two bugs that have been there for a long time, and -// are inevitable if you use NSPR alone: +// 5. Fixes a bug that have been there for a long time, and +// is inevitable if you use NSPR alone: // // The problem on platforms (Macintosh) in which a path does not fully -// specify a file. +// specify a file, because two volumes can have the same name. // // Not yet provided: // @@ -88,13 +88,38 @@ #define NS_USING_NAMESPACE #endif +#if !defined(NS_USING_STL) && (defined(__MWERKS__) || defined(XP_PC)) +#define NS_USING_STL +#endif + #ifdef NS_USING_NAMESPACE + #define NS_NAMESPACE_PROTOTYPE #define NS_NAMESPACE namespace #define NS_NAMESPACE_END -#define BASIC_STREAMBUF basic_streambuf -#define IOS_BASE ios_base + +#else +#define NS_NAMESPACE_PROTOTYPE static +#define NS_NAMESPACE struct +#define NS_NAMESPACE_END ; + +#endif // NS_USING_NAMESPACE + +#ifdef NS_USING_STL + +// Macintosh and Windows use this section. +// +// Here's where the party is. When Unix wants to join in (by supporting +// a build system with STL headers), what fun we'll have! Meanwhile, I've used +// macros to make this build on all our platforms. Unix doesn't have support for +// STL, and therefore we could not use the template forms of these classes on Unix. +// (it's a long story). Therefore, Unix supports no stream char types except 1-byte +// characters, and therefore nobody else does now either, until Unix catches up. + + +#define DEFINING_FILE_STREAM // templateers define this when this file is included. +#define IOS_BASE ios_base #include using std::ios_base; using std::basic_streambuf; @@ -106,18 +131,49 @@ using std::basic_ostream; using std::basic_iostream; using std::char_traits; - +#define TEMPLATE_DEF template +#define FILE_BUFFER_TYPE nsFileBufferT +#define INPUT_FILE_STREAM nsInputFileStreamT +#define OUTPUT_FILE_STREAM nsOutputFileStreamT +#define IO_FILE_STREAM nsIOFileStreamT +#define BASIC_STREAMBUF basic_streambuf +#define BASIC_ISTREAM basic_istream +#define BASIC_OSTREAM basic_ostream +#define BASIC_IOSTREAM basic_iostream +#define INT_TYPE FILE_BUFFER_TYPE::int_type +#define POS_TYPE FILE_BUFFER_TYPE::pos_type +#define OFF_TYPE FILE_BUFFER_TYPE::off_type +#define SEEK_DIR IOS_BASE::seekdir +#define EOF_VALUE traits::eof() + #else -#define NS_NAMESPACE_PROTOTYPE static -#define NS_NAMESPACE struct -#define NS_NAMESPACE_END ; -#define BASIC_STREAMBUF streambuf +// Unix uses this section until it supports STL. This means no locales, no traits, +// no wide chars, etc. Also, the stream classes are the original ARM-style ones, +// and are not templatized. + #define IOS_BASE ios - #include +#define TEMPLATE_DEF +#define FILE_BUFFER_TYPE nsFileBufferT +#define INPUT_FILE_STREAM nsInputFileStreamT +#define OUTPUT_FILE_STREAM nsOutputFileStreamT +#define IO_FILE_STREAM nsIOFileStreamT +#define BASIC_STREAMBUF streambuf +#define BASIC_ISTREAM istream +#define BASIC_OSTREAM ostream +#define BASIC_IOSTREAM iostream +#define INT_TYPE int +#define POS_TYPE long +#define OFF_TYPE long +#define SEEK_DIR ios::seek_dir +#define int_type int +#define pos_type long +#define off_type long +#define char_type char +#define EOF_VALUE EOF -#endif // NS_USING_NAMESPACE +#endif // NS_USING_STL #ifdef __MWERKS__ @@ -132,11 +188,12 @@ #else -// Fix me for thread-safety. +// Fix me, if necessary, for thread-safety. #define NS_READ_LOCK(mut) #define NS_WRITE_LOCK(mut) #endif // __MWERKS__ + //=========================== End Compiler-specific macros =============================== //======================================================================================== @@ -156,11 +213,12 @@ NS_NAMESPACE nsFileStreamHelpers //======================================================================================== //======================================================================================== -template +TEMPLATE_DEF class nsFileBufferT //======================================================================================== -: public BASIC_STREAMBUF +: public BASIC_STREAMBUF { +#ifdef NS_USING_STL typedef codecvt_base::result result; public: @@ -171,57 +229,61 @@ public: typedef traits traits_type; typedef typename traits::state_type state_type; - typedef nsFileBufferT filebuf_type; typedef codecvt ofacet_type; typedef codecvt ifacet_type; +#endif +public: nsFileBufferT(); nsFileBufferT(PRFileDesc* pfile_arg); virtual ~nsFileBufferT(); bool is_open() const; - filebuf_type* open( + FILE_BUFFER_TYPE* open( const nsFilePath& inFile, IOS_BASE::openmode mode, PRIntn accessMode); - filebuf_type* close(); + FILE_BUFFER_TYPE* close(); protected: - virtual int_type overflow(int_type c=traits::eof()); - virtual int_type pbackfail(int_type c=traits::eof()); + virtual int_type overflow(int_type c=EOF_VALUE); + virtual int_type pbackfail(int_type c=EOF_VALUE); virtual int_type underflow(); virtual pos_type seekoff( - off_type off, IOS_BASE::seekdir way, + off_type off, SEEK_DIR way, IOS_BASE::openmode which=IOS_BASE::in|IOS_BASE::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); + virtual BASIC_STREAMBUF* setbuf(char_type* s, streamsize n); virtual int sync(); virtual int_type uflow(); +#ifdef NS_USING_STL virtual void imbue(const locale& loc); +#endif virtual streamsize showmanyc(); virtual streamsize xsgetn(char_type* s, streamsize n); virtual streamsize xsputn(const char_type* s, streamsize n); private: PRFileDesc* mFileDesc; - IOS_BASE::openmode mode_; + IOS_BASE::openmode mode_; }; // class nsFileBufferT //======================================================================================== -template +TEMPLATE_DEF class nsInputFileStreamT //======================================================================================== -: public basic_istream +: public BASIC_ISTREAM { - typedef nsFileBufferT filebuf_type; - +#ifdef NS_USING_STL public: typedef charT char_type; typedef typename traits::pos_type pos_type; typedef typename traits::off_type off_type; typedef typename traits::int_type int_type; typedef traits traits_type; +#endif +public: nsInputFileStreamT(); explicit nsInputFileStreamT( const nsFilePath& inFile, @@ -230,7 +292,7 @@ public: virtual ~nsInputFileStreamT(); - filebuf_type* rdbuf() const; + FILE_BUFFER_TYPE* rdbuf() const; inline bool is_open(); inline void open( const nsFilePath& inFile, @@ -239,23 +301,25 @@ public: inline void close(); private: - filebuf_type mBuffer; + FILE_BUFFER_TYPE mBuffer; }; // class nsInputFileStreamT //======================================================================================== -template +TEMPLATE_DEF class nsOutputFileStreamT //======================================================================================== -: public basic_ostream +: public BASIC_OSTREAM { - typedef nsFileBufferT filebuf_type; - +#ifdef NS_USING_STL public: typedef charT char_type; typedef typename traits::pos_type pos_type; typedef typename traits::off_type off_type; typedef typename traits::int_type int_type; typedef traits traits_type; +#endif + +public: nsOutputFileStreamT(); explicit nsOutputFileStreamT( @@ -265,7 +329,7 @@ public: virtual ~nsOutputFileStreamT(); - filebuf_type* rdbuf() const; + FILE_BUFFER_TYPE* rdbuf() const; inline bool is_open(); inline void open( const nsFilePath& inFile, @@ -274,7 +338,7 @@ public: inline void close(); private: - filebuf_type mBuffer; + FILE_BUFFER_TYPE mBuffer; }; // class nsOutputFileStreamT //======================================================================================== @@ -282,33 +346,47 @@ private: //======================================================================================== //---------------------------------------------------------------------------------------- -template -inline nsFileBufferT::nsFileBufferT() - : BASIC_STREAMBUF(), mFileDesc(NULL) +TEMPLATE_DEF +inline FILE_BUFFER_TYPE::nsFileBufferT() + : BASIC_STREAMBUF(), mFileDesc(NULL) //---------------------------------------------------------------------------------------- { } //---------------------------------------------------------------------------------------- -template -inline nsFileBufferT::nsFileBufferT(PRFileDesc* pfarg) - : BASIC_STREAMBUF(), mFileDesc(pfarg) +TEMPLATE_DEF +inline FILE_BUFFER_TYPE::nsFileBufferT(PRFileDesc* pfarg) + : BASIC_STREAMBUF(), mFileDesc(pfarg) //---------------------------------------------------------------------------------------- { } //---------------------------------------------------------------------------------------- -template -inline nsFileBufferT::~nsFileBufferT() +TEMPLATE_DEF +inline FILE_BUFFER_TYPE* FILE_BUFFER_TYPE::close() +// Must precede the destructor because both are inline. +//---------------------------------------------------------------------------------------- +{ + if (mFileDesc==PR_STDIN || mFileDesc==PR_STDOUT || mFileDesc==PR_STDERR) + return this; + NS_WRITE_LOCK(_mutex); + return (mFileDesc && PR_Close(mFileDesc) == PR_SUCCESS) ? mFileDesc = 0, this : 0; +} + +#if defined(DEFINING_FILE_STREAM) +//---------------------------------------------------------------------------------------- +TEMPLATE_DEF +FILE_BUFFER_TYPE::~nsFileBufferT() //---------------------------------------------------------------------------------------- { close(); } +#endif // #if defined(DEFINING_FILE_STREAM) //---------------------------------------------------------------------------------------- -template +TEMPLATE_DEF inline bool -nsFileBufferT::is_open() const +FILE_BUFFER_TYPE::is_open() const //---------------------------------------------------------------------------------------- { NS_READ_LOCK(_mutex); @@ -316,8 +394,8 @@ nsFileBufferT::is_open() const } //---------------------------------------------------------------------------------------- -template -nsFileBufferT* nsFileBufferT::open( +TEMPLATE_DEF +inline FILE_BUFFER_TYPE* FILE_BUFFER_TYPE::open( const nsFilePath& inFile, IOS_BASE::openmode mode, PRIntn accessMode) @@ -331,42 +409,35 @@ nsFileBufferT* nsFileBufferT::open( return 0; mode_ = mode; return this; -} // nsFileBufferT::open +} // FILE_BUFFER_TYPE::open //---------------------------------------------------------------------------------------- -template -nsFileBufferT* nsFileBufferT::close() -//---------------------------------------------------------------------------------------- -{ - if (mFileDesc==PR_STDIN || mFileDesc==PR_STDOUT || mFileDesc==PR_STDERR) - return this; - NS_WRITE_LOCK(_mutex); - return (mFileDesc && PR_Close(mFileDesc) == PR_SUCCESS) ? mFileDesc = 0, this : 0; -} - -//---------------------------------------------------------------------------------------- -template -inline int -nsFileBufferT:: sync() +TEMPLATE_DEF +inline int FILE_BUFFER_TYPE:: sync() //---------------------------------------------------------------------------------------- { return (mFileDesc ? (int)PR_Sync(mFileDesc) : 0); } //---------------------------------------------------------------------------------------- -template -inline BASIC_STREAMBUF* -nsFileBufferT::setbuf(char_type*, streamsize) +TEMPLATE_DEF +inline BASIC_STREAMBUF* FILE_BUFFER_TYPE::setbuf(char_type*, streamsize) //---------------------------------------------------------------------------------------- { return (!mFileDesc) ? 0 : this; } +#if defined(DEFINING_FILE_STREAM) //---------------------------------------------------------------------------------------- -template -nsFileBufferT::int_type nsFileBufferT::overflow(int_type c) +TEMPLATE_DEF +INT_TYPE FILE_BUFFER_TYPE::overflow(int_type c) //---------------------------------------------------------------------------------------- { +#ifndef NS_USING_STL + char ch = c; + PRInt32 bytesWrit1 = PR_Write(mFileDesc, &ch, sizeof(ch)); + return bytesWrit1 < sizeof(ch) ? EOF_VALUE : c; +#else #ifdef NS_EXPLICIT_FUNC_TEMPLATE_ARG const ofacet_type& ft=use_facet(getloc()); #elif defined(XP_PC) @@ -376,13 +447,13 @@ nsFileBufferT::int_type nsFileBufferT::overflow(in #endif char_type ch = traits_type::to_char_type(c); if (!mFileDesc) - return traits_type::eof(); - if (traits_type::eq_int_type(c, traits::eof())) + return EOF_VALUE; + if (traits_type::eq_int_type(c, EOF_VALUE)) return traits_type::not_eof(c); if (ft.always_noconv()) { PRInt32 bytesWrit1 = PR_Write(mFileDesc, &ch, sizeof(ch)); - return bytesWrit1 < sizeof(ch) ? traits::eof() : c; + return bytesWrit1 < sizeof(ch) ? EOF_VALUE : c; } { // <- sic! state_type fst; @@ -394,36 +465,43 @@ nsFileBufferT::int_type nsFileBufferT::overflow(in codecvt_base::noconv) { PRInt32 bytesWrit2 = PR_Write(mFileDesc, &ch, sizeof(ch)); - return bytesWrit2 < sizeof(ch) ? traits::eof() : c; + return bytesWrit2 < sizeof(ch) ? EOF_VALUE : c; } if ((conv==codecvt_base::partial)||(conv==codecvt_base::error)) - return traits::eof(); + return EOF_VALUE; *ebuf=0; PRInt32 bytesWrit3 = strlen(buf); - return PR_Write(mFileDesc, buf, bytesWrit3) < bytesWrit3 ? traits_type::eof() : c; + return PR_Write(mFileDesc, buf, bytesWrit3) < bytesWrit3 ? EOF_VALUE : c; } +#endif } +#endif // #if defined(DEFINING_FILE_STREAM) //---------------------------------------------------------------------------------------- -template -inline nsFileBufferT::int_type nsFileBufferT::underflow() +TEMPLATE_DEF +inline INT_TYPE FILE_BUFFER_TYPE::underflow() //---------------------------------------------------------------------------------------- { if (!mFileDesc) - return traits_type::eof(); + return EOF_VALUE; char_type s; PRInt32 request = 1; if (1 != PR_Read(mFileDesc, &s, request)) - return traits_type::eof(); + return EOF_VALUE; PR_Seek(mFileDesc, -1, PR_SEEK_CUR); return (int_type)s; } +#if defined(DEFINING_FILE_STREAM) //---------------------------------------------------------------------------------------- -template -streamsize nsFileBufferT::xsputn(const char_type* s, streamsize n) +TEMPLATE_DEF +streamsize FILE_BUFFER_TYPE::xsputn(const char_type* s, streamsize n) //---------------------------------------------------------------------------------------- { +#ifndef NS_USING_STL + PRInt32 bytesWrit1 = PR_Write(mFileDesc, s, sizeof(char) * size_t(n)); + return bytesWrit1 < 0 ? 0 : (streamsize)bytesWrit1; +#else #ifdef NS_EXPLICIT_FUNC_TEMPLATE_ARG const ofacet_type& ft=use_facet(loc); #elif defined(XP_PC) @@ -432,98 +510,111 @@ streamsize nsFileBufferT::xsputn(const char_type* s, streamsize n const ofacet_type& ft=use_facet(getloc(), (ofacet_type*)0); #endif if (!mFileDesc || !n) - return 0; + return 0; if (ft.always_noconv()) { - PRInt32 bytesWrit1 = PR_Write(mFileDesc, s, sizeof(char) * size_t(n)); - return bytesWrit1 < 0 ? 0 : (streamsize)bytesWrit1; + PRInt32 bytesWrit1 = PR_Write(mFileDesc, s, sizeof(char) * size_t(n)); + return bytesWrit1 < 0 ? 0 : (streamsize)bytesWrit1; } { // <- sic! - state_type fst; - const char_type* end; - char buf[8]; - char* ebuf; - result conv; + state_type fst; + const char_type* end; + char buf[8]; + char* ebuf; + result conv; #ifdef NS_EXPLICIT_FUNC_TEMPLATE_ARG - if ((conv=use_facet(getloc()). + if ((conv=use_facet(getloc()). #elif defined(XP_PC) - if ((conv=use_facet(getloc(), (ofacet_type*)0, false). + if ((conv=use_facet(getloc(), (ofacet_type*)0, false). #else - if ((conv=use_facet(getloc(), (ofacet_type*)0). + if ((conv=use_facet(getloc(), (ofacet_type*)0). #endif - out(fst, s, s+n, end, buf, buf+7, ebuf))==codecvt_base::noconv) - return (streamsize)PR_Write(mFileDesc, s, sizeof(char) * size_t(n)); - if ((conv==codecvt_base::partial) ||(conv==codecvt_base::error)) - return 0; - *ebuf=0; - PRInt32 bytesWrit2 = strlen(buf); - bytesWrit2 = PR_Write(mFileDesc, buf, bytesWrit2); - return bytesWrit2 < 0 ? 0 : streamsize(bytesWrit2 / sizeof(char_type)); + out(fst, s, s+n, end, buf, buf+7, ebuf))==codecvt_base::noconv) + return (streamsize)PR_Write(mFileDesc, s, sizeof(char) * size_t(n)); + if ((conv==codecvt_base::partial) ||(conv==codecvt_base::error)) + return 0; + *ebuf=0; + PRInt32 bytesWrit2 = strlen(buf); + bytesWrit2 = PR_Write(mFileDesc, buf, bytesWrit2); + return bytesWrit2 < 0 ? 0 : streamsize(bytesWrit2 / sizeof(char_type)); } -} +#endif +} // FILE_BUFFER_TYPE::xsputn +#endif // #if defined(DEFINING_FILE_STREAM) //---------------------------------------------------------------------------------------- -template -inline nsFileBufferT::int_type - nsFileBufferT::pbackfail(int_type c) +TEMPLATE_DEF +inline INT_TYPE FILE_BUFFER_TYPE::pbackfail(int_type c) //---------------------------------------------------------------------------------------- { if (!mFileDesc) - return traits_type::eof(); + return EOF_VALUE; if (PR_Seek(mFileDesc, -1, PR_SEEK_CUR) < 0) - return traits_type::eof(); - return (traits::eq_int_type(c, traits_type::eof())) ? traits::not_eof(c) : c; + return EOF_VALUE; + #ifdef NS_USING_STL + return (traits::eq_int_type(c, EOF_VALUE)) ? traits::not_eof(c) : c; + #else + return c; + #endif } //---------------------------------------------------------------------------------------- -template -inline nsFileBufferT::int_type nsFileBufferT::uflow() +TEMPLATE_DEF +inline INT_TYPE FILE_BUFFER_TYPE::uflow() //---------------------------------------------------------------------------------------- { if (!mFileDesc) - return traits_type::eof(); + return EOF_VALUE; char_type s; if (1 != PR_Read(mFileDesc, &s, 1)) // attempt to read 1 byte, confirm 1 byte - return traits_type::eof(); + return EOF_VALUE; return (int_type)s; } //---------------------------------------------------------------------------------------- -template -inline streamsize nsFileBufferT::xsgetn(char_type* s, streamsize n) +TEMPLATE_DEF +inline streamsize FILE_BUFFER_TYPE::xsgetn(char_type* s, streamsize n) //---------------------------------------------------------------------------------------- { return mFileDesc ? (streamsize)PR_Read(mFileDesc, s, sizeof(char) * size_t(n)) : 0; } +#ifdef NS_USING_STL //---------------------------------------------------------------------------------------- -template -inline void nsFileBufferT::imbue(const locale& loc_arg) +TEMPLATE_DEF +inline void FILE_BUFFER_TYPE::imbue(const locale& loc_arg) //---------------------------------------------------------------------------------------- { #ifdef XP_MAC loc = loc_arg; #endif } +#endif //---------------------------------------------------------------------------------------- -template -inline streamsize -nsFileBufferT::showmanyc() +TEMPLATE_DEF +inline streamsize FILE_BUFFER_TYPE::showmanyc() //---------------------------------------------------------------------------------------- { return (streamsize)PR_Available(mFileDesc); } +#if defined(DEFINING_FILE_STREAM) //---------------------------------------------------------------------------------------- -template -nsFileBufferT::pos_type nsFileBufferT::seekoff( - off_type off, - IOS_BASE::seekdir way, +TEMPLATE_DEF +POS_TYPE FILE_BUFFER_TYPE::seekoff( + OFF_TYPE off, + SEEK_DIR way, IOS_BASE::openmode /* which */) //---------------------------------------------------------------------------------------- { - if (!mFileDesc || ((way&IOS_BASE::beg) && off<0) || ((way&IOS_BASE::end) && off > 0)) + if (!mFileDesc || +#ifdef NS_USING_STL + ((way&IOS_BASE::beg) && off<0) || ((way&IOS_BASE::end) && off > 0) +#else + ((way == IOS_BASE::beg) && off<0) || ((way == IOS_BASE::end) && off > 0) +#endif + ) return pos_type(-1); PRSeekWhence poseek = PR_SEEK_CUR; switch (way) @@ -538,16 +629,17 @@ nsFileBufferT::pos_type nsFileBufferT::seekoff( return pos_type(-1); return pos_type(position); } +#endif // #if defined(DEFINING_FILE_STREAM) +#if defined(DEFINING_FILE_STREAM) //---------------------------------------------------------------------------------------- -template -nsFileBufferT::pos_type -nsFileBufferT::seekpos(pos_type sp, IOS_BASE::openmode) +TEMPLATE_DEF +POS_TYPE FILE_BUFFER_TYPE::seekpos(pos_type sp, IOS_BASE::openmode) //---------------------------------------------------------------------------------------- { if (!mFileDesc || sp==pos_type(-1)) return -1; -#if defined(XP_PC) +#if defined(XP_PC) || defined(XP_UNIX) PRInt32 position = sp; #else PRInt32 position = sp.offset(); @@ -557,63 +649,63 @@ nsFileBufferT::seekpos(pos_type sp, IOS_BASE::openmode) return pos_type(-1); return position; } +#endif // #if defined(DEFINING_FILE_STREAM) //======================================================================================== // Implementation of nsInputFileStreamT //======================================================================================== //---------------------------------------------------------------------------------------- -template -inline nsInputFileStreamT::nsInputFileStreamT() - : basic_istream(&mBuffer) +TEMPLATE_DEF +inline INPUT_FILE_STREAM::nsInputFileStreamT() + : BASIC_ISTREAM(&mBuffer) //---------------------------------------------------------------------------------------- { // already inited } //---------------------------------------------------------------------------------------- -template -inline nsInputFileStreamT::nsInputFileStreamT( +TEMPLATE_DEF +inline INPUT_FILE_STREAM::nsInputFileStreamT( const nsFilePath& inFile, IOS_BASE::openmode mode, PRIntn accessMode) //---------------------------------------------------------------------------------------- - : basic_istream(&mBuffer) + : BASIC_ISTREAM(&mBuffer) { // already inited if (!mBuffer.open(inFile, openmode(mode|in), accessMode)) setstate(failbit); } +#if defined(DEFINING_FILE_STREAM) //---------------------------------------------------------------------------------------- -template -inline nsInputFileStreamT::~nsInputFileStreamT() +TEMPLATE_DEF +INPUT_FILE_STREAM::~nsInputFileStreamT() //---------------------------------------------------------------------------------------- { } +#endif // #if defined(DEFINING_FILE_STREAM) //---------------------------------------------------------------------------------------- -template -inline nsFileBufferT* -nsInputFileStreamT::rdbuf() const +TEMPLATE_DEF +inline FILE_BUFFER_TYPE* INPUT_FILE_STREAM::rdbuf() const //---------------------------------------------------------------------------------------- { - return (nsFileBufferT*)&mBuffer; + return (FILE_BUFFER_TYPE*)&mBuffer; } //---------------------------------------------------------------------------------------- -template -inline bool -nsInputFileStreamT:: is_open() +TEMPLATE_DEF +inline bool INPUT_FILE_STREAM:: is_open() //---------------------------------------------------------------------------------------- { return mBuffer.is_open(); } //---------------------------------------------------------------------------------------- -template -inline void -nsInputFileStreamT::open( +TEMPLATE_DEF +inline void INPUT_FILE_STREAM::open( const nsFilePath& inFile, IOS_BASE::openmode mode, PRIntn accessMode) @@ -624,8 +716,8 @@ nsInputFileStreamT::open( } //---------------------------------------------------------------------------------------- -template -inline void nsInputFileStreamT::close() +TEMPLATE_DEF +inline void INPUT_FILE_STREAM::close() //---------------------------------------------------------------------------------------- { if (!mBuffer.close()) @@ -637,55 +729,59 @@ inline void nsInputFileStreamT::close() //======================================================================================== //---------------------------------------------------------------------------------------- -template -inline nsOutputFileStreamT::nsOutputFileStreamT() - : basic_ostream(&mBuffer) +TEMPLATE_DEF +inline OUTPUT_FILE_STREAM::nsOutputFileStreamT() + : BASIC_OSTREAM(&mBuffer) //---------------------------------------------------------------------------------------- { // already inited } +#if defined(DEFINING_FILE_STREAM) //---------------------------------------------------------------------------------------- -template -nsOutputFileStreamT::nsOutputFileStreamT( +TEMPLATE_DEF +OUTPUT_FILE_STREAM::nsOutputFileStreamT( const nsFilePath& inFile, IOS_BASE::openmode mode, PRIntn accessMode) //---------------------------------------------------------------------------------------- -: basic_ostream(&mBuffer) +: BASIC_OSTREAM(&mBuffer) { // already inited if (!mBuffer.open(inFile, openmode(mode|out), accessMode)) setstate(failbit); } +#endif // #if defined(DEFINING_FILE_STREAM) +#if defined(DEFINING_FILE_STREAM) //---------------------------------------------------------------------------------------- -template -inline nsOutputFileStreamT::~nsOutputFileStreamT() +TEMPLATE_DEF +inline OUTPUT_FILE_STREAM::~nsOutputFileStreamT() //---------------------------------------------------------------------------------------- { } +#endif // #if defined(DEFINING_FILE_STREAM) //---------------------------------------------------------------------------------------- -template -inline nsFileBufferT* -nsOutputFileStreamT::rdbuf() const +TEMPLATE_DEF +inline FILE_BUFFER_TYPE* +OUTPUT_FILE_STREAM::rdbuf() const //---------------------------------------------------------------------------------------- { - return (nsFileBufferT*)&mBuffer; + return (FILE_BUFFER_TYPE*)&mBuffer; } //---------------------------------------------------------------------------------------- -template -inline bool nsOutputFileStreamT:: is_open() +TEMPLATE_DEF +inline bool OUTPUT_FILE_STREAM:: is_open() //---------------------------------------------------------------------------------------- { return mBuffer.is_open(); } //---------------------------------------------------------------------------------------- -template -inline void nsOutputFileStreamT::open( +TEMPLATE_DEF +inline void OUTPUT_FILE_STREAM::open( const nsFilePath& inFile, IOS_BASE::openmode mode, PRIntn accessMode) @@ -696,8 +792,8 @@ inline void nsOutputFileStreamT::open( } //---------------------------------------------------------------------------------------- -template -inline void nsOutputFileStreamT:: close() +TEMPLATE_DEF +inline void OUTPUT_FILE_STREAM:: close() //---------------------------------------------------------------------------------------- { if (!mBuffer.close()) @@ -705,19 +801,20 @@ inline void nsOutputFileStreamT:: close() } //======================================================================================== -template -class nsIOFileStreamT : public basic_iostream +TEMPLATE_DEF +class nsIOFileStreamT : public BASIC_IOSTREAM //======================================================================================== { - typedef nsFileBufferT filebuf_type; - +#ifdef NS_USING_STL public: typedef charT char_type; typedef typename traits::pos_type pos_type; typedef typename traits::off_type off_type; typedef typename traits::int_type int_type; typedef traits traits_type; +#endif +public: nsIOFileStreamT(); explicit nsIOFileStreamT( const nsFilePath& inFile, @@ -726,7 +823,7 @@ public: virtual ~nsIOFileStreamT(); - filebuf_type* rdbuf() const; + FILE_BUFFER_TYPE* rdbuf() const; inline bool is_open(); inline void open( const nsFilePath& inFile, @@ -735,7 +832,7 @@ public: inline void close(); private: - filebuf_type mBuffer; + FILE_BUFFER_TYPE mBuffer; }; // class nsIOFileStreamT //======================================================================================== @@ -743,55 +840,55 @@ private: //======================================================================================== //---------------------------------------------------------------------------------------- -template -inline nsIOFileStreamT::nsIOFileStreamT() +TEMPLATE_DEF +inline IO_FILE_STREAM::nsIOFileStreamT() //---------------------------------------------------------------------------------------- - : mBuffer(), basic_iostream(&mBuffer) + : mBuffer(), BASIC_IOSTREAM(&mBuffer) { // already inited } //---------------------------------------------------------------------------------------- -template -inline nsIOFileStreamT::nsIOFileStreamT( +TEMPLATE_DEF +inline IO_FILE_STREAM::nsIOFileStreamT( const nsFilePath& inFile, IOS_BASE::openmode mode, PRIntn accessMode) //---------------------------------------------------------------------------------------- - : mBuffer(), basic_iostream(&mBuffer) + : mBuffer(), BASIC_IOSTREAM(&mBuffer) { // already inited if (!mBuffer.open(inFile, mode, accessMode)) setstate(failbit); } -template -inline nsIOFileStreamT::~nsIOFileStreamT() +//---------------------------------------------------------------------------------------- +TEMPLATE_DEF +inline IO_FILE_STREAM::~nsIOFileStreamT() +//---------------------------------------------------------------------------------------- { } //---------------------------------------------------------------------------------------- -template -inline nsFileBufferT* -nsIOFileStreamT::rdbuf() const +TEMPLATE_DEF +inline FILE_BUFFER_TYPE* +IO_FILE_STREAM::rdbuf() const //---------------------------------------------------------------------------------------- { - return (nsFileBufferT*)&mBuffer; + return (FILE_BUFFER_TYPE*)&mBuffer; } //---------------------------------------------------------------------------------------- -template -inline bool -nsIOFileStreamT::is_open() +TEMPLATE_DEF +inline bool IO_FILE_STREAM::is_open() //---------------------------------------------------------------------------------------- { return mBuffer.is_open(); } //---------------------------------------------------------------------------------------- -template -inline void -nsIOFileStreamT::open( +TEMPLATE_DEF +inline void IO_FILE_STREAM::open( const nsFilePath& inFile, IOS_BASE::openmode mode, PRIntn accessMode) @@ -802,9 +899,8 @@ nsIOFileStreamT::open( } //---------------------------------------------------------------------------------------- -template -inline void -nsIOFileStreamT::close() +TEMPLATE_DEF +inline void IO_FILE_STREAM::close() //---------------------------------------------------------------------------------------- { if (!mBuffer.close()) @@ -815,6 +911,7 @@ nsIOFileStreamT::close() // Specializations of the stream templates //======================================================================================== +#ifdef NS_USING_STL typedef nsFileBufferT > nsFileBuffer; typedef nsInputFileStreamT > nsInputFileStream; typedef nsOutputFileStreamT > nsOutputFileStream; @@ -827,5 +924,14 @@ typedef nsOutputFileStreamT > nsWideOutputFileStre typedef nsIOFileStreamT > nsWideIOFileStream; #endif // NS_USING_WIDE_CHAR +#else + +typedef nsFileBufferT nsFileBuffer; +typedef nsInputFileStreamT nsInputFileStream; +typedef nsOutputFileStreamT nsOutputFileStream; +typedef nsIOFileStreamT nsIOFileStream; + +#endif + #endif /* _FILESTREAM_H_ */ diff --git a/mozilla/xpcom/tests/FilesTest.cpp b/mozilla/xpcom/tests/FilesTest.cpp index 17271fe7b8b..396bec6f47e 100644 --- a/mozilla/xpcom/tests/FilesTest.cpp +++ b/mozilla/xpcom/tests/FilesTest.cpp @@ -1,7 +1,7 @@ #include "nsFileSpec.h" #include "nsFileStream.h" -#ifdef NS_USING_NAMESPACE +#ifdef NS_USING_STL #include using namespace std; #else @@ -10,7 +10,7 @@ NS_NAMESPACE FileTest { - void WriteStuff(ostream& s); + NS_NAMESPACE_PROTOTYPE void WriteStuff(ostream& s); } NS_NAMESPACE_END //---------------------------------------------------------------------------------------- @@ -56,9 +56,6 @@ void main() //---------------------------------------------------------------------------------------- { -#if !defined(DEBUG) || (DEBUG==0) -#error "This test only works with a DEBUG build." -#endif // Test of nsFileSpec cout << "WRITING TEST OUTPUT TO cout" << endl << endl;