1 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
\r
2 * This file is part of clib library
\r
3 * Copyright (C) 2011 Avinash Dongre ( dongre.avinash@gmail.com )
\r
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
\r
6 * of this software and associated documentation files (the "Software"), to deal
\r
7 * in the Software without restriction, including without limitation the rights
\r
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
\r
9 * copies of the Software, and to permit persons to whom the Software is
\r
10 * furnished to do so, subject to the following conditions:
\r
12 * The above copyright notice and this permission notice shall be included in
\r
13 * all copies or substantial portions of the Software.
\r
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
\r
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
\r
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
\r
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
\r
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
\r
22 ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **/
\r
29 clib_copy( void *destination, void *source, size_t size ) {
\r
30 memcpy ( (char*)destination, source, size);
\r
33 clib_get ( void *destination, void *source, size_t size) {
\r
34 memcpy ( destination, (char*)source, size);
\r
38 new_clib_object(void *inObject, size_t obj_size) {
\r
39 struct clib_object* tmp = (struct clib_object*)malloc(sizeof(struct clib_object));
\r
41 return (struct clib_object*)0;
\r
42 tmp->size = obj_size;
\r
43 tmp->raw_data = (void*)malloc(obj_size);
\r
44 if ( !tmp->raw_data ) {
\r
46 return (struct clib_object*)0;
\r
48 memcpy ( tmp->raw_data, inObject, obj_size);
\r
53 get_raw_clib_object ( struct clib_object *inObject, void**elem) {
\r
54 *elem = (void*)malloc(inObject->size);
\r
56 return CLIB_ELEMENT_RETURN_ERROR;
\r
57 memcpy ( *elem, inObject->raw_data, inObject->size );
\r
59 return CLIB_ERROR_SUCCESS;
\r
62 replace_raw_clib_object(struct clib_object *current_object,void *elem, size_t elem_size) {
\r
63 free (current_object->raw_data);
\r
64 current_object->raw_data = (void*)malloc(elem_size);
\r
65 memcpy ( current_object->raw_data, elem, elem_size);
\r
70 delete_clib_object ( struct clib_object *inObject ) {
\r
72 free (inObject->raw_data);
\r
78 clib_strdup ( char *ptr ) {
\r
80 return _strdup (ptr);
\r
82 return strdup (ptr);
\r