- add HEADEREND
[platform/upstream/libsolv.git] / src / util.h
1 /*
2  * Copyright (c) 2007, Novell Inc.
3  *
4  * This program is licensed under the BSD license, read LICENSE.BSD
5  * for further information
6  */
7
8 /*
9  * util.h
10  *
11  */
12
13 #ifndef SATSOLVER_UTIL_H
14 #define SATSOLVER_UTIL_H
15
16 #include <stddef.h>
17
18 extern void *sat_malloc(size_t);
19 extern void *sat_malloc2(size_t, size_t);
20 extern void *sat_calloc(size_t, size_t);
21 extern void *sat_realloc(void *, size_t);
22 extern void *sat_realloc2(void *, size_t, size_t);
23 extern void *sat_free(void *);
24
25 static inline void *sat_extend(void *buf, size_t len, size_t nmemb, size_t size, size_t block)
26 {
27   if (nmemb == 1)
28     {
29       if ((len & block) == 0)
30         buf = sat_realloc2(buf, len + (1 + block), size);
31     }
32   else
33     {
34       if (((len - 1) | block) != ((len + nmemb - 1) | block))
35         buf = sat_realloc2(buf, (len + (nmemb + block)) & ~block, size);
36     }
37   return buf;
38 }
39
40 static inline void *sat_extend_resize(void *buf, size_t len, size_t size, size_t block)
41 {
42   if (len)
43     buf = sat_realloc2(buf, (len + block) & ~block, size);
44   return buf;
45 }
46
47 #endif /* SATSOLVER_UTIL_H */