str.c 539 B

12345678910111213141516171819202122232425262728
  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. #include "c_stdlib.h"
  9. #include "c_types.h"
  10. #include "str.h"
  11. str * coap_new_string(size_t size) {
  12. str *s = (str *)c_malloc(sizeof(str) + size + 1);
  13. if ( !s ) {
  14. return NULL;
  15. }
  16. c_memset(s, 0, sizeof(str));
  17. s->s = ((unsigned char *)s) + sizeof(str);
  18. return s;
  19. }
  20. void coap_delete_string(str *s) {
  21. c_free(s);
  22. }