modules/libjar/zipwriter/src/StreamFunctions.h

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

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

mercurial