Added an alternate ReadString() in case you know how large the string can get.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@14601 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2005-10-31 20:04:59 +00:00
parent 4f86bb69c5
commit 0083a1f3f5
2 changed files with 38 additions and 0 deletions

View File

@ -28,6 +28,7 @@ class LinkReceiver {
virtual status_t Read(void *data, ssize_t size);
status_t ReadString(char **string);
status_t ReadString(char *buffer, size_t bufferSize);
template <class Type> status_t Read(Type *data)
{
return Read(data, sizeof(Type));

View File

@ -298,4 +298,41 @@ LinkReceiver::ReadString(char **_string)
}
}
status_t
LinkReceiver::ReadString(char *buffer, size_t bufferLength)
{
int32 length = 0;
status_t status;
status = Read<int32>(&length);
if (status < B_OK)
return status;
if (length >= (int32)bufferLength) {
status = B_BUFFER_OVERFLOW;
goto err;
}
if (length < 0) {
status = B_ERROR;
goto err;
}
if (length > 0) {
status = Read(buffer, length);
if (status < B_OK)
goto err;
}
// make sure the string is null terminated
buffer[length] = '\0';
return B_OK;
err:
fRecvPosition -= sizeof(int32);
// rewind the transaction
return status;
}
} // namespace BPrivate