2 * Copyright (c) 2007, Novell Inc.
4 * This program is licensed under the BSD license, read LICENSE.BSD
5 * for further information
19 sat_oom(size_t num, size_t len)
22 fprintf(stderr, "Out of memory allocating %zu*%zu bytes!\n", num, len);
24 fprintf(stderr, "Out of memory allocating %zu bytes!\n", len);
30 sat_malloc(size_t len)
32 void *r = malloc(len ? len : 1);
39 sat_malloc2(size_t num, size_t len)
41 if (len && (num * len) / len != num)
43 return sat_malloc(num * len);
47 sat_realloc(void *old, size_t len)
50 old = malloc(len ? len : 1);
52 old = realloc(old, len ? len : 1);
59 sat_realloc2(void *old, size_t num, size_t len)
61 if (len && (num * len) / len != num)
63 return sat_realloc(old, num * len);
67 sat_calloc(size_t num, size_t len)
70 if (num == 0 || len == 0)
88 sat_timems(unsigned int subtract)
93 if (gettimeofday(&tv, 0))
95 r = (((unsigned int)tv.tv_sec >> 16) * 1000) << 16;
96 r += ((unsigned int)tv.tv_sec & 0xffff) * 1000;
97 r += (unsigned int)tv.tv_usec / 1000;
101 /* bsd's qsort_r has different arguments, so we define our
102 own version in case we need to do some clever mapping */
104 sat_sort(void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *, void *), void *compard)
106 qsort_r(base, nmemb, size, compar, compard);