e2e455a9ec90cf214fb48a48db0860fec9243c3e
[silc.git] / lib / silcutil / silcmemory.c
1 /*
2
3   silcmemory.c 
4
5   Author: Pekka Riikonen <priikone@silcnet.org>
6
7   Copyright (C) 1999 - 2002 Pekka Riikonen
8
9   This program is free software; you can redistribute it and/or modify
10   it under the terms of the GNU General Public License as published by
11   the Free Software Foundation; version 2 of the License.
12
13   This program is distributed in the hope that it will be useful,
14   but WITHOUT ANY WARRANTY; without even the implied warranty of
15   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16   GNU General Public License for more details.
17
18 */
19 /* $Id$ */
20
21 #include "silcincludes.h"
22
23 #ifndef SILC_STACKTRACE
24
25 void *silc_malloc(size_t size)
26 {
27   void *addr;
28   addr = malloc(size);
29   assert(addr != NULL);
30   return addr;
31 }
32
33 void *silc_calloc(size_t items, size_t size)
34 {
35   void *addr;
36   addr = calloc(items, size);
37   assert(addr != NULL);
38   return addr;
39 }
40
41 void *silc_realloc(void *ptr, size_t size)
42 {
43   void *addr;
44   addr = realloc(ptr, size);
45   assert(addr != NULL);
46   return addr;
47 }
48
49 void silc_free(void *ptr)
50 {
51   free(ptr);
52 }
53
54 void *silc_memdup(const void *ptr, size_t size)
55 {
56   unsigned char *addr = silc_malloc(size + 1);
57   assert(addr != NULL);
58   memcpy((void *)addr, ptr, size);
59   addr[size] = '\0';
60   return (void *)addr;
61 }
62
63 #endif /* !SILC_STACKTRACE */