modules/libjar/zipwriter/src/StreamFunctions.cpp

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     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