str.c
Go to the documentation of this file.
/* 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
* README for terms of use.
*/
#include "coap_config.h"
#include <stdio.h>
#include "debug.h"
#include "mem.h"
#include "str.h"
str *coap_new_string(size_t size) {
str *s = coap_malloc(sizeof(str) + size + 1);
if ( !s ) {
#ifndef NDEBUG
coap_log(LOG_CRIT, "coap_new_string: malloc\n");
#endif
return NULL;
}
memset(s, 0, sizeof(str));
s->s = ((unsigned char *)s) + sizeof(str);
return s;
}
void coap_delete_string(str *s) {
coap_free(s);
}
coap_new_string
str * coap_new_string(size_t size)
Returns a new string object with at least size bytes storage allocated.
Definition: str.c:17
mem.h
coap_malloc
static void * coap_malloc(size_t size)
Wrapper function to coap_malloc_type() for backwards compatibility.
Definition: mem.h:70
debug.h
str.h
LOG_CRIT
Definition: debug.h:29
str
Definition: str.h:15
coap_free
static void coap_free(void *object)
Wrapper function to coap_free_type() for backwards compatibility.
Definition: mem.h:77
coap_delete_string
void coap_delete_string(str *s)
Deletes the given string and releases any memory allocated.
Definition: str.c:31
coap_log
#define coap_log(...)
Definition: debug.h:58
str::s
unsigned char * s
Definition: str.h:17