* Added BString version of LinkReceiver::ReadString().

* adopted this method for ServerLink as well.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@14750 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2005-11-07 16:14:05 +00:00
parent ca9e5772c3
commit 41572514dd
4 changed files with 60 additions and 2 deletions
+44
View File
@@ -15,6 +15,7 @@
#include <ServerProtocol.h>
#include <LinkReceiver.h>
#include <String.h>
#include "link_message.h"
@@ -296,6 +297,49 @@ LinkReceiver::ReadString(char **_string)
}
status_t
LinkReceiver::ReadString(BString &string)
{
int32 length = 0;
status_t status;
status = Read<int32>(&length);
if (status < B_OK)
return status;
if (length < 0) {
status = B_ERROR;
goto err;
}
if (length > 0) {
char* buffer = string.LockBuffer(length + 1);
if (buffer == NULL) {
status = B_NO_MEMORY;
goto err;
}
status = Read(buffer, length);
if (status < B_OK) {
string.UnlockBuffer();
goto err;
}
// make sure the string is null terminated
buffer[length] = '\0';
string.UnlockBuffer(length);
} else
string = "";
return B_OK;
err:
fRecvPosition -= sizeof(int32);
// rewind the transaction
return status;
}
status_t
LinkReceiver::ReadString(char *buffer, size_t bufferLength)
{