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
19 extern void *sat_malloc(size_t);
20 extern void *sat_malloc2(size_t, size_t);
21 extern void *sat_calloc(size_t, size_t);
22 extern void *sat_realloc(void *, size_t);
23 extern void *sat_realloc2(void *, size_t, size_t);
24 extern void *sat_free(void *);
26 static inline void *sat_extend(void *buf, size_t len, size_t nmemb, size_t size, size_t block)
30 if ((len & block) == 0)
31 buf = sat_realloc2(buf, len + (1 + block), size);
35 if (((len - 1) | block) != ((len + nmemb - 1) | block))
36 buf = sat_realloc2(buf, (len + (nmemb + block)) & ~block, size);
41 static inline void *sat_zextend(void *buf, size_t len, size_t nmemb, size_t size, size_t block)
43 buf = sat_extend(buf, len, nmemb, size, block);
44 memset((char *)buf + len * size, 0, nmemb * size);
48 static inline void *sat_extend_resize(void *buf, size_t len, size_t size, size_t block)
51 buf = sat_realloc2(buf, (len + block) & ~block, size);
55 static inline void *sat_calloc_block(size_t len, size_t size, size_t block)
60 buf = sat_malloc2((len + block) & ~block, size);
61 memset(buf, 0, ((len + block) & ~block) * size);
64 #endif /* SATSOLVER_UTIL_H */