diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-10-11 09:43:04 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-10-11 09:43:04 +0000 |
commit | d9d94d0e53d26af75ec8241383d166544ebd79f3 (patch) | |
tree | 9080b73624389403a198257fe0547bb4634e64d2 /src/util/common_allocation.c | |
parent | 2d792ee2e9cc0c993b8907e2c8edb0c2b8465343 (diff) | |
download | gnunet-d9d94d0e53d26af75ec8241383d166544ebd79f3.tar.gz gnunet-d9d94d0e53d26af75ec8241383d166544ebd79f3.zip |
converting to GNUNET_LOG_from*
Diffstat (limited to 'src/util/common_allocation.c')
-rw-r--r-- | src/util/common_allocation.c | 60 |
1 files changed, 32 insertions, 28 deletions
diff --git a/src/util/common_allocation.c b/src/util/common_allocation.c index 98c89d86a..31da5829b 100644 --- a/src/util/common_allocation.c +++ b/src/util/common_allocation.c | |||
@@ -27,6 +27,10 @@ | |||
27 | #include "platform.h" | 27 | #include "platform.h" |
28 | #include "gnunet_common.h" | 28 | #include "gnunet_common.h" |
29 | 29 | ||
30 | #define LOG(kind,...) GNUNET_log_from (kind, "util",__VA_ARGS__) | ||
31 | |||
32 | #define LOG_STRERROR(kind,syscall) GNUNET_log_from_strerror (kind, "util", syscall) | ||
33 | |||
30 | #ifndef INT_MAX | 34 | #ifndef INT_MAX |
31 | #define INT_MAX 0x7FFFFFFF | 35 | #define INT_MAX 0x7FFFFFFF |
32 | #endif | 36 | #endif |
@@ -61,10 +65,10 @@ GNUNET_xmalloc_ (size_t size, const char *filename, int linenumber) | |||
61 | GNUNET_assert_at (size <= GNUNET_MAX_MALLOC_CHECKED, filename, linenumber); | 65 | GNUNET_assert_at (size <= GNUNET_MAX_MALLOC_CHECKED, filename, linenumber); |
62 | ret = GNUNET_xmalloc_unchecked_ (size, filename, linenumber); | 66 | ret = GNUNET_xmalloc_unchecked_ (size, filename, linenumber); |
63 | if (ret == NULL) | 67 | if (ret == NULL) |
64 | { | 68 | { |
65 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "malloc"); | 69 | LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "malloc"); |
66 | abort (); | 70 | abort (); |
67 | } | 71 | } |
68 | return ret; | 72 | return ret; |
69 | } | 73 | } |
70 | 74 | ||
@@ -82,7 +86,7 @@ GNUNET_xmalloc_ (size_t size, const char *filename, int linenumber) | |||
82 | */ | 86 | */ |
83 | void * | 87 | void * |
84 | GNUNET_xmemdup_ (const void *buf, size_t size, const char *filename, | 88 | GNUNET_xmemdup_ (const void *buf, size_t size, const char *filename, |
85 | int linenumber) | 89 | int linenumber) |
86 | { | 90 | { |
87 | void *ret; | 91 | void *ret; |
88 | 92 | ||
@@ -97,10 +101,10 @@ GNUNET_xmemdup_ (const void *buf, size_t size, const char *filename, | |||
97 | GNUNET_assert_at (size < INT_MAX, filename, linenumber); | 101 | GNUNET_assert_at (size < INT_MAX, filename, linenumber); |
98 | ret = malloc (size); | 102 | ret = malloc (size); |
99 | if (ret == NULL) | 103 | if (ret == NULL) |
100 | { | 104 | { |
101 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "malloc"); | 105 | LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "malloc"); |
102 | abort (); | 106 | abort (); |
103 | } | 107 | } |
104 | #ifdef W32_MEM_LIMIT | 108 | #ifdef W32_MEM_LIMIT |
105 | *((size_t *) ret) = size; | 109 | *((size_t *) ret) = size; |
106 | ret = &((size_t *) ret)[1]; | 110 | ret = &((size_t *) ret)[1]; |
@@ -168,10 +172,10 @@ GNUNET_xrealloc_ (void *ptr, size_t n, const char *filename, int linenumber) | |||
168 | #endif | 172 | #endif |
169 | ptr = realloc (ptr, n); | 173 | ptr = realloc (ptr, n); |
170 | if ((NULL == ptr) && (n > 0)) | 174 | if ((NULL == ptr) && (n > 0)) |
171 | { | 175 | { |
172 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "realloc"); | 176 | LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "realloc"); |
173 | abort (); | 177 | abort (); |
174 | } | 178 | } |
175 | #ifdef W32_MEM_LIMIT | 179 | #ifdef W32_MEM_LIMIT |
176 | ptr = &((size_t *) ptr)[1]; | 180 | ptr = &((size_t *) ptr)[1]; |
177 | #endif | 181 | #endif |
@@ -229,7 +233,7 @@ GNUNET_xstrdup_ (const char *str, const char *filename, int linenumber) | |||
229 | */ | 233 | */ |
230 | char * | 234 | char * |
231 | GNUNET_xstrndup_ (const char *str, size_t len, const char *filename, | 235 | GNUNET_xstrndup_ (const char *str, size_t len, const char *filename, |
232 | int linenumber) | 236 | int linenumber) |
233 | { | 237 | { |
234 | char *res; | 238 | char *res; |
235 | 239 | ||
@@ -256,7 +260,7 @@ GNUNET_xstrndup_ (const char *str, size_t len, const char *filename, | |||
256 | */ | 260 | */ |
257 | void | 261 | void |
258 | GNUNET_xgrow_ (void **old, size_t elementSize, unsigned int *oldCount, | 262 | GNUNET_xgrow_ (void **old, size_t elementSize, unsigned int *oldCount, |
259 | unsigned int newCount, const char *filename, int linenumber) | 263 | unsigned int newCount, const char *filename, int linenumber) |
260 | { | 264 | { |
261 | void *tmp; | 265 | void *tmp; |
262 | size_t size; | 266 | size_t size; |
@@ -264,22 +268,22 @@ GNUNET_xgrow_ (void **old, size_t elementSize, unsigned int *oldCount, | |||
264 | GNUNET_assert_at (INT_MAX / elementSize > newCount, filename, linenumber); | 268 | GNUNET_assert_at (INT_MAX / elementSize > newCount, filename, linenumber); |
265 | size = newCount * elementSize; | 269 | size = newCount * elementSize; |
266 | if (size == 0) | 270 | if (size == 0) |
267 | { | 271 | { |
268 | tmp = NULL; | 272 | tmp = NULL; |
269 | } | 273 | } |
270 | else | 274 | else |
271 | { | 275 | { |
272 | tmp = GNUNET_xmalloc_ (size, filename, linenumber); | 276 | tmp = GNUNET_xmalloc_ (size, filename, linenumber); |
273 | memset (tmp, 0, size); /* client code should not rely on this, though... */ | 277 | memset (tmp, 0, size); /* client code should not rely on this, though... */ |
274 | if (*oldCount > newCount) | 278 | if (*oldCount > newCount) |
275 | *oldCount = newCount; /* shrink is also allowed! */ | 279 | *oldCount = newCount; /* shrink is also allowed! */ |
276 | memcpy (tmp, *old, elementSize * (*oldCount)); | 280 | memcpy (tmp, *old, elementSize * (*oldCount)); |
277 | } | 281 | } |
278 | 282 | ||
279 | if (*old != NULL) | 283 | if (*old != NULL) |
280 | { | 284 | { |
281 | GNUNET_xfree_ (*old, filename, linenumber); | 285 | GNUNET_xfree_ (*old, filename, linenumber); |
282 | } | 286 | } |
283 | *old = tmp; | 287 | *old = tmp; |
284 | *oldCount = newCount; | 288 | *oldCount = newCount; |
285 | } | 289 | } |