2 Copyright 2020 Google LLC
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
11 void put_be24(uint8_t *out
, uint32_t i
)
13 out
[0] = (uint8_t)((i
>> 16) & 0xff);
14 out
[1] = (uint8_t)((i
>> 8) & 0xff);
15 out
[2] = (uint8_t)(i
& 0xff);
18 uint32_t get_be24(uint8_t *in
)
20 return (uint32_t)(in
[0]) << 16 | (uint32_t)(in
[1]) << 8 |
24 void put_be16(uint8_t *out
, uint16_t i
)
26 out
[0] = (uint8_t)((i
>> 8) & 0xff);
27 out
[1] = (uint8_t)(i
& 0xff);
30 int binsearch(size_t sz
, int (*f
)(size_t k
, void *args
), void *args
)
37 * (hi == sz) || f(hi) == true
38 * (lo == 0 && f(0) == true) || fi(lo) == false
41 size_t mid
= lo
+ (hi
- lo
) / 2;
52 return f(0, args
) ? 0 : 1;
55 void free_names(char **a
)
61 for (p
= a
; *p
; p
++) {
67 size_t names_length(char **names
)
75 void parse_names(char *buf
, int size
, char ***namesp
)
82 char *end
= buf
+ size
;
84 char *next
= strchr(p
, '\n');
85 if (next
&& next
< end
) {
91 REFTABLE_ALLOC_GROW(names
, names_len
+ 1, names_cap
);
92 names
[names_len
++] = xstrdup(p
);
97 REFTABLE_REALLOC_ARRAY(names
, names_len
+ 1);
98 names
[names_len
] = NULL
;
102 int names_equal(char **a
, char **b
)
105 for (; a
[i
] && b
[i
]; i
++) {
106 if (strcmp(a
[i
], b
[i
])) {
114 int common_prefix_size(struct strbuf
*a
, struct strbuf
*b
)
117 for (; p
< a
->len
&& p
< b
->len
; p
++) {
118 if (a
->buf
[p
] != b
->buf
[p
])