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 see also: http://sources.redhat.com/ml/libc-alpha/2008-12/msg00003.html
107 sat_sort(void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *, void *), void *compard)
109 #if defined(__GLIBC__)
110 # if __GLIBC_PREREQ(2, 8)
111 qsort_r(base, nmemb, size, compar, compard);
113 /* backported for SLE10-SP2 */
114 __qsort_r(base, nmemb, size, compar, compard);
117 # error please add qsort_r call here
122 sat_dupjoin(const char *str1, const char *str2, const char *str3)
126 l1 = str1 ? strlen(str1) : 0;
127 l2 = str2 ? strlen(str2) : 0;
128 l3 = str3 ? strlen(str3) : 0;
129 s = str = sat_malloc(l1 + l2 + l3 + 1);