Backing out 58668 until we can figure out Mac problem.

This commit is contained in:
mkaply%us.ibm.com 2001-02-05 20:11:07 +00:00
Родитель 39359db612
Коммит afa372bfe1
3 изменённых файлов: 58 добавлений и 26 удалений

Просмотреть файл

@ -36,6 +36,9 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
#if defined(XP_MAC)
#include <Errors.h>
#endif
#if defined(SUNOS4) #if defined(SUNOS4)
#include <unistd.h> /* for SEEK_SET */ #include <unistd.h> /* for SEEK_SET */
@ -63,7 +66,7 @@ static num_reads = 0;
struct BufioFileStruct struct BufioFileStruct
{ {
PRFileDesc *fd; /* real file descriptor */ FILE *fd; /* real file descriptor */
PRInt32 fsize; /* total size of file */ PRInt32 fsize; /* total size of file */
PRInt32 fpos; /* our logical position in the file */ PRInt32 fpos; /* our logical position in the file */
PRInt32 datastart; /* the file position at which the buffer starts */ PRInt32 datastart; /* the file position at which the buffer starts */
@ -89,12 +92,12 @@ static int _bufio_flushBuf( BufioFile* file );
/** /**
* like fopen() this routine takes *native* filenames, not NSPR names. * like fopen() this routine takes *native* filenames, not NSPR names.
*/ */
BufioFile* bufio_Open(const char* name, PRIntn flags, PRIntn mode) BufioFile* bufio_Open(const char* name, const char* mode)
{ {
PRFileDesc *fd; FILE *fd;
BufioFile *file = NULL; BufioFile *file = NULL;
fd = PR_Open( name, flags, mode ); fd = fopen( name, mode );
if ( fd ) if ( fd )
{ {
@ -110,10 +113,12 @@ BufioFile* bufio_Open(const char* name, PRIntn flags, PRIntn mode)
if ( file->data ) if ( file->data )
{ {
/* get file size to finish initialization of bufio */ /* get file size to finish initialization of bufio */
if ( PR_Seek( fd, 0, PR_SEEK_END ) >= 0) if ( !fseek( fd, 0, SEEK_END ) )
{ {
file->fsize = PR_Seek(fd, 0, PR_SEEK_CUR); file->fsize = ftell( fd );
file->readOnly = (flags & PR_RDONLY);
file->readOnly = strcmp(mode,XP_FILE_READ) == 0 ||
strcmp(mode,XP_FILE_READ_BIN) == 0;
} }
else else
{ {
@ -128,10 +133,39 @@ BufioFile* bufio_Open(const char* name, PRIntn flags, PRIntn mode)
/* close file if we couldn't create BufioFile */ /* close file if we couldn't create BufioFile */
if (!file) if (!file)
{ {
PR_Close( fd ); fclose( fd );
PR_SetError( PR_OUT_OF_MEMORY_ERROR, 0 ); PR_SetError( PR_OUT_OF_MEMORY_ERROR, 0 );
} }
} }
else
{
/* couldn't open file. Figure out why and set NSPR errors */
switch (errno)
{
/* file not found */
#ifdef XP_MAC
case fnfErr:
#else
case ENOENT:
#endif
PR_SetError(PR_FILE_NOT_FOUND_ERROR,0);
break;
/* file in use */
#ifdef XP_MAC
case opWrErr:
#else
case EACCES:
#endif
PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR,0);
break;
default:
PR_SetError(PR_UNKNOWN_ERROR,0);
break;
}
}
return file; return file;
} }
@ -150,7 +184,7 @@ int bufio_Close(BufioFile* file)
if ( file->bufdirty ) if ( file->bufdirty )
_bufio_flushBuf( file ); _bufio_flushBuf( file );
retval = PR_Close( file->fd ); retval = fclose( file->fd );
if ( file->data ) if ( file->data )
PR_Free( file->data ); PR_Free( file->data );
@ -290,12 +324,12 @@ PRUint32 bufio_Read(BufioFile* file, char* dest, PRUint32 count)
/* we need more than we could load into a buffer, so */ /* we need more than we could load into a buffer, so */
/* skip buffering and just read the data directly */ /* skip buffering and just read the data directly */
if ( PR_Seek( file->fd, file->fpos, PR_SEEK_SET ) >= 0 ) if ( fseek( file->fd, file->fpos, SEEK_SET ) == 0 )
{ {
#if DEBUG_dougt #if DEBUG_dougt
++num_reads; ++num_reads;
#endif #endif
bytesRead = PR_Read(file->fd, dest+bytesCopied, leftover); bytesRead = fread(dest+bytesCopied, 1, leftover, file->fd);
file->fpos += bytesRead; file->fpos += bytesRead;
retcount += bytesRead; retcount += bytesRead;
} }
@ -353,9 +387,9 @@ PRUint32 bufio_Read(BufioFile* file, char* dest, PRUint32 count)
else else
{ {
/* leftover data doesn't fit so skip buffering */ /* leftover data doesn't fit so skip buffering */
if ( PR_Seek( file->fd, file->fpos, PR_SEEK_SET ) >= 0 ) if ( fseek( file->fd, file->fpos, SEEK_SET ) == 0 )
{ {
bytesRead = PR_Read(file->fd, dest, leftover); bytesRead = fread(dest, 1, leftover, file->fd);
#if DEBUG_dougt #if DEBUG_dougt
++num_reads; ++num_reads;
#endif #endif
@ -480,8 +514,8 @@ PRUint32 bufio_Write(BufioFile* file, const char* src, PRUint32 count)
else else
{ {
/* request didn't fit in a buffer, write directly */ /* request didn't fit in a buffer, write directly */
if ( PR_Seek( file->fd, file->fpos, PR_SEEK_SET ) >= 0 ) if ( fseek( file->fd, file->fpos, SEEK_SET ) == 0 )
bytesWritten = PR_Write(file->fd, newsrc, leftover); bytesWritten = fwrite( newsrc, 1, leftover, file->fd );
else else
bytesWritten = 0; /* seek failed! */ bytesWritten = 0; /* seek failed! */
} }
@ -512,7 +546,7 @@ int bufio_Flush(BufioFile* file)
if ( file->bufdirty ) if ( file->bufdirty )
_bufio_flushBuf( file ); _bufio_flushBuf( file );
return PR_Sync(file->fd); return fflush(file->fd);
} }
@ -556,14 +590,14 @@ static PRBool _bufio_loadBuf( BufioFile* file, PRUint32 count )
if ( endPos > endBuf ) if ( endPos > endBuf )
startBuf += (endPos - endBuf); startBuf += (endPos - endBuf);
if ( PR_Seek( file->fd, startBuf, PR_SEEK_SET ) < 0 ) if ( fseek( file->fd, startBuf, SEEK_SET ) != 0 )
return PR_FALSE; return PR_FALSE;
else else
{ {
#if DEBUG_dougt #if DEBUG_dougt
++num_reads; ++num_reads;
#endif #endif
bytesRead = PR_Read(file->fd, file->data, file->bufsize); bytesRead = fread( file->data, 1, file->bufsize, file->fd );
file->datastart = startBuf; file->datastart = startBuf;
file->datasize = bytesRead; file->datasize = bytesRead;
file->bufdirty = PR_FALSE; file->bufdirty = PR_FALSE;
@ -591,10 +625,10 @@ static int _bufio_flushBuf( BufioFile* file )
return 0; return 0;
startpos = file->datastart + file->dirtystart; startpos = file->datastart + file->dirtystart;
if ( PR_Seek( file->fd, startpos, PR_SEEK_SET ) >= 0) if ( !fseek( file->fd, startpos, SEEK_SET ) )
{ {
dirtyamt = file->dirtyend - file->dirtystart; dirtyamt = file->dirtyend - file->dirtystart;
written = PR_Write( file->fd, file->data+file->dirtystart, dirtyamt ); written = fwrite( file->data+file->dirtystart, 1, dirtyamt, file->fd );
if ( written == dirtyamt ) if ( written == dirtyamt )
{ {
#ifdef DEBUG_dveditzbuf #ifdef DEBUG_dveditzbuf

Просмотреть файл

@ -35,7 +35,7 @@
typedef struct BufioFileStruct BufioFile; typedef struct BufioFileStruct BufioFile;
BufioFile* bufio_Open(const char* name, PRIntn flags, PRIntn mode); BufioFile* bufio_Open(const char* name, const char* mode);
int bufio_Close(BufioFile* file); int bufio_Close(BufioFile* file);
int bufio_Seek(BufioFile* file, PRInt32 offset, int whence); int bufio_Seek(BufioFile* file, PRInt32 offset, int whence);
PRUint32 bufio_Read(BufioFile* file, char* dest, PRUint32 count); PRUint32 bufio_Read(BufioFile* file, char* dest, PRUint32 count);

Просмотреть файл

@ -155,8 +155,7 @@ typedef MmioFile* XP_File;
/* home-grown XP buffering */ /* home-grown XP buffering */
/* writes are buffered too so use flush! */ /* writes are buffered too so use flush! */
/*-----------------------------------------------*/ /*-----------------------------------------------*/
#define USE_NSPR_MODES #define USE_STDIO_MODES
#include "nr_bufio.h" #include "nr_bufio.h"
#define XP_FileSeek(file,offset,whence) bufio_Seek((file),(offset),(whence)) #define XP_FileSeek(file,offset,whence) bufio_Seek((file),(offset),(whence))
@ -164,8 +163,7 @@ typedef MmioFile* XP_File;
#define XP_FileWrite(src,count,file) bufio_Write((file), (src), (count)) #define XP_FileWrite(src,count,file) bufio_Write((file), (src), (count))
#define XP_FileTell(file) bufio_Tell(file) #define XP_FileTell(file) bufio_Tell(file)
#define XP_FileClose(file) bufio_Close(file) #define XP_FileClose(file) bufio_Close(file)
#define XP_FileOpen(path, mode) bufio_Open((path), mode) #define XP_FileOpen(path, mode) bufio_Open((path), (mode))
#define XP_FileFlush(file) bufio_Flush(file) #define XP_FileFlush(file) bufio_Flush(file)
#define XP_FileSetBufferSize(file,bufsize) bufio_SetBufferSize(file,bufsize) #define XP_FileSetBufferSize(file,bufsize) bufio_SetBufferSize(file,bufsize)
@ -247,7 +245,7 @@ typedef PRFileDesc* XP_File;
#define XP_FILE_WRITE_BIN PR_WRONLY, 0644 #define XP_FILE_WRITE_BIN PR_WRONLY, 0644
#define XP_FILE_UPDATE (PR_RDWR|PR_CREATE_FILE), 0644 #define XP_FILE_UPDATE (PR_RDWR|PR_CREATE_FILE), 0644
#define XP_FILE_TRUNCATE (PR_RDWR | PR_TRUNCATE), 0644 #define XP_FILE_TRUNCATE (PR_RDWR | PR_TRUNCATE), 0644
#define XP_FILE_UPDATE_BIN (PR_RDWR|PR_CREATE_FILE), 0644 #define XP_FILE_UPDATE_BIN PR_RDWR|PR_CREATE_FILE, 0644
#define XP_FILE_TRUNCATE_BIN (PR_RDWR | PR_TRUNCATE), 0644 #define XP_FILE_TRUNCATE_BIN (PR_RDWR | PR_TRUNCATE), 0644
#ifdef SEEK_SET #ifdef SEEK_SET