758b1d0e05
categories: * Missing includes (like <stdlib.h> and <string.h>). * Linking against $(TARGET_LIBSTDC++) instead of libstdc++.r4.so. * Local variables shadowing parameters. * Default parameters in function definitions (as opposed to function declarations). * All C++ stuff (nothrow, map, set, vector, min, max,...) must be imported explicitly from the std:: namespace now. * "new (sometype)[...]" must read "new sometype[...]", even if sometype is something like "const char *". * __FUNCTION__ is no longer a string literal (but a string expression), i.e. 'printf(__FUNCTION__ ": ...\n")' is invalid code. * A type cast results in a non-lvalue. E.g. "(char *)buffer += bytes" is an invalid expression. * "friend class SomeClass" only works when SomeClass is known before. Otherwise the an inner class with that name is considered as friend. gcc 4 is much pickier about scopes. * gcc 4 is generally stricter with respect to type conversions in C. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@14878 a95241bf-73f2-0310-859d-f6bbb57e9c96
79 lines
1.2 KiB
C++
79 lines
1.2 KiB
C++
#include "RAMLinkMsgReader.h"
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
RAMLinkMsgReader::RAMLinkMsgReader(int8 *buffer)
|
|
: BPrivate::LinkReceiver(-1)
|
|
{
|
|
SetBuffer(buffer);
|
|
}
|
|
|
|
|
|
RAMLinkMsgReader::RAMLinkMsgReader(void)
|
|
: BPrivate::LinkReceiver(-1)
|
|
{
|
|
SetBuffer(NULL);
|
|
}
|
|
|
|
|
|
RAMLinkMsgReader::~RAMLinkMsgReader(void)
|
|
{
|
|
// Note that this class does NOT take responsibility for the buffer it reads from.
|
|
}
|
|
|
|
|
|
void
|
|
RAMLinkMsgReader::SetBuffer(int8 *buffer)
|
|
{
|
|
if (!buffer) {
|
|
fBuffer = NULL;
|
|
fAttachStart = NULL;
|
|
fPosition = NULL;
|
|
fAttachSize = 0;
|
|
fCode = B_ERROR;
|
|
return;
|
|
}
|
|
|
|
fBuffer = buffer;
|
|
fPosition = fBuffer + 4;
|
|
|
|
fCode = *((int32*)fBuffer);
|
|
fAttachSize = *((size_t *)fPosition);
|
|
fPosition += sizeof(size_t);
|
|
fAttachStart = fPosition;
|
|
}
|
|
|
|
|
|
int8 *
|
|
RAMLinkMsgReader::GetBuffer(void)
|
|
{
|
|
return fBuffer;
|
|
}
|
|
|
|
|
|
size_t
|
|
RAMLinkMsgReader::GetBufferSize(void)
|
|
{
|
|
return fAttachSize;
|
|
}
|
|
|
|
|
|
status_t
|
|
RAMLinkMsgReader::Read(void *data, ssize_t size)
|
|
{
|
|
if (!fBuffer || fAttachSize == 0)
|
|
return B_NO_INIT;
|
|
|
|
if (size < 1)
|
|
return B_BAD_VALUE;
|
|
|
|
if (fPosition + size > fAttachStart + fAttachSize) {
|
|
// read past end of buffer
|
|
return B_BAD_VALUE;
|
|
}
|
|
|
|
memcpy(data, fPosition, size);
|
|
fPosition += size;
|
|
return B_OK;
|
|
}
|