Small style changes, just to improve my commit stats :)
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@13214 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,36 +1,16 @@
|
|||||||
//------------------------------------------------------------------------------
|
/*
|
||||||
// Copyright (c) 2001-2002, OpenBeOS
|
* Copyright (c) 2001-2005, Haiku
|
||||||
//
|
* Distributed under the terms of the MIT license
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
* Authors:
|
||||||
// copy of this software and associated documentation files (the "Software"),
|
Stefano Ceccherini ([email protected])
|
||||||
// to deal in the Software without restriction, including without limitation
|
*/
|
||||||
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
||||||
// and/or sell copies of the Software, and to permit persons to whom the
|
// A buffered adapter for BPositionIO objects.
|
||||||
// Software is furnished to do so, subject to the following conditions:
|
|
||||||
//
|
|
||||||
// The above copyright notice and this permission notice shall be included in
|
|
||||||
// all copies or substantial portions of the Software.
|
|
||||||
//
|
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
||||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
||||||
// DEALINGS IN THE SOFTWARE.
|
|
||||||
//
|
|
||||||
// File Name: BufferIO.cpp
|
|
||||||
// Author(s): Stefano Ceccherini ([email protected])
|
|
||||||
//
|
|
||||||
// Description: A buffered adapter for BPositionIO objects.
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
// Standard Includes -----------------------------------------------------------
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
// System Includes -------------------------------------------------------------
|
|
||||||
#include <BufferIO.h>
|
#include <BufferIO.h>
|
||||||
|
|
||||||
/*! \class BBufferIO
|
/*! \class BBufferIO
|
||||||
@@ -66,7 +46,7 @@ BBufferIO::BBufferIO(BPositionIO *stream, size_t buf_size, bool owns_stream)
|
|||||||
// I think R5 uses new, but doesn't catch the thrown exception
|
// I think R5 uses new, but doesn't catch the thrown exception
|
||||||
// (if you specify a very big buffer, the application just
|
// (if you specify a very big buffer, the application just
|
||||||
// terminates with abort).
|
// terminates with abort).
|
||||||
m_buffer = (char*)malloc(m_buffer_phys * sizeof(char));
|
m_buffer = (char *)malloc(m_buffer_phys * sizeof(char));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -108,8 +88,7 @@ BBufferIO::ReadAt(off_t pos, void *buffer, size_t size)
|
|||||||
|
|
||||||
// If the amount of data we want doesn't fit in the buffer, just
|
// If the amount of data we want doesn't fit in the buffer, just
|
||||||
// read it directly from the disk (and don't touch the buffer).
|
// read it directly from the disk (and don't touch the buffer).
|
||||||
if (size > m_buffer_phys)
|
if (size > m_buffer_phys) {
|
||||||
{
|
|
||||||
if (m_buffer_dirty)
|
if (m_buffer_dirty)
|
||||||
Flush();
|
Flush();
|
||||||
return m_stream->ReadAt(pos, buffer, size);
|
return m_stream->ReadAt(pos, buffer, size);
|
||||||
@@ -119,8 +98,8 @@ BBufferIO::ReadAt(off_t pos, void *buffer, size_t size)
|
|||||||
if (size > m_buffer_used
|
if (size > m_buffer_used
|
||||||
|| pos < m_buffer_start
|
|| pos < m_buffer_start
|
||||||
|| pos > m_buffer_start + m_buffer_used
|
|| pos > m_buffer_start + m_buffer_used
|
||||||
|| pos + size > m_buffer_start + m_buffer_used)
|
|| pos + size > m_buffer_start + m_buffer_used) {
|
||||||
{
|
|
||||||
if (m_buffer_dirty)
|
if (m_buffer_dirty)
|
||||||
Flush(); // If there are pending writes, do them.
|
Flush(); // If there are pending writes, do them.
|
||||||
|
|
||||||
@@ -161,16 +140,14 @@ BBufferIO::WriteAt(off_t pos, const void *buffer, size_t size)
|
|||||||
|
|
||||||
// If we have cached data in the buffer, whose offset into the stream
|
// If we have cached data in the buffer, whose offset into the stream
|
||||||
// is > 0, and the buffer isn't dirty, drop the data.
|
// is > 0, and the buffer isn't dirty, drop the data.
|
||||||
if (!m_buffer_dirty && m_buffer_start > pos)
|
if (!m_buffer_dirty && m_buffer_start > pos) {
|
||||||
{
|
|
||||||
m_buffer_start = 0;
|
m_buffer_start = 0;
|
||||||
m_buffer_used = 0;
|
m_buffer_used = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we want to write beyond the cached data...
|
// If we want to write beyond the cached data...
|
||||||
if (pos > m_buffer_start + m_buffer_used
|
if (pos > m_buffer_start + m_buffer_used
|
||||||
|| pos < m_buffer_start)
|
|| pos < m_buffer_start) {
|
||||||
{
|
|
||||||
ssize_t read;
|
ssize_t read;
|
||||||
off_t where = pos;
|
off_t where = pos;
|
||||||
|
|
||||||
@@ -179,15 +156,15 @@ BBufferIO::WriteAt(off_t pos, const void *buffer, size_t size)
|
|||||||
|
|
||||||
// ...cache more.
|
// ...cache more.
|
||||||
read = m_stream->ReadAt(where, m_buffer, m_buffer_phys);
|
read = m_stream->ReadAt(where, m_buffer, m_buffer_phys);
|
||||||
if (read > 0)
|
if (read > 0) {
|
||||||
{
|
|
||||||
m_buffer_used = read;
|
m_buffer_used = read;
|
||||||
m_buffer_start = where;
|
m_buffer_start = where;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
memcpy(m_buffer + pos - m_buffer_start, buffer, size);
|
|
||||||
m_buffer_dirty = true;
|
|
||||||
|
|
||||||
|
memcpy(m_buffer + pos - m_buffer_start, buffer, size);
|
||||||
|
|
||||||
|
m_buffer_dirty = true;
|
||||||
m_buffer_used = max_c((size + pos), m_buffer_used);
|
m_buffer_used = max_c((size + pos), m_buffer_used);
|
||||||
|
|
||||||
return size;
|
return size;
|
||||||
|
|||||||
Reference in New Issue
Block a user