File: prs_u64_big.c

package info (click to toggle)
libowfat 0.34-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,288 kB
  • sloc: ansic: 20,181; makefile: 16
file content (28 lines) | stat: -rw-r--r-- 589 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include "parse.h"

uint64_t prs_u64_big(struct bytestream* bs) {
  unsigned int i;
  uint64_t x = bs_get(bs);
  for (i=1; i<8; ++i)
    x = (x << 8) | bs_get(bs);
  return x;
}

#ifdef UNITTEST
#include <assert.h>

#undef UNITTEST
#include "buffer/bs_get.c"
#include "buffer/bs_err.c"

// mock this
ssize_t buffer_getc(buffer* b,char* c) { return 0; }

int main() {
  struct bytestream bs = BS_FROM_MEMBUF("\xde\xad\xbe\xef\x12\x34\x56\x78",8);
  assert(prs_u64_big(&bs) == 0xdeadbeef12345678);
  assert(bs_err(&bs) == 0);
  assert(prs_u64_big(&bs) == 0);
  assert(bs_err(&bs));
}
#endif