Coverage Report

Created: 2020-05-07 18:36

/proc/self/cwd/c/compat.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
Copyright 2020 Google LLC
3
4
Use of this source code is governed by a BSD-style
5
license that can be found in the LICENSE file or at
6
https://developers.google.com/open-source/licenses/bsd
7
8
*/
9
10
/* compat.c - compatibility functions for standalone compilation */
11
12
#include "system.h"
13
#include "basics.h"
14
15
void put_be32(uint8_t *out, uint32_t i)
16
219
{
17
219
  out[0] = (uint8_t)((i >> 24) & 0xff);
18
219
  out[1] = (uint8_t)((i >> 16) & 0xff);
19
219
  out[2] = (uint8_t)((i >> 8) & 0xff);
20
219
  out[3] = (uint8_t)((i)&0xff);
21
219
}
22
23
uint32_t get_be32(uint8_t *in)
24
347
{
25
347
  return (uint32_t)(in[0]) << 24 | (uint32_t)(in[1]) << 16 |
26
347
         (uint32_t)(in[2]) << 8 | (uint32_t)(in[3]);
27
347
}
28
29
void put_be64(uint8_t *out, uint64_t v)
30
3.44k
{
31
3.44k
  int i = sizeof(uint64_t);
32
30.9k
  while (i--) {
33
27.5k
    out[i] = (uint8_t)(v & 0xff);
34
27.5k
    v >>= 8;
35
27.5k
  }
36
3.44k
}
37
38
uint64_t get_be64(uint8_t *out)
39
2.59k
{
40
2.59k
  uint64_t v = 0;
41
2.59k
  int i = 0;
42
23.3k
  for (i = 0; i < sizeof(uint64_t); i++) {
43
20.7k
    v = (v << 8) | (uint8_t)(out[i] & 0xff);
44
20.7k
  }
45
2.59k
  return v;
46
2.59k
}
47
48
uint16_t get_be16(uint8_t *in)
49
1.76k
{
50
1.76k
  return (uint32_t)(in[0]) << 8 | (uint32_t)(in[1]);
51
1.76k
}
52
53
char *xstrdup(const char *s)
54
3.59k
{
55
3.59k
  int l = strlen(s);
56
3.59k
  char *dest = (char *)reftable_malloc(l + 1);
57
3.59k
  strncpy(dest, s, l + 1);
58
3.59k
  return dest;
59
3.59k
}
60
61
void sleep_millisec(int millisecs)
62
0
{
63
0
  usleep(millisecs * 1000);
64
0
}