Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
michael@0 | 4 | */ |
michael@0 | 5 | |
michael@0 | 6 | #include "nscore.h" |
michael@0 | 7 | #include "nsIInputStream.h" |
michael@0 | 8 | #include "nsIOutputStream.h" |
michael@0 | 9 | |
michael@0 | 10 | /* |
michael@0 | 11 | * Fully reads the required amount of data. Keeps reading until all the |
michael@0 | 12 | * data is retrieved or an error is hit. |
michael@0 | 13 | */ |
michael@0 | 14 | NS_HIDDEN_(nsresult) ZW_ReadData(nsIInputStream *aStream, char *aBuffer, uint32_t aCount) |
michael@0 | 15 | { |
michael@0 | 16 | while (aCount > 0) { |
michael@0 | 17 | uint32_t read; |
michael@0 | 18 | nsresult rv = aStream->Read(aBuffer, aCount, &read); |
michael@0 | 19 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 20 | aCount -= read; |
michael@0 | 21 | aBuffer += read; |
michael@0 | 22 | // If we hit EOF before reading the data we need then throw. |
michael@0 | 23 | if (read == 0 && aCount > 0) |
michael@0 | 24 | return NS_ERROR_FAILURE; |
michael@0 | 25 | } |
michael@0 | 26 | |
michael@0 | 27 | return NS_OK; |
michael@0 | 28 | } |
michael@0 | 29 | |
michael@0 | 30 | /* |
michael@0 | 31 | * Fully writes the required amount of data. Keeps writing until all the |
michael@0 | 32 | * data is written or an error is hit. |
michael@0 | 33 | */ |
michael@0 | 34 | NS_HIDDEN_(nsresult) ZW_WriteData(nsIOutputStream *aStream, const char *aBuffer, |
michael@0 | 35 | uint32_t aCount) |
michael@0 | 36 | { |
michael@0 | 37 | while (aCount > 0) { |
michael@0 | 38 | uint32_t written; |
michael@0 | 39 | nsresult rv = aStream->Write(aBuffer, aCount, &written); |
michael@0 | 40 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 41 | if (written <= 0) |
michael@0 | 42 | return NS_ERROR_FAILURE; |
michael@0 | 43 | aCount -= written; |
michael@0 | 44 | aBuffer += written; |
michael@0 | 45 | } |
michael@0 | 46 | |
michael@0 | 47 | return NS_OK; |
michael@0 | 48 | } |