From 0083a1f3f557e9c27dea33b08d661a7f20611134 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Mon, 31 Oct 2005 20:04:59 +0000 Subject: [PATCH] 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 --- headers/private/app/LinkMsgReader.h | 1 + src/kits/app/LinkReceiver.cpp | 37 +++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/headers/private/app/LinkMsgReader.h b/headers/private/app/LinkMsgReader.h index 380dcdf9a7..6ca28cbe01 100644 --- a/headers/private/app/LinkMsgReader.h +++ b/headers/private/app/LinkMsgReader.h @@ -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 status_t Read(Type *data) { return Read(data, sizeof(Type)); diff --git a/src/kits/app/LinkReceiver.cpp b/src/kits/app/LinkReceiver.cpp index e3bf8ad352..2364e12dce 100644 --- a/src/kits/app/LinkReceiver.cpp +++ b/src/kits/app/LinkReceiver.cpp @@ -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(&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