libtrbase  1.0.2
Web server and task management solution.
sized_data.c
Go to the documentation of this file.
1 /**
2  * \file
3  *
4  * \author Georg Hopp
5  *
6  * \copyright
7  * Copyright © 2014 Georg Hopp
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, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <http://www.gnu.org/licenses/>.
21  */
22 
23 #include <stdarg.h>
24 #include <string.h>
25 #include <sys/types.h>
26 
27 #include "trbase.h"
28 
29 #include "tr/sized_data.h"
30 
31 static
32 int
33 sizedDataCtor(void * _this, va_list * params)
34 {
35  TR_SizedData this = _this;
36  char * data = va_arg(*params, char *);
37 
38  this->size = va_arg(*params, size_t);
39 
40  if (data != NULL) {
41  this->data = TR_malloc(this->size);
42  memcpy(this->data, data, this->size);
43  }
44 
45  return 0;
46 }
47 
48 static
49 void
50 sizedDataDtor(void * _this)
51 {
52  TR_MEM_FREE(((TR_SizedData)_this)->data);
53 }
54 
55 TR_INIT_IFACE(TR_Class, sizedDataCtor, sizedDataDtor, NULL);
56 TR_CREATE_CLASS(TR_SizedData, NULL, NULL, TR_IF(TR_Class));
57 
58 // vim: set ts=4 sw=4:
#define TR_IF(name)
Definition: interface.h:49
static int sizedDataCtor(void *_this, va_list *params)
Definition: sized_data.c:33
void * TR_malloc(size_t)
Definition: memory.c:178
#define TR_MEM_FREE(seg)
Definition: memory.h:26
TR_CREATE_CLASS(TR_SizedData, NULL, NULL, TR_IF(TR_Class))
static void sizedDataDtor(void *_this)
Definition: sized_data.c:50
TR_INIT_IFACE(TR_Class, sizedDataCtor, sizedDataDtor, NULL)
size_t size
Definition: memory.h:34