updates.
[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 void *silc_malloc(size_t size)
24 {
25   void *addr;
26   addr = malloc(size);
27   assert(addr != NULL);
28   return addr;
29 }
30
31 void *silc_calloc(size_t items, size_t size)
32 {
33   void *addr;
34   addr = calloc(items, size);
35   assert(addr != NULL);
36   return addr;
37 }
38
39 void *silc_realloc(void *ptr, size_t size)
40 {
41   void *addr;
42   addr = realloc(ptr, size);
43   assert(addr != NULL);
44   return addr;
45 }
46
47 void silc_free(void *ptr)
48 {
49   free(ptr);
50 }
51
52 void *silc_memdup(const void *ptr, size_t size)
53 {
54   unsigned char *addr = silc_malloc(size + 1);
55   assert(addr != NULL);
56   memcpy((void *)addr, ptr, size);
57   addr[size] = '\0';
58   return (void *)addr;
59 }