Backing out previous change from the trunk, because it was supposed to have gone in on a branch.

This commit is contained in:
mcmullen%netscape.com 1999-02-18 00:45:07 +00:00
parent 37d7aee1e4
commit 0064c92613
4 changed files with 80 additions and 78 deletions

View File

@ -41,13 +41,13 @@
//
// Basic example:
//
// nsFileSpec myPath("/Development/iotest.txt");
// nsFilePath myPath("/Development/iotest.txt");
//
// nsOutputFileStream testStream(myPath);
// testStream << "Hello World" << nsEndl;
//
// 4. Requires streams to be constructed using typesafe nsFileSpec specifier
// (not the notorious and bug prone const char*), namely nsFileSpec. See
// 4. Requires streams to be constructed using typesafe nsFilePath specifier
// (not the notorious and bug prone const char*), namely nsFilePath. See
// nsFileSpec.h for more details.
//
// 5. Fixes a bug that have been there for a long time, and
@ -140,7 +140,7 @@ public:
nsBasicFileStream();
nsBasicFileStream(PRFileDesc* desc, int nsprMode);
nsBasicFileStream(
const nsFileSpec& inFile,
const nsFilePath& inFile,
int nsprMode,
PRIntn accessMode);
virtual ~nsBasicFileStream();
@ -148,14 +148,14 @@ public:
inline PRBool is_open() const { return mFileDesc != 0; }
void open(
const nsFileSpec& inFile,
const nsFilePath& inFile,
int nsprMode,
PRIntn accessMode);
void close();
PRIntn tell() const;
void seek(PRInt32 offset) { seek(PR_SEEK_SET, offset); }
void seek(PRSeekWhence whence, PRInt32 offset);
PRBool eof() const { return mEOF; }
PRBool eof() const { return mEOF; }
PRBool failed() const { return mFailed; }
// call PR_GetError() for details
protected:
@ -249,7 +249,7 @@ public:
enum { kDefaultMode = PR_RDONLY };
nsInputFileStream(istream* stream = CONSOLE_IN);
nsInputFileStream(
const nsFileSpec& inFile,
const nsFilePath& inFile,
int nsprMode = kDefaultMode,
PRIntn accessMode = 00700) // <- OCTAL
: nsBasicFileStream(inFile, nsprMode, accessMode)
@ -257,7 +257,7 @@ public:
{}
void open(
const nsFileSpec& inFile,
const nsFilePath& inFile,
int nsprMode = kDefaultMode,
PRIntn accessMode = 00700) // <- OCTAL
{
@ -280,7 +280,7 @@ public:
nsOutputFileStream(ostream* stream = CONSOLE_OUT);
nsOutputFileStream(
const nsFileSpec& inFile,
const nsFilePath& inFile,
int nsprMode = kDefaultMode,
PRIntn accessMode = 00700) // <- OCTAL
: nsBasicFileStream(inFile, nsprMode, accessMode)
@ -288,7 +288,7 @@ public:
{}
inline void open(
const nsFileSpec& inFile,
const nsFilePath& inFile,
int nsprMode = kDefaultMode,
PRIntn accessMode = 00700) // <- OCTAL
{
@ -307,7 +307,7 @@ public:
enum { kDefaultMode = (PR_RDWR | PR_CREATE_FILE) };
nsIOFileStream(
const nsFileSpec& inFile,
const nsFilePath& inFile,
int nsprMode = kDefaultMode,
PRIntn accessMode = 00700) // <- OCTAL
: nsBasicFileStream(inFile, nsprMode, accessMode)
@ -316,7 +316,7 @@ public:
{}
inline void open(
const nsFileSpec& inFile,
const nsFilePath& inFile,
int nsprMode = kDefaultMode,
PRIntn accessMode = 00700) // <- OCTAL
{

View File

@ -38,21 +38,21 @@ nsBasicFileStream::nsBasicFileStream()
//----------------------------------------------------------------------------------------
: mFileDesc(0)
, mNSPRMode(0)
, mFailed(PR_FALSE)
, mEOF(PR_FALSE)
, mFailed(false)
, mEOF(false)
{
}
//----------------------------------------------------------------------------------------
nsBasicFileStream::nsBasicFileStream(
const nsFileSpec& inFile,
const nsFilePath& inFile,
int nsprMode,
PRIntn accessMode)
//----------------------------------------------------------------------------------------
: mFileDesc(0)
, mNSPRMode(0)
, mFailed(PR_FALSE)
, mEOF(PR_FALSE)
, mFailed(false)
, mEOF(false)
{
open(inFile, nsprMode, accessMode);
}
@ -62,8 +62,8 @@ nsBasicFileStream::nsBasicFileStream(PRFileDesc* desc, int nsprMode)
//----------------------------------------------------------------------------------------
: mFileDesc(desc)
, mNSPRMode(nsprMode)
, mFailed(PR_FALSE)
, mEOF(PR_FALSE)
, mFailed(false)
, mEOF(false)
{
}
@ -76,7 +76,7 @@ nsBasicFileStream::~nsBasicFileStream()
//----------------------------------------------------------------------------------------
void nsBasicFileStream::open(
const nsFileSpec& inFile,
const nsFilePath& inFile,
int nsprMode,
PRIntn accessMode)
//----------------------------------------------------------------------------------------
@ -110,7 +110,7 @@ void nsBasicFileStream::open(
// several files on the Macintosh (you can have several volumes with the
// same name, see).
mFileDesc = 0;
if (inFile.Error() != noErr)
if (inFile.GetNativeSpec().Error() != noErr)
return;
OSErr err = noErr;
#if DEBUG
@ -118,9 +118,10 @@ void nsBasicFileStream::open(
#else
const OSType kCreator = 'MOSS';
#endif
const FSSpec& spec = inFile.operator const FSSpec&();
nsNativeFileSpec nativeSpec = inFile.GetNativeSpec();
FSSpec* spec = (FSSpec*)nativeSpec;
if (nsprMode & PR_CREATE_FILE)
err = FSpCreate(&spec, kCreator, 'TEXT', 0);
err = FSpCreate(spec, kCreator, 'TEXT', 0);
if (err == dupFNErr)
err = noErr;
if (err != noErr)
@ -135,7 +136,7 @@ void nsBasicFileStream::open(
perm = fsRdPerm;
short refnum;
err = FSpOpenDF(&spec, perm, &refnum);
err = FSpOpenDF(spec, perm, &refnum);
if (err == noErr && (nsprMode & PR_TRUNCATE))
err = SetEOF(refnum, 0);
@ -150,7 +151,7 @@ void nsBasicFileStream::open(
// Platforms other than Macintosh...
// Another bug in NSPR: Mac PR_Open assumes a unix style path, but Win PR_Open assumes
// a windows path.
if ((mFileDesc = PR_Open((const char*)nsFileSpec(inFile), nsprMode, accessMode)) == 0)
if ((mFileDesc = PR_Open((const char*)nsNativeFileSpec(inFile), nsprMode, accessMode)) == 0)
return;
#endif
mNSPRMode = nsprMode;
@ -174,8 +175,8 @@ void nsBasicFileStream::seek(PRSeekWhence whence, PRInt32 offset)
{
if (mFileDesc==PR_STDIN || mFileDesc==PR_STDOUT || mFileDesc==PR_STDERR || mFileDesc == 0)
return;
mFailed = PR_FALSE; // reset on a seek.
mEOF = PR_FALSE; // reset on a seek.
mFailed = false; // reset on a seek.
mEOF = false; // reset on a seek.
PRInt32 position = PR_Seek(mFileDesc, 0, PR_SEEK_CUR);
PRInt32 available = PR_Available(mFileDesc);
PRInt32 fileSize = position + available;
@ -189,15 +190,15 @@ void nsBasicFileStream::seek(PRSeekWhence whence, PRInt32 offset)
if (newPosition < 0)
{
newPosition = 0;
mFailed = PR_TRUE;
mFailed = true;
}
else if (newPosition >= fileSize)
{
newPosition = fileSize;
mEOF = PR_TRUE;
mEOF = true;
}
if (PR_Seek(mFileDesc, newPosition, PR_SEEK_SET) < 0)
mFailed = PR_TRUE;
mFailed = true;
} // nsBasicFileStream::seek
//----------------------------------------------------------------------------------------
@ -233,15 +234,15 @@ PRBool nsBasicInStream::readline(char* s, PRInt32 n)
// This will truncate if the buffer is too small. Result will always be null-terminated.
//----------------------------------------------------------------------------------------
{
PRBool bufferLargeEnough = PR_TRUE; // result
PRBool bufferLargeEnough = true; // result
if (!s || !n)
return PR_TRUE;
return true;
PRIntn position = mBase.tell();
if (position < 0)
return PR_FALSE;
return false;
PRInt32 bytesRead = read(s, n - 1);
if (mBase.failed())
return PR_FALSE;
return false;
s[bytesRead] = '\0'; // always terminate at the end of the buffer
char* tp = strpbrk(s, "\n\r");
if (tp)
@ -253,7 +254,7 @@ PRBool nsBasicInStream::readline(char* s, PRInt32 n)
bytesRead = (tp - s);
}
else if (!mBase.eof())
bufferLargeEnough = PR_FALSE;
bufferLargeEnough = false;
position += bytesRead;
mBase.seek(position);
return bufferLargeEnough;
@ -275,9 +276,9 @@ PRInt32 nsBasicInStream::read(void* s, PRInt32 n)
return -1;
PRInt32 bytesRead = PR_Read(mBase.GetFileDescriptor(), s, n);
if (bytesRead < 0)
mBase.mFailed = PR_TRUE;
mBase.mFailed = true;
else if (bytesRead < n)
mBase.mEOF = PR_TRUE;
mBase.mEOF = true;
return bytesRead;
}
@ -341,7 +342,7 @@ PRInt32 nsBasicOutStream::write(const void* s, PRInt32 n)
return -1;
PRInt32 bytesWrit = PR_Write(mBase.mFileDesc, s, n);
if (bytesWrit != n)
mBase.mFailed = PR_TRUE;
mBase.mFailed = true;
return bytesWrit;
}
@ -415,7 +416,7 @@ void nsBasicOutStream::flush()
#ifdef XP_MAC
// On unix, it seems to fail always.
if (itFailed)
mBase.mFailed = PR_TRUE;
mBase.mFailed = true;
#endif
} // nsBasicOutStream::flush

View File

@ -38,21 +38,21 @@ nsBasicFileStream::nsBasicFileStream()
//----------------------------------------------------------------------------------------
: mFileDesc(0)
, mNSPRMode(0)
, mFailed(PR_FALSE)
, mEOF(PR_FALSE)
, mFailed(false)
, mEOF(false)
{
}
//----------------------------------------------------------------------------------------
nsBasicFileStream::nsBasicFileStream(
const nsFileSpec& inFile,
const nsFilePath& inFile,
int nsprMode,
PRIntn accessMode)
//----------------------------------------------------------------------------------------
: mFileDesc(0)
, mNSPRMode(0)
, mFailed(PR_FALSE)
, mEOF(PR_FALSE)
, mFailed(false)
, mEOF(false)
{
open(inFile, nsprMode, accessMode);
}
@ -62,8 +62,8 @@ nsBasicFileStream::nsBasicFileStream(PRFileDesc* desc, int nsprMode)
//----------------------------------------------------------------------------------------
: mFileDesc(desc)
, mNSPRMode(nsprMode)
, mFailed(PR_FALSE)
, mEOF(PR_FALSE)
, mFailed(false)
, mEOF(false)
{
}
@ -76,7 +76,7 @@ nsBasicFileStream::~nsBasicFileStream()
//----------------------------------------------------------------------------------------
void nsBasicFileStream::open(
const nsFileSpec& inFile,
const nsFilePath& inFile,
int nsprMode,
PRIntn accessMode)
//----------------------------------------------------------------------------------------
@ -110,7 +110,7 @@ void nsBasicFileStream::open(
// several files on the Macintosh (you can have several volumes with the
// same name, see).
mFileDesc = 0;
if (inFile.Error() != noErr)
if (inFile.GetNativeSpec().Error() != noErr)
return;
OSErr err = noErr;
#if DEBUG
@ -118,9 +118,10 @@ void nsBasicFileStream::open(
#else
const OSType kCreator = 'MOSS';
#endif
const FSSpec& spec = inFile.operator const FSSpec&();
nsNativeFileSpec nativeSpec = inFile.GetNativeSpec();
FSSpec* spec = (FSSpec*)nativeSpec;
if (nsprMode & PR_CREATE_FILE)
err = FSpCreate(&spec, kCreator, 'TEXT', 0);
err = FSpCreate(spec, kCreator, 'TEXT', 0);
if (err == dupFNErr)
err = noErr;
if (err != noErr)
@ -135,7 +136,7 @@ void nsBasicFileStream::open(
perm = fsRdPerm;
short refnum;
err = FSpOpenDF(&spec, perm, &refnum);
err = FSpOpenDF(spec, perm, &refnum);
if (err == noErr && (nsprMode & PR_TRUNCATE))
err = SetEOF(refnum, 0);
@ -150,7 +151,7 @@ void nsBasicFileStream::open(
// Platforms other than Macintosh...
// Another bug in NSPR: Mac PR_Open assumes a unix style path, but Win PR_Open assumes
// a windows path.
if ((mFileDesc = PR_Open((const char*)nsFileSpec(inFile), nsprMode, accessMode)) == 0)
if ((mFileDesc = PR_Open((const char*)nsNativeFileSpec(inFile), nsprMode, accessMode)) == 0)
return;
#endif
mNSPRMode = nsprMode;
@ -174,8 +175,8 @@ void nsBasicFileStream::seek(PRSeekWhence whence, PRInt32 offset)
{
if (mFileDesc==PR_STDIN || mFileDesc==PR_STDOUT || mFileDesc==PR_STDERR || mFileDesc == 0)
return;
mFailed = PR_FALSE; // reset on a seek.
mEOF = PR_FALSE; // reset on a seek.
mFailed = false; // reset on a seek.
mEOF = false; // reset on a seek.
PRInt32 position = PR_Seek(mFileDesc, 0, PR_SEEK_CUR);
PRInt32 available = PR_Available(mFileDesc);
PRInt32 fileSize = position + available;
@ -189,15 +190,15 @@ void nsBasicFileStream::seek(PRSeekWhence whence, PRInt32 offset)
if (newPosition < 0)
{
newPosition = 0;
mFailed = PR_TRUE;
mFailed = true;
}
else if (newPosition >= fileSize)
{
newPosition = fileSize;
mEOF = PR_TRUE;
mEOF = true;
}
if (PR_Seek(mFileDesc, newPosition, PR_SEEK_SET) < 0)
mFailed = PR_TRUE;
mFailed = true;
} // nsBasicFileStream::seek
//----------------------------------------------------------------------------------------
@ -233,15 +234,15 @@ PRBool nsBasicInStream::readline(char* s, PRInt32 n)
// This will truncate if the buffer is too small. Result will always be null-terminated.
//----------------------------------------------------------------------------------------
{
PRBool bufferLargeEnough = PR_TRUE; // result
PRBool bufferLargeEnough = true; // result
if (!s || !n)
return PR_TRUE;
return true;
PRIntn position = mBase.tell();
if (position < 0)
return PR_FALSE;
return false;
PRInt32 bytesRead = read(s, n - 1);
if (mBase.failed())
return PR_FALSE;
return false;
s[bytesRead] = '\0'; // always terminate at the end of the buffer
char* tp = strpbrk(s, "\n\r");
if (tp)
@ -253,7 +254,7 @@ PRBool nsBasicInStream::readline(char* s, PRInt32 n)
bytesRead = (tp - s);
}
else if (!mBase.eof())
bufferLargeEnough = PR_FALSE;
bufferLargeEnough = false;
position += bytesRead;
mBase.seek(position);
return bufferLargeEnough;
@ -275,9 +276,9 @@ PRInt32 nsBasicInStream::read(void* s, PRInt32 n)
return -1;
PRInt32 bytesRead = PR_Read(mBase.GetFileDescriptor(), s, n);
if (bytesRead < 0)
mBase.mFailed = PR_TRUE;
mBase.mFailed = true;
else if (bytesRead < n)
mBase.mEOF = PR_TRUE;
mBase.mEOF = true;
return bytesRead;
}
@ -341,7 +342,7 @@ PRInt32 nsBasicOutStream::write(const void* s, PRInt32 n)
return -1;
PRInt32 bytesWrit = PR_Write(mBase.mFileDesc, s, n);
if (bytesWrit != n)
mBase.mFailed = PR_TRUE;
mBase.mFailed = true;
return bytesWrit;
}
@ -415,7 +416,7 @@ void nsBasicOutStream::flush()
#ifdef XP_MAC
// On unix, it seems to fail always.
if (itFailed)
mBase.mFailed = PR_TRUE;
mBase.mFailed = true;
#endif
} // nsBasicOutStream::flush

View File

@ -41,13 +41,13 @@
//
// Basic example:
//
// nsFileSpec myPath("/Development/iotest.txt");
// nsFilePath myPath("/Development/iotest.txt");
//
// nsOutputFileStream testStream(myPath);
// testStream << "Hello World" << nsEndl;
//
// 4. Requires streams to be constructed using typesafe nsFileSpec specifier
// (not the notorious and bug prone const char*), namely nsFileSpec. See
// 4. Requires streams to be constructed using typesafe nsFilePath specifier
// (not the notorious and bug prone const char*), namely nsFilePath. See
// nsFileSpec.h for more details.
//
// 5. Fixes a bug that have been there for a long time, and
@ -140,7 +140,7 @@ public:
nsBasicFileStream();
nsBasicFileStream(PRFileDesc* desc, int nsprMode);
nsBasicFileStream(
const nsFileSpec& inFile,
const nsFilePath& inFile,
int nsprMode,
PRIntn accessMode);
virtual ~nsBasicFileStream();
@ -148,14 +148,14 @@ public:
inline PRBool is_open() const { return mFileDesc != 0; }
void open(
const nsFileSpec& inFile,
const nsFilePath& inFile,
int nsprMode,
PRIntn accessMode);
void close();
PRIntn tell() const;
void seek(PRInt32 offset) { seek(PR_SEEK_SET, offset); }
void seek(PRSeekWhence whence, PRInt32 offset);
PRBool eof() const { return mEOF; }
PRBool eof() const { return mEOF; }
PRBool failed() const { return mFailed; }
// call PR_GetError() for details
protected:
@ -249,7 +249,7 @@ public:
enum { kDefaultMode = PR_RDONLY };
nsInputFileStream(istream* stream = CONSOLE_IN);
nsInputFileStream(
const nsFileSpec& inFile,
const nsFilePath& inFile,
int nsprMode = kDefaultMode,
PRIntn accessMode = 00700) // <- OCTAL
: nsBasicFileStream(inFile, nsprMode, accessMode)
@ -257,7 +257,7 @@ public:
{}
void open(
const nsFileSpec& inFile,
const nsFilePath& inFile,
int nsprMode = kDefaultMode,
PRIntn accessMode = 00700) // <- OCTAL
{
@ -280,7 +280,7 @@ public:
nsOutputFileStream(ostream* stream = CONSOLE_OUT);
nsOutputFileStream(
const nsFileSpec& inFile,
const nsFilePath& inFile,
int nsprMode = kDefaultMode,
PRIntn accessMode = 00700) // <- OCTAL
: nsBasicFileStream(inFile, nsprMode, accessMode)
@ -288,7 +288,7 @@ public:
{}
inline void open(
const nsFileSpec& inFile,
const nsFilePath& inFile,
int nsprMode = kDefaultMode,
PRIntn accessMode = 00700) // <- OCTAL
{
@ -307,7 +307,7 @@ public:
enum { kDefaultMode = (PR_RDWR | PR_CREATE_FILE) };
nsIOFileStream(
const nsFileSpec& inFile,
const nsFilePath& inFile,
int nsprMode = kDefaultMode,
PRIntn accessMode = 00700) // <- OCTAL
: nsBasicFileStream(inFile, nsprMode, accessMode)
@ -316,7 +316,7 @@ public:
{}
inline void open(
const nsFileSpec& inFile,
const nsFilePath& inFile,
int nsprMode = kDefaultMode,
PRIntn accessMode = 00700) // <- OCTAL
{