]> git.ipfire.org Git - thirdparty/git.git/blob - reftable/basics.h
Merge branch 'en/fetch-negotiation-default-fix'
[thirdparty/git.git] / reftable / basics.h
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 #ifndef BASICS_H
10 #define BASICS_H
11
12 /*
13 * miscellaneous utilities that are not provided by Git.
14 */
15
16 #include "system.h"
17
18 /* Bigendian en/decoding of integers */
19
20 void put_be24(uint8_t *out, uint32_t i);
21 uint32_t get_be24(uint8_t *in);
22 void put_be16(uint8_t *out, uint16_t i);
23
24 /*
25 * find smallest index i in [0, sz) at which f(i) is true, assuming
26 * that f is ascending. Return sz if f(i) is false for all indices.
27 *
28 * Contrary to bsearch(3), this returns something useful if the argument is not
29 * found.
30 */
31 int binsearch(size_t sz, int (*f)(size_t k, void *args), void *args);
32
33 /*
34 * Frees a NULL terminated array of malloced strings. The array itself is also
35 * freed.
36 */
37 void free_names(char **a);
38
39 /* parse a newline separated list of names. `size` is the length of the buffer,
40 * without terminating '\0'. Empty names are discarded. */
41 void parse_names(char *buf, int size, char ***namesp);
42
43 /* compares two NULL-terminated arrays of strings. */
44 int names_equal(char **a, char **b);
45
46 /* returns the array size of a NULL-terminated array of strings. */
47 int names_length(char **names);
48
49 /* Allocation routines; they invoke the functions set through
50 * reftable_set_alloc() */
51 void *reftable_malloc(size_t sz);
52 void *reftable_realloc(void *p, size_t sz);
53 void reftable_free(void *p);
54 void *reftable_calloc(size_t sz);
55
56 /* Find the longest shared prefix size of `a` and `b` */
57 struct strbuf;
58 int common_prefix_size(struct strbuf *a, struct strbuf *b);
59
60 #endif