Adding signature checking
[platform/core/system/tizen-platform-wrapper.git] / src / heap.h
1 /*
2  * Copyright (C) 2013-2014 Intel Corporation.
3  * 
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
17  *
18  * Authors:
19  *   José Bollo <jose.bollo@open.eurogiciel.org>
20  *   Stéphane Desneux <stephane.desneux@open.eurogiciel.org>
21  *   Jean-Benoit Martin <jean-benoit.martin@open.eurogiciel.org>
22  *
23  */
24 #ifndef HEAP_H
25 #define HEAP_H
26
27 /* null offset value */
28 #define HNULL               ((size_t)-1)
29
30 /* structure defining the heap */
31 struct heap {
32     char  *data;     /* pointer to data of the heap */
33     size_t size;     /* count of used byte of the heap */
34     size_t capacity; /* count of byte of the heap */
35 };
36
37 /*
38    Return the address of the 'heap' memory of 'offset'.
39    The returned pointer is only valid until
40    a call to 'heap_destroy', 'heap_resize', 'heap_alloc' 
41 */
42 inline static void *heap_address( struct heap *heap, size_t offset)
43 {
44     return heap->data + offset;
45 }
46
47
48 /*
49    Initialize the 'heap' with a 'capacity' in byte.
50    The allocated size will be zero.
51    Returns 0 if success, -1 if error occured (see then errno)
52 */
53 int heap_create( struct heap *heap, size_t capacity);
54
55 /*
56    Resize the 'heap' to 'size'.
57    Returns 0 if success, -1 if error occured (see then errno)
58 */
59 int heap_resize( struct heap *heap, size_t size);
60
61 /*
62    Allocation of 'count' bytes from the 'heap'.
63    Returns the offset (in byte) from the start
64    of the heap. Return HNULL in case of error (see then errno).
65 */
66 size_t heap_alloc( struct heap *heap, size_t count);
67
68 /*
69    Copy the 'string' of 'length' in the 'heap', appending a terminating null.
70    Return the offset or HNULL if error.
71 */
72 size_t heap_strndup( struct heap *heap, const char *string, size_t length);
73
74 /*
75    Copy the 'string' in the 'heap' with the terminating null.
76    Return the offset or HNULL if error.
77 */
78 size_t heap_strdup( struct heap *heap, const char *string);
79
80 /*
81    Destroy the 'heap'.
82    Returns 0 if success, -1 if error occured (see then errno)
83 */
84 int heap_destroy( struct heap *heap);
85
86 /*
87    Set the heap as read/write
88    Returns 0 if success, -1 if error occured (see then errno)
89 */
90 int heap_read_write( struct heap *heap);
91
92 /*
93    Set the heap as read only
94    Returns 0 if success, -1 if error occured (see then errno)
95 */
96 int heap_read_only( struct heap *heap);
97
98 #endif
99