]>
git.proxmox.com Git - libgit2.git/blob - src/util.h
1 #ifndef INCLUDE_util_h__
2 #define INCLUDE_util_h__
4 #define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
6 extern void *git__malloc(size_t);
7 extern void *git__calloc(size_t, size_t);
8 extern char *git__strdup(const char *);
10 #ifndef GIT__NO_HIDE_MALLOC
11 # define GIT__FORBID_MALLOC do_not_use_malloc_directly
16 # define malloc(a) GIT__FORBID_MALLOC
21 # define calloc(a,b) GIT__FORBID_MALLOC
26 # define strdup(a) GIT__FORBID_MALLOC
29 extern int git__fmt(char *, size_t, const char *, ...)
30 GIT_FORMAT_PRINTF(3, 4);
31 extern int git__prefixcmp(const char *str
, const char *prefix
);
32 extern int git__suffixcmp(const char *str
, const char *suffix
);
34 extern int git__dirname(char *dir
, size_t n
, char *path
);
35 extern int git__basename(char *base
, size_t n
, char *path
);
37 extern void git__hexdump(const char *buffer
, size_t n
);
39 /** @return true if p fits into the range of a size_t */
40 GIT_INLINE(int) git__is_sizet(off_t p
)
47 * Realloc the buffer pointed at by variable 'x' so that it can hold
48 * at least 'nr' entries; the number of entries currently allocated
49 * is 'alloc', using the standard growing factor alloc_nr() macro.
51 * DO NOT USE any expression with side-effect for 'x' or 'alloc'.
53 #define alloc_nr(x) (((x)+16)*3/2)
54 #define ALLOC_GROW(x, nr, alloc) \
57 if (alloc_nr(alloc) < (nr)) \
60 alloc = alloc_nr(alloc); \
61 x = xrealloc((x), alloc * sizeof(*(x))); \
65 #endif /* INCLUDE_util_h__ */