2 * cbfstool, CLI utility for CBFS file manipulation
4 * Copyright 2013 Google Inc.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
24 size_t bgets(struct buffer
*input
, void *output
, size_t len
)
26 len
= input
->size
< len
? input
->size
: len
;
27 memmove(output
, input
->data
, len
);
33 size_t bputs(struct buffer
*b
, const void *data
, size_t len
)
35 memmove(&b
->data
[b
->size
], data
, len
);
40 /* The assumption in all this code is that we're given a pointer to enough data.
41 * Hence, we do not check for underflow.
43 static uint8_t get8(struct buffer
*input
)
45 uint8_t ret
= *input
->data
++;
50 static uint16_t get16be(struct buffer
*input
)
53 ret
= get8(input
) << 8;
58 static uint32_t get32be(struct buffer
*input
)
61 ret
= get16be(input
) << 16;
62 ret
|= get16be(input
);
66 static uint64_t get64be(struct buffer
*input
)
71 ret
|= get32be(input
);
75 static void put8(struct buffer
*input
, uint8_t val
)
77 input
->data
[input
->size
] = val
;
81 static void put16be(struct buffer
*input
, uint16_t val
)
83 put8(input
, val
>> 8);
87 static void put32be(struct buffer
*input
, uint32_t val
)
89 put16be(input
, val
>> 16);
93 static void put64be(struct buffer
*input
, uint64_t val
)
95 put32be(input
, val
>> 32);
99 static uint16_t get16le(struct buffer
*input
)
103 ret
|= get8(input
) << 8;
107 static uint32_t get32le(struct buffer
*input
)
110 ret
= get16le(input
);
111 ret
|= get16le(input
) << 16;
115 static uint64_t get64le(struct buffer
*input
)
119 low
= get32le(input
);
120 ret
= get32le(input
);
126 static void put16le(struct buffer
*input
, uint16_t val
)
129 put8(input
, val
>> 8);
132 static void put32le(struct buffer
*input
, uint32_t val
)
135 put16le(input
, val
>> 16);
138 static void put64le(struct buffer
*input
, uint64_t val
)
141 put32le(input
, val
>> 32);
144 struct xdr xdr_be
= {
145 get8
, get16be
, get32be
, get64be
,
146 put8
, put16be
, put32be
, put64be
149 struct xdr xdr_le
= {
150 get8
, get16le
, get32le
, get64le
,
151 put8
, put16le
, put32le
, put64le