From 56b2bcdf35b8cfe98e05865414521ecea47edeca Mon Sep 17 00:00:00 2001 From: Kyle Huey Date: Wed, 8 Jun 2011 11:11:41 -0700 Subject: [PATCH] Bug 661529: Add NS_ReadInputStreamToBuffer to complement NS_ReadInputStreamToString. r=biesi --HG-- extra : rebase_source : 81b8876a34a2ec8c6fd0c2092b697fb8e2472a4a --- netwerk/base/public/nsNetUtil.h | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/netwerk/base/public/nsNetUtil.h b/netwerk/base/public/nsNetUtil.h index 991a44ef5128..08bb02ac01f1 100644 --- a/netwerk/base/public/nsNetUtil.h +++ b/netwerk/base/public/nsNetUtil.h @@ -1171,16 +1171,19 @@ NS_NewPostDataStream(nsIInputStream **result, } inline nsresult -NS_ReadInputStreamToString(nsIInputStream *aInputStream, - nsACString &aDest, +NS_ReadInputStreamToBuffer(nsIInputStream *aInputStream, + void** aDest, PRUint32 aCount) { nsresult rv; - aDest.SetLength(aCount); - if (aDest.Length() != aCount) - return NS_ERROR_OUT_OF_MEMORY; - char * p = aDest.BeginWriting(); + if (!*aDest) { + *aDest = malloc(aCount); + if (!*aDest) + return NS_ERROR_OUT_OF_MEMORY; + } + + char * p = reinterpret_cast(*aDest); PRUint32 bytesRead; PRUint32 totalRead = 0; while (1) { @@ -1197,6 +1200,18 @@ NS_ReadInputStreamToString(nsIInputStream *aInputStream, return rv; } +inline nsresult +NS_ReadInputStreamToString(nsIInputStream *aInputStream, + nsACString &aDest, + PRUint32 aCount) +{ + aDest.SetLength(aCount); + if (aDest.Length() != aCount) + return NS_ERROR_OUT_OF_MEMORY; + void* dest = aDest.BeginWriting(); + return NS_ReadInputStreamToBuffer(aInputStream, &dest, aCount); +} + inline nsresult NS_LoadPersistentPropertiesFromURI(nsIPersistentProperties **result, nsIURI *uri,