Implementation of connectivity abstraction feature Release v0.3
[platform/upstream/iotivity.git] / resource / csdk / connectivity / lib / libcoap-4.1.1 / str.c
1 /* str.c -- strings to be used in the CoAP library
2  *
3  * Copyright (C) 2010,2011 Olaf Bergmann <bergmann@tzi.org>
4  *
5  * This file is part of the CoAP library libcoap. Please see
6  * README for terms of use.
7  */
8
9 #include "config.h"
10
11 #include <stdio.h>
12
13 #include "debug.h"
14 #include "mem.h"
15 #include "str.h"
16
17 str *coap_new_string(size_t size)
18 {
19     str *s = coap_malloc(sizeof(str) + size + 1);
20     if (!s)
21     {
22 #ifndef NDEBUG
23         coap_log(LOG_CRIT, "coap_new_string: malloc\n");
24 #endif
25         return NULL;
26     }
27
28     memset(s, 0, sizeof(str));
29     s->s = ((unsigned char *) s) + sizeof(str);
30     return s;
31 }
32
33 void coap_delete_string(str *s)
34 {
35     coap_free(s);
36 }
37