bytesWritten = count; memcpy( file->data + startOffset, src, bytesWritten );
if ( endOffset <= BUFIO_BUFSIZE ) bytesCopied = count; else bytesCopied = BUFIO_BUFSIZE - startOffset;  memcpy( file->data + startOffset, src, bytesCopied );
PRUint32 bufio_Write(BufioFile* file, const char* src, PRUint32 count){    PRInt32  startOffset;    PRInt32  endOffset;    PRUint32 retcount = 0;    PRUint32 bytesWritten = 0;    /* sanity check arguments */    if ( !file || !src || count == 0 || file->readOnly )        return 0;    /* Write to the current buffer if we can, otherwise load a new buffer */    startOffset = file->fpos - file->datastart;    endOffset = startOffset + count;    if ( startOffset >= 0 &&          startOffset <  BUFIO_BUFSIZE &&          endOffset   <= BUFIO_BUFSIZE )    {        /* the entire area we want to write is buffered */        bytesWritten = count;        memcpy( file->data + startOffset, src, bytesWritten );        file->bufdirty = PR_TRUE;        if ( endOffset > file->datasize )            file->datasize = endOffset;        file->dirtystart = PR_MIN( startOffset, file->dirtystart );        file->dirtyend   = PR_MAX( endOffset,   file->dirtyend );    }    else if ( count > BUFIO_BUFSIZE )    {        /* the data doesn't fit in a buffer, write w/out buffering. */        /* first check to see if it overlaps our current buffer */        if ( startOffset < BUFIO_BUFSIZE && endOffset > 0 )        {            /* this write overlaps at least part of the current buffer */            /* Flush any dirty data first */            if ( file->bufdirty )                 _bufio_flushBuf( file );            /* then empty the buffer so stale data isn't used */            file->datasize = 0;            file->dirtystart = BUFIO_BUFSIZE;            file->dirtyend = 0;        }        /* now if is safe to do the write */        if ( fseek( file->fd, file->fpos, SEEK_SET ) == 0 )        {            bytesWritten = fwrite( src, 1, count, file->fd );        }    }    else    {        /* the data doesn't fit in the current buffer, so we'll just */        /* start a new buffer. Flush any dirty data first            */        if ( file->bufdirty )            _bufio_flushBuf( file );        bytesWritten = count;        memcpy( file->data, src, bytesWritten );        file->bufdirty = PR_TRUE;        file->datastart = file->fpos; /* NB: original fpos! */        file->datasize = bytesWritten;        file->dirtystart = 0;        file->dirtyend = file->datasize;    }    file->fpos += bytesWritten;    if ( file->fpos > file->fsize )    {        file->fsize = file->fpos;    }        return bytesWritten;}