2 * Copyright (c) 2007, Novell Inc.
4 * This program is licensed under the BSD license, read LICENSE.BSD
5 * for further information
13 #ifndef SATSOLVER_UTIL_H
14 #define SATSOLVER_UTIL_H
21 * exits with error message on error
23 extern void *sat_malloc(size_t);
24 extern void *sat_malloc2(size_t, size_t);
25 extern void *sat_calloc(size_t, size_t);
26 extern void *sat_realloc(void *, size_t);
27 extern void *sat_realloc2(void *, size_t, size_t);
28 extern void *sat_free(void *);
29 extern void sat_oom(size_t, size_t);
30 extern unsigned int sat_timems(unsigned int subtract);
31 extern void sat_sort(void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *, void *), void *compard);
32 extern char *sat_dupjoin(const char *str1, const char *str2, const char *str3);
34 static inline void *sat_extend(void *buf, size_t len, size_t nmemb, size_t size, size_t block)
38 if ((len & block) == 0)
39 buf = sat_realloc2(buf, len + (1 + block), size);
43 if (((len - 1) | block) != ((len + nmemb - 1) | block))
44 buf = sat_realloc2(buf, (len + (nmemb + block)) & ~block, size);
50 * extend an array by reallocation and zero's the new section
53 * nmbemb number of elements to add
54 * size size of each element
55 * block block size used to allocate the elements
57 static inline void *sat_zextend(void *buf, size_t len, size_t nmemb, size_t size, size_t block)
59 buf = sat_extend(buf, len, nmemb, size, block);
60 memset((char *)buf + len * size, 0, nmemb * size);
64 static inline void *sat_extend_resize(void *buf, size_t len, size_t size, size_t block)
67 buf = sat_realloc2(buf, (len + block) & ~block, size);
71 static inline void *sat_calloc_block(size_t len, size_t size, size_t block)
76 buf = sat_malloc2((len + block) & ~block, size);
77 memset(buf, 0, ((len + block) & ~block) * size);
80 #endif /* SATSOLVER_UTIL_H */