mirror of
https://github.com/nodemcu/nodemcu-firmware.git
synced 2025-02-06 21:18:25 +08:00
The PR removed the bulk of non-newlib headers from the NodeMCU source base. app/libc has now been cut down to the bare minimum overrides to shadow the corresponding functions in the SDK's libc. The old c_xyz.h headerfiles have been nuked in favour of the standard <xyz.h> headers, with a few exceptions over in sdk-overrides. Again, shipping a libc.a without headers is a terrible thing to do. We're still living on a prayer that libc was configured the same was as a default-configured xtensa gcc toolchain assumes it is. That part I cannot do anything about, unfortunately, but it's no worse than it has been before. This enables our source files to compile successfully using the standard header files, and use the typical malloc()/calloc()/realloc()/free(), the strwhatever()s and memwhatever()s. These end up, through macro and linker magic, mapped to the appropriate SDK or ROM functions.
29 lines
531 B
C
29 lines
531 B
C
/* 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 <stdlib.h>
|
|
#include "c_types.h"
|
|
|
|
#include "str.h"
|
|
|
|
str * coap_new_string(size_t size) {
|
|
str *s = (str *)malloc(sizeof(str) + size + 1);
|
|
if ( !s ) {
|
|
return NULL;
|
|
}
|
|
|
|
memset(s, 0, sizeof(str));
|
|
s->s = ((unsigned char *)s) + sizeof(str);
|
|
return s;
|
|
}
|
|
|
|
void coap_delete_string(str *s) {
|
|
free(s);
|
|
}
|
|
|