win32: special-case `ENOSPC` when writing to a pipe
[git.git] / reftable / basics.h
blob096b36862b9f4ebf14be7c3074d6f86d5e92c22c
1 /*
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
7 */
9 #ifndef BASICS_H
10 #define BASICS_H
13 * miscellaneous utilities that are not provided by Git.
16 #include "system.h"
18 /* Bigendian en/decoding of integers */
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);
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.
28 * Contrary to bsearch(3), this returns something useful if the argument is not
29 * found.
31 int binsearch(size_t sz, int (*f)(size_t k, void *args), void *args);
34 * Frees a NULL terminated array of malloced strings. The array itself is also
35 * freed.
37 void free_names(char **a);
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);
43 /* compares two NULL-terminated arrays of strings. */
44 int names_equal(char **a, char **b);
46 /* returns the array size of a NULL-terminated array of strings. */
47 int names_length(char **names);
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);
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);
60 #endif