modules/libjar/zipwriter/src/StreamFunctions.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial