2015-02-04 18:32:57 +01:00
|
|
|
/* str.c -- strings to be used in the CoAP library
|
|
|
|
*
|
|
|
|
* Copyright (C) 2010,2011 Olaf Bergmann <bergmann@tzi.org>
|
|
|
|
*
|
|
|
|
* This file is part of the CoAP library libcoap. Please see
|
2019-02-17 19:26:29 +01:00
|
|
|
* README for terms of use.
|
2015-02-04 18:32:57 +01:00
|
|
|
*/
|
|
|
|
|
2019-07-21 23:58:21 +02:00
|
|
|
#include <stdlib.h>
|
2015-02-04 18:32:57 +01:00
|
|
|
#include "c_types.h"
|
2019-02-17 19:26:29 +01:00
|
|
|
|
2015-02-04 18:32:57 +01:00
|
|
|
#include "str.h"
|
|
|
|
|
|
|
|
str * coap_new_string(size_t size) {
|
2019-07-21 23:58:21 +02:00
|
|
|
str *s = (str *)malloc(sizeof(str) + size + 1);
|
2015-02-04 18:32:57 +01:00
|
|
|
if ( !s ) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2019-07-21 23:58:21 +02:00
|
|
|
memset(s, 0, sizeof(str));
|
2015-02-04 18:32:57 +01:00
|
|
|
s->s = ((unsigned char *)s) + sizeof(str);
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
void coap_delete_string(str *s) {
|
2019-07-21 23:58:21 +02:00
|
|
|
free(s);
|
2015-02-04 18:32:57 +01:00
|
|
|
}
|
|
|
|
|