Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/modules/libjar/zipwriter/StreamFunctions.cpp
Line
Count
Source (jump to first uncovered line)
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
 */
5
6
#include "nscore.h"
7
#include "nsIInputStream.h"
8
#include "nsIOutputStream.h"
9
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
nsresult ZW_ReadData(nsIInputStream *aStream, char *aBuffer, uint32_t aCount)
15
0
{
16
0
    while (aCount > 0) {
17
0
        uint32_t read;
18
0
        nsresult rv = aStream->Read(aBuffer, aCount, &read);
19
0
        NS_ENSURE_SUCCESS(rv, rv);
20
0
        aCount -= read;
21
0
        aBuffer += read;
22
0
        // If we hit EOF before reading the data we need then throw.
23
0
        if (read == 0 && aCount > 0)
24
0
            return NS_ERROR_FAILURE;
25
0
    }
26
0
27
0
    return NS_OK;
28
0
}
29
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
nsresult ZW_WriteData(nsIOutputStream *aStream, const char *aBuffer,
35
                                  uint32_t aCount)
36
0
{
37
0
    while (aCount > 0) {
38
0
        uint32_t written;
39
0
        nsresult rv = aStream->Write(aBuffer, aCount, &written);
40
0
        NS_ENSURE_SUCCESS(rv, rv);
41
0
        if (written <= 0)
42
0
            return NS_ERROR_FAILURE;
43
0
        aCount -= written;
44
0
        aBuffer += written;
45
0
    }
46
0
47
0
    return NS_OK;
48
0
}