Thu, 22 Jan 2015 13:21:57 +0100
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 #ifndef _nsStreamFunctions_h_
7 #define _nsStreamFunctions_h_
9 #include "nscore.h"
10 #include "nsIInputStream.h"
11 #include "nsIOutputStream.h"
13 /*
14 * ZIP file data is stored little-endian. These are helper functions to read and
15 * write little endian data to/from a char buffer.
16 * The off argument, where present, is incremented according to the number of
17 * bytes consumed from the buffer.
18 */
19 inline NS_HIDDEN_(void) WRITE8(uint8_t* buf, uint32_t* off, uint8_t val)
20 {
21 buf[(*off)++] = val;
22 }
24 inline NS_HIDDEN_(void) WRITE16(uint8_t* buf, uint32_t* off, uint16_t val)
25 {
26 WRITE8(buf, off, val & 0xff);
27 WRITE8(buf, off, (val >> 8) & 0xff);
28 }
30 inline NS_HIDDEN_(void) WRITE32(uint8_t* buf, uint32_t* off, uint32_t val)
31 {
32 WRITE16(buf, off, val & 0xffff);
33 WRITE16(buf, off, (val >> 16) & 0xffff);
34 }
36 inline NS_HIDDEN_(uint8_t) READ8(const uint8_t* buf, uint32_t* off)
37 {
38 return buf[(*off)++];
39 }
41 inline NS_HIDDEN_(uint16_t) READ16(const uint8_t* buf, uint32_t* off)
42 {
43 uint16_t val = READ8(buf, off);
44 val |= READ8(buf, off) << 8;
45 return val;
46 }
48 inline NS_HIDDEN_(uint32_t) READ32(const uint8_t* buf, uint32_t* off)
49 {
50 uint32_t val = READ16(buf, off);
51 val |= READ16(buf, off) << 16;
52 return val;
53 }
55 inline NS_HIDDEN_(uint32_t) PEEK32(const uint8_t* buf)
56 {
57 return (uint32_t)( (buf [0] ) |
58 (buf [1] << 8) |
59 (buf [2] << 16) |
60 (buf [3] << 24) );
61 }
63 NS_HIDDEN_(nsresult) ZW_ReadData(nsIInputStream *aStream, char *aBuffer, uint32_t aCount);
65 NS_HIDDEN_(nsresult) ZW_WriteData(nsIOutputStream *aStream, const char *aBuffer,
66 uint32_t aCount);
68 #endif