Commit 526d21da authored by Johny Mattsson's avatar Johny Mattsson Committed by Terry Ellison
Browse files

Major cleanup - c_whatever is finally history. (#2838)

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.
parent 9f8b74de
......@@ -6,8 +6,8 @@
#include "lauxlib.h"
#include "platform.h"
#include "c_string.h"
#include "c_stdlib.h"
#include <string.h>
#include <stdlib.h>
#include "ctype.h"
#include "c_types.h"
......@@ -95,18 +95,18 @@ static void wifi_scan_done(void *arg, STATUS status)
while (bss_link != NULL)
{
c_memset(ssid, 0, 33);
if (c_strlen(bss_link->ssid) <= 32)
memset(ssid, 0, 33);
if (strlen(bss_link->ssid) <= 32)
{
c_memcpy(ssid, bss_link->ssid, c_strlen(bss_link->ssid));
memcpy(ssid, bss_link->ssid, strlen(bss_link->ssid));
}
else
{
c_memcpy(ssid, bss_link->ssid, 32);
memcpy(ssid, bss_link->ssid, 32);
}
if(getap_output_format==1) //use new format(BSSID : SSID, RSSI, Authmode, Channel)
{
c_sprintf(temp,MACSTR, MAC2STR(bss_link->bssid));
sprintf(temp,MACSTR, MAC2STR(bss_link->bssid));
wifi_add_sprintf_field(L, temp, "%s,%d,%d,%d",
ssid, bss_link->rssi, bss_link->authmode, bss_link->channel);
NODE_DBG(MACSTR" : %s\n",MAC2STR(bss_link->bssid) , temp);//00 00 00 00 00 00
......@@ -260,7 +260,7 @@ static int wifi_setcountry( lua_State* L ){
if( lua_isstring(L, -1) ){
const char *country_code = luaL_checklstring( L, -1, &len );
luaL_argcheck(L, (len==2 && isalpha(country_code[0]) && isalpha(country_code[1])), 1, "country: country code must be 2 chars");
c_memcpy(cfg.cc, country_code, len);
memcpy(cfg.cc, country_code, len);
if(cfg.cc[0] >= 0x61) cfg.cc[0]=cfg.cc[0]-32; //if lowercase change to uppercase
if(cfg.cc[1] >= 0x61) cfg.cc[1]=cfg.cc[1]-32; //if lowercase change to uppercase
}
......@@ -552,7 +552,7 @@ static int wifi_getmac( lua_State* L, uint8_t mode )
char temp[64];
uint8_t mac[6];
wifi_get_macaddr(mode, mac);
c_sprintf(temp, MACSTR, MAC2STR(mac));
sprintf(temp, MACSTR, MAC2STR(mac));
lua_pushstring( L, temp );
return 1;
}
......@@ -581,11 +581,11 @@ static int wifi_getip( lua_State* L, uint8_t mode )
}
else
{
c_sprintf(temp, "%d.%d.%d.%d", IP2STR(&pTempIp.ip) );
sprintf(temp, "%d.%d.%d.%d", IP2STR(&pTempIp.ip) );
lua_pushstring( L, temp );
c_sprintf(temp, "%d.%d.%d.%d", IP2STR(&pTempIp.netmask) );
sprintf(temp, "%d.%d.%d.%d", IP2STR(&pTempIp.netmask) );
lua_pushstring( L, temp );
c_sprintf(temp, "%d.%d.%d.%d", IP2STR(&pTempIp.gw) );
sprintf(temp, "%d.%d.%d.%d", IP2STR(&pTempIp.gw) );
lua_pushstring( L, temp );
return 3;
}
......@@ -609,7 +609,7 @@ static int wifi_getbroadcast( lua_State* L, uint8_t mode )
uint32 broadcast_address32 = ~pTempIp.netmask.addr | subnet_mask32;
broadcast_address.addr = broadcast_address32;
c_sprintf(temp, "%d.%d.%d.%d", IP2STR(&broadcast_address) );
sprintf(temp, "%d.%d.%d.%d", IP2STR(&broadcast_address) );
lua_pushstring( L, temp );
return 1;
......@@ -688,7 +688,7 @@ static int wifi_station_get_ap_info4lua( lua_State* L )
lua_pushstring(L, temp);
lua_setfield(L, -2, "ssid");
#if defined(WIFI_DEBUG)
c_sprintf(debug_temp, " %-6d %-32s ", i, temp);
sprintf(debug_temp, " %-6d %-32s ", i, temp);
#endif
memset(temp, 0, sizeof(temp));
......@@ -699,13 +699,13 @@ static int wifi_station_get_ap_info4lua( lua_State* L )
lua_setfield(L, -2, "pwd");
}
#if defined(WIFI_DEBUG)
c_sprintf(debug_temp + strlen(debug_temp), "%-64s ", temp);
sprintf(debug_temp + strlen(debug_temp), "%-64s ", temp);
#endif
memset(temp, 0, sizeof(temp));
if (config[i].bssid_set)
{
c_sprintf(temp, MACSTR, MAC2STR(config[i].bssid));
sprintf(temp, MACSTR, MAC2STR(config[i].bssid));
lua_pushstring(L, temp);
lua_setfield(L, -2, "bssid");
}
......@@ -812,7 +812,7 @@ static int wifi_station_getconfig( lua_State* L, bool get_flash_cfg)
lua_setfield(L, -2, "bssid_set");
memset(temp, 0, sizeof(temp));
c_sprintf(temp, MACSTR, MAC2STR(sta_conf.bssid));
sprintf(temp, MACSTR, MAC2STR(sta_conf.bssid));
lua_pushstring( L, temp);
lua_setfield(L, -2, "bssid");
......@@ -827,7 +827,7 @@ static int wifi_station_getconfig( lua_State* L, bool get_flash_cfg)
memcpy(temp, sta_conf.password, sizeof(sta_conf.password));
lua_pushstring(L, temp);
lua_pushinteger( L, sta_conf.bssid_set);
c_sprintf(temp, MACSTR, MAC2STR(sta_conf.bssid));
sprintf(temp, MACSTR, MAC2STR(sta_conf.bssid));
lua_pushstring( L, temp);
return 4;
}
......@@ -1180,8 +1180,8 @@ static int wifi_station_listap( lua_State* L )
const char *ssidstr = luaL_checklstring( L, -1, &len );
if(len>32)
return luaL_error( L, "ssid:<32" );
c_memset(ssid, 0, 32);
c_memcpy(ssid, ssidstr, len);
memset(ssid, 0, 32);
memcpy(ssid, ssidstr, len);
scan_cfg.ssid=ssid;
NODE_DBG(scan_cfg.ssid);
NODE_DBG("\n");
......@@ -1199,7 +1199,7 @@ static int wifi_station_listap( lua_State* L )
{
const char *macaddr = luaL_checklstring( L, -1, &len );
luaL_argcheck(L, len==17, 1, INVALID_MAC_STR);
c_memset(bssid, 0, 6);
memset(bssid, 0, 6);
ets_str2macaddr(bssid, macaddr);
scan_cfg.bssid=bssid;
NODE_DBG(MACSTR, MAC2STR(scan_cfg.bssid));
......@@ -1401,7 +1401,7 @@ static int wifi_ap_deauth( lua_State* L )
}
else
{
c_memset(&mac, 0xFF, sizeof(mac));
memset(&mac, 0xFF, sizeof(mac));
}
lua_pushboolean(L,wifi_softap_deauth(mac));
return 1;
......@@ -1799,7 +1799,7 @@ static int wifi_ap_listclient( lua_State* L )
struct station_info * next_station;
while (station != NULL)
{
c_sprintf(temp, MACSTR, MAC2STR(station->bssid));
sprintf(temp, MACSTR, MAC2STR(station->bssid));
wifi_add_sprintf_field(L, temp, IPSTR, IP2STR(&station->ip));
station = STAILQ_NEXT(station, next);
}
......@@ -1833,9 +1833,9 @@ static int wifi_ap_dhcp_config( lua_State* L )
ip4_addr4(&lease.end_ip) += config.max_connection - 1;
char temp[64];
c_sprintf(temp, IPSTR, IP2STR(&lease.start_ip));
sprintf(temp, IPSTR, IP2STR(&lease.start_ip));
lua_pushstring(L, temp);
c_sprintf(temp, IPSTR, IP2STR(&lease.end_ip));
sprintf(temp, IPSTR, IP2STR(&lease.end_ip));
lua_pushstring(L, temp);
// note: DHCP max range = 101 from start_ip to end_ip
......@@ -1983,20 +1983,20 @@ void wifi_change_default_host_name(void)
wifi_get_macaddr(STATION_IF, mac);
#ifndef WIFI_STA_HOSTNAME
c_sprintf(temp, "NODE-%X%X%X", (mac)[3], (mac)[4], (mac)[5]);
sprintf(temp, "NODE-%X%X%X", (mac)[3], (mac)[4], (mac)[5]);
#elif defined(WIFI_STA_HOSTNAME) && !defined(WIFI_STA_HOSTNAME_APPEND_MAC)
if(wifi_sta_checkhostname(WIFI_STA_HOSTNAME, strlen(WIFI_STA_HOSTNAME))){
c_sprintf(temp, "%s", WIFI_STA_HOSTNAME);
sprintf(temp, "%s", WIFI_STA_HOSTNAME);
}
else{
c_sprintf(temp, "NODE-%X%X%X", (mac)[3], (mac)[4], (mac)[5]);
sprintf(temp, "NODE-%X%X%X", (mac)[3], (mac)[4], (mac)[5]);
}
#elif defined(WIFI_STA_HOSTNAME) && defined(WIFI_STA_HOSTNAME_APPEND_MAC)
if(strlen(WIFI_STA_HOSTNAME) <= 26 && wifi_sta_checkhostname(WIFI_STA_HOSTNAME, strlen(WIFI_STA_HOSTNAME))){
c_sprintf(temp, "%s%X%X%X", WIFI_STA_HOSTNAME, (mac)[3], (mac)[4], (mac)[5]);
sprintf(temp, "%s%X%X%X", WIFI_STA_HOSTNAME, (mac)[3], (mac)[4], (mac)[5]);
}
else{
c_sprintf(temp, "NODE-%X%X%X", (mac)[3], (mac)[4], (mac)[5]);
sprintf(temp, "NODE-%X%X%X", (mac)[3], (mac)[4], (mac)[5]);
}
#endif
......
......@@ -10,7 +10,7 @@ void wifi_add_sprintf_field(lua_State* L, char* name, char* string, ...)
char buffer[256];
va_list arglist;
va_start( arglist, string );
c_vsprintf( buffer, string, arglist );
vsprintf( buffer, string, arglist );
va_end( arglist );
lua_pushstring(L, buffer);
lua_setfield(L, -2, name);
......
......@@ -5,12 +5,11 @@
#include "lauxlib.h"
#include "platform.h"
#include "c_string.h"
#include "c_stdlib.h"
#include "c_types.h"
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include "user_interface.h"
#include "user_config.h"
#include "c_stdio.h"
#include "task/task.h"
//#define WIFI_DEBUG
......@@ -37,16 +36,16 @@ static inline void unregister_lua_cb(lua_State* L, int* cb_ref){
void wifi_change_default_host_name(void);
#if defined(WIFI_DEBUG) || defined(NODE_DEBUG)
#define WIFI_DBG(...) c_printf(__VA_ARGS__)
#define WIFI_DBG(...) printf(__VA_ARGS__)
#else
#define WIFI_DBG(...) //c_printf(__VA_ARGS__)
#define WIFI_DBG(...) //printf(__VA_ARGS__)
#endif
#if defined(EVENT_DEBUG) || defined(NODE_DEBUG)
#define EVENT_DBG(fmt, ...) c_printf("\n EVENT_DBG(%s): "fmt"\n", __FUNCTION__, ##__VA_ARGS__)
#define EVENT_DBG(fmt, ...) printf("\n EVENT_DBG(%s): "fmt"\n", __FUNCTION__, ##__VA_ARGS__)
#else
#define EVENT_DBG(...) //c_printf(__VA_ARGS__)
#define EVENT_DBG(...) //printf(__VA_ARGS__)
#endif
enum wifi_suspension_state{
......
......@@ -4,8 +4,8 @@
#include "lauxlib.h"
#include "platform.h"
#include "c_string.h"
#include "c_stdlib.h"
#include <string.h>
#include <stdlib.h>
#include "c_types.h"
#include "user_interface.h"
......@@ -82,7 +82,7 @@ static void wifi_event_monitor_handle_event_cb(System_Event_t *evt)
lua_rawgeti(L, LUA_REGISTRYINDEX, event_queue_ref);
System_Event_t* evt_tmp = lua_newuserdata(L, sizeof(System_Event_t));
c_memcpy(evt_tmp, evt, sizeof(System_Event_t)); //copy event data to new struct
memcpy(evt_tmp, evt, sizeof(System_Event_t)); //copy event data to new struct
sint32_t evt_ud_ref = luaL_ref(L, LUA_REGISTRYINDEX);
size_t queue_len = lua_objlen(L, -1);
......
......@@ -5,8 +5,8 @@
#include "lapi.h"
#include "platform.h"
#include "c_string.h"
#include "c_stdlib.h"
#include <string.h>
#include <stdlib.h>
#include "ctype.h"
#include "c_types.h"
......@@ -294,12 +294,12 @@ static void wifi_rx_cb(uint8 *buf, uint16 len) {
return;
}
packet_t *packet = (packet_t *) c_malloc(len + sizeof(packet_t));
packet_t *packet = (packet_t *) malloc(len + sizeof(packet_t));
if (packet) {
packet->len = len;
memcpy(packet->buf, buf, len);
if (!task_post_medium(tasknumber, (ETSParam) packet)) {
c_free(packet);
free(packet);
}
}
}
......@@ -320,11 +320,11 @@ static void monitor_task(os_param_t param, uint8_t prio)
luaL_getmetatable(L, "wifi.packet");
lua_setmetatable(L, -2);
c_free(input);
free(input);
lua_call(L, 1, 0);
} else {
c_free(input);
free(input);
}
}
......
#include "module.h"
#include "lauxlib.h"
#include "platform.h"
#include "c_stdlib.h"
#include "c_string.h"
#include <stdlib.h>
#include <string.h>
#include "osapi.h"
/**
* Code is based on https://github.com/CHERTS/esp8266-devkit/blob/master/Espressif/examples/EspLightNode/user/ws2801.c
......
......@@ -2,9 +2,9 @@
#include "lauxlib.h"
#include "lmem.h"
#include "platform.h"
#include "c_stdlib.h"
#include "c_math.h"
#include "c_string.h"
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include "user_interface.h"
#include "driver/uart.h"
#include "osapi.h"
......@@ -201,7 +201,7 @@ static int ws2812_new_buffer(lua_State *L) {
ws2812_buffer * buffer = allocate_buffer(L, leds, colorsPerLed);
c_memset(buffer->values, 0, colorsPerLed * leds);
memset(buffer->values, 0, colorsPerLed * leds);
return 1;
}
......@@ -295,7 +295,7 @@ int ws2812_buffer_shift(ws2812_buffer * buffer, int shiftValue, unsigned shift_t
return 0;
}
uint8_t * tmp_pixels = c_malloc(buffer->colorsPerLed * sizeof(uint8_t) * shift);
uint8_t * tmp_pixels = malloc(buffer->colorsPerLed * sizeof(uint8_t) * shift);
int i,j;
size_t shift_len, remaining_len;
// calculate length of shift section and remaining section
......@@ -305,37 +305,37 @@ int ws2812_buffer_shift(ws2812_buffer * buffer, int shiftValue, unsigned shift_t
if (shiftValue > 0)
{
// Store the values which are moved out of the array (last n pixels)
c_memcpy(tmp_pixels, &buffer->values[offset + (size-shift)*buffer->colorsPerLed], shift_len);
memcpy(tmp_pixels, &buffer->values[offset + (size-shift)*buffer->colorsPerLed], shift_len);
// Move pixels to end
os_memmove(&buffer->values[offset + shift*buffer->colorsPerLed], &buffer->values[offset], remaining_len);
// Fill beginning with temp data
if (shift_type == SHIFT_LOGICAL)
{
c_memset(&buffer->values[offset], 0, shift_len);
memset(&buffer->values[offset], 0, shift_len);
}
else
{
c_memcpy(&buffer->values[offset], tmp_pixels, shift_len);
memcpy(&buffer->values[offset], tmp_pixels, shift_len);
}
}
else
{
// Store the values which are moved out of the array (last n pixels)
c_memcpy(tmp_pixels, &buffer->values[offset], shift_len);
memcpy(tmp_pixels, &buffer->values[offset], shift_len);
// Move pixels to end
os_memmove(&buffer->values[offset], &buffer->values[offset + shift*buffer->colorsPerLed], remaining_len);
// Fill beginning with temp data
if (shift_type == SHIFT_LOGICAL)
{
c_memset(&buffer->values[offset + (size-shift)*buffer->colorsPerLed], 0, shift_len);
memset(&buffer->values[offset + (size-shift)*buffer->colorsPerLed], 0, shift_len);
}
else
{
c_memcpy(&buffer->values[offset + (size-shift)*buffer->colorsPerLed], tmp_pixels, shift_len);
memcpy(&buffer->values[offset + (size-shift)*buffer->colorsPerLed], tmp_pixels, shift_len);
}
}
// Free memory
c_free(tmp_pixels);
free(tmp_pixels);
return 0;
}
......@@ -386,7 +386,7 @@ static int ws2812_buffer_replace(lua_State* L) {
luaL_argcheck(L, srcLen + start - 1 <= buffer->size, 2, "Does not fit into destination");
c_memcpy(buffer->values + (start - 1) * buffer->colorsPerLed, src, srcLen * buffer->colorsPerLed);
memcpy(buffer->values + (start - 1) * buffer->colorsPerLed, src, srcLen * buffer->colorsPerLed);
return 0;
}
......@@ -504,7 +504,7 @@ static int ws2812_buffer_set(lua_State* L) {
return luaL_error(L, "string size will exceed strip length");
}
c_memcpy(&buffer->values[buffer->colorsPerLed*led], buf, len);
memcpy(&buffer->values[buffer->colorsPerLed*led], buf, len);
}
else
{
......@@ -535,7 +535,7 @@ static int ws2812_buffer_sub(lua_State* L) {
if (end > (ptrdiff_t)l) end = (ptrdiff_t)l;
if (start <= end) {
ws2812_buffer *result = allocate_buffer(L, end - start + 1, lhs->colorsPerLed);
c_memcpy(result->values, lhs->values + lhs->colorsPerLed * (start - 1), lhs->colorsPerLed * (end - start + 1));
memcpy(result->values, lhs->values + lhs->colorsPerLed * (start - 1), lhs->colorsPerLed * (end - start + 1));
} else {
ws2812_buffer *result = allocate_buffer(L, 0, lhs->colorsPerLed);
}
......@@ -553,8 +553,8 @@ static int ws2812_buffer_concat(lua_State* L) {
ws2812_buffer * buffer = allocate_buffer(L, leds, colorsPerLed);
c_memcpy(buffer->values, lhs->values, lhs->colorsPerLed * lhs->size);
c_memcpy(buffer->values + lhs->colorsPerLed * lhs->size, rhs->values, rhs->colorsPerLed * rhs->size);
memcpy(buffer->values, lhs->values, lhs->colorsPerLed * lhs->size);
memcpy(buffer->values + lhs->colorsPerLed * lhs->size, rhs->values, rhs->colorsPerLed * rhs->size);
return 1;
}
......@@ -579,7 +579,7 @@ static int ws2812_buffer_tostring(lua_State* L) {
luaL_addchar(&result, ',');
}
char numbuf[5];
c_sprintf(numbuf, "%d", buffer->values[p]);
sprintf(numbuf, "%d", buffer->values[p]);
luaL_addstring(&result, numbuf);
}
luaL_addchar(&result, ')');
......
......@@ -5,9 +5,9 @@
#include "lauxlib.h"
#include "lmem.h"
#include "platform.h"
#include "c_stdlib.h"
#include "c_math.h"
#include "c_string.h"
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include "user_interface.h"
#include "driver/uart.h"
#include "osapi.h"
......
......@@ -2,9 +2,9 @@
#include "lauxlib.h"
#include "lmem.h"
#include "platform.h"
#include "c_stdlib.h"
#include "c_math.h"
#include "c_string.h"
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include "user_interface.h"
#include "driver/uart.h"
#include "osapi.h"
......@@ -18,8 +18,6 @@
#define DEFAULT_MODE 0
#define DEFAULT_COLOR 0xFF0000
#define UINT32_MAX 4294967295U
#define SPEED_MIN 0
#define SPEED_MAX 255
#define SPEED_DEFAULT 150
......@@ -161,11 +159,11 @@ static int ws2812_effects_init(lua_State *L) {
// get rid of old state
if (state != NULL) {
luaL_unref(L, LUA_REGISTRYINDEX, state->buffer_ref);
os_free((void *) state);
free((void *) state);
}
// Allocate memory and set all to zero
size_t size = sizeof(ws2812_effects) + buffer->colorsPerLed*sizeof(uint8_t);
state = (ws2812_effects *) os_zalloc(size);
state = (ws2812_effects *) calloc(1,size);
// initialize
state->speed = SPEED_DEFAULT;
state->mode_delay = DELAY_DEFAULT;
......@@ -307,7 +305,7 @@ static int ws2812_effects_mode_blink() {
else {
// off
ws2812_buffer * buffer = state->buffer;
c_memset(&buffer->values[0], 0, buffer->size * buffer->colorsPerLed);
memset(&buffer->values[0], 0, buffer->size * buffer->colorsPerLed);
}
return 0;
}
......
......@@ -29,7 +29,7 @@
*
*/
#include "c_string.h"
#include <string.h>
#include "mqtt_msg.h"
#define MQTT_MAX_FIXED_HEADER_SIZE 3
......@@ -61,7 +61,7 @@ static int append_string(mqtt_connection_t* connection, const char* string, int
connection->buffer[connection->message.length++] = len >> 8;
connection->buffer[connection->message.length++] = len & 0xff;
c_memcpy(connection->buffer + connection->message.length, string, len);
memcpy(connection->buffer + connection->message.length, string, len);
connection->message.length += len;
return len + 2;
......@@ -121,7 +121,7 @@ static mqtt_message_t* fini_message(mqtt_connection_t* connection, int type, int
void mqtt_msg_init(mqtt_connection_t* connection, uint8_t* buffer, uint16_t buffer_length)
{
c_memset(connection, 0, sizeof(connection));
memset(connection, 0, sizeof(connection));
connection->buffer = buffer;
connection->buffer_length = buffer_length;
}
......@@ -299,7 +299,7 @@ mqtt_message_t* mqtt_msg_connect(mqtt_connection_t* connection, mqtt_connect_inf
variable_header->lengthMsb = 0;
variable_header->lengthLsb = 4;
c_memcpy(variable_header->magic, "MQTT", 4);
memcpy(variable_header->magic, "MQTT", 4);
variable_header->version = 4;
variable_header->flags = 0;
variable_header->keepaliveMsb = info->keepalive >> 8;
......@@ -310,7 +310,7 @@ mqtt_message_t* mqtt_msg_connect(mqtt_connection_t* connection, mqtt_connect_inf
if(info->client_id != NULL && info->client_id[0] != '\0')
{
if(append_string(connection, info->client_id, c_strlen(info->client_id)) < 0)
if(append_string(connection, info->client_id, strlen(info->client_id)) < 0)
return fail_message(connection);
}
else
......@@ -318,10 +318,10 @@ mqtt_message_t* mqtt_msg_connect(mqtt_connection_t* connection, mqtt_connect_inf
if(info->will_topic != NULL && info->will_topic[0] != '\0')
{
if(append_string(connection, info->will_topic, c_strlen(info->will_topic)) < 0)
if(append_string(connection, info->will_topic, strlen(info->will_topic)) < 0)
return fail_message(connection);
if(append_string(connection, info->will_message, c_strlen(info->will_message)) < 0)
if(append_string(connection, info->will_message, strlen(info->will_message)) < 0)
return fail_message(connection);
variable_header->flags |= MQTT_CONNECT_FLAG_WILL;
......@@ -332,7 +332,7 @@ mqtt_message_t* mqtt_msg_connect(mqtt_connection_t* connection, mqtt_connect_inf
if(info->username != NULL && info->username[0] != '\0')
{
if(append_string(connection, info->username, c_strlen(info->username)) < 0)
if(append_string(connection, info->username, strlen(info->username)) < 0)
return fail_message(connection);
variable_header->flags |= MQTT_CONNECT_FLAG_USERNAME;
......@@ -340,7 +340,7 @@ mqtt_message_t* mqtt_msg_connect(mqtt_connection_t* connection, mqtt_connect_inf
if(info->password != NULL && info->password[0] != '\0')
{
if(append_string(connection, info->password, c_strlen(info->password)) < 0)
if(append_string(connection, info->password, strlen(info->password)) < 0)
return fail_message(connection);
variable_header->flags |= MQTT_CONNECT_FLAG_PASSWORD;
......@@ -356,7 +356,7 @@ mqtt_message_t* mqtt_msg_publish(mqtt_connection_t* connection, const char* topi
if(topic == NULL || topic[0] == '\0')
return fail_message(connection);
if(append_string(connection, topic, c_strlen(topic)) < 0)
if(append_string(connection, topic, strlen(topic)) < 0)
return fail_message(connection);
if(qos > 0)
......@@ -369,7 +369,7 @@ mqtt_message_t* mqtt_msg_publish(mqtt_connection_t* connection, const char* topi
if(connection->message.length + data_length > connection->buffer_length)
return fail_message(connection);
c_memcpy(connection->buffer + connection->message.length, data, data_length);
memcpy(connection->buffer + connection->message.length, data, data_length);
connection->message.length += data_length;
return fini_message(connection, MQTT_MSG_TYPE_PUBLISH, 0, qos, retain);
......@@ -422,7 +422,7 @@ mqtt_message_t* mqtt_msg_subscribe_topic(mqtt_connection_t* connection, const ch
if(topic == NULL || topic[0] == '\0')
return fail_message(connection);
if(append_string(connection, topic, c_strlen(topic)) < 0)
if(append_string(connection, topic, strlen(topic)) < 0)
return fail_message(connection);
if(connection->message.length + 1 > connection->buffer_length)
......@@ -462,7 +462,7 @@ mqtt_message_t* mqtt_msg_unsubscribe_topic(mqtt_connection_t* connection, const
if(topic == NULL || topic[0] == '\0')
return fail_message(connection);
if(append_string(connection, topic, c_strlen(topic)) < 0)
if(append_string(connection, topic, strlen(topic)) < 0)
return fail_message(connection);
return &connection->message;
......
#include "c_string.h"
#include "c_stdlib.h"
#include "c_stdio.h"
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include "msg_queue.h"
#include "user_config.h"
msg_queue_t *msg_enqueue(msg_queue_t **head, mqtt_message_t *msg, uint16_t msg_id, int msg_type, int publish_qos){
if(!head){
......@@ -11,19 +12,19 @@ msg_queue_t *msg_enqueue(msg_queue_t **head, mqtt_message_t *msg, uint16_t msg_i
NODE_DBG("empty message\n");
return NULL;
}
msg_queue_t *node = (msg_queue_t *)c_zalloc(sizeof(msg_queue_t));
msg_queue_t *node = (msg_queue_t *)calloc(1,sizeof(msg_queue_t));
if(!node){
NODE_DBG("not enough memory\n");
return NULL;
}
node->msg.data = (uint8_t *)c_zalloc(msg->length);
node->msg.data = (uint8_t *)calloc(1,msg->length);
if(!node->msg.data){
NODE_DBG("not enough memory\n");
c_free(node);
free(node);
return NULL;
}
c_memcpy(node->msg.data, msg->data, msg->length);
memcpy(node->msg.data, msg->data, msg->length);
node->msg.length = msg->length;
node->next = NULL;
node->msg_id = msg_id;
......@@ -43,10 +44,10 @@ msg_queue_t *msg_enqueue(msg_queue_t **head, mqtt_message_t *msg, uint16_t msg_i
void msg_destroy(msg_queue_t *node){
if(!node) return;
if(node->msg.data){
c_free(node->msg.data);
free(node->msg.data);
node->msg.data = NULL;
}
c_free(node);
free(node);
}
msg_queue_t * msg_dequeue(msg_queue_t **head){
......
......@@ -48,7 +48,7 @@
#include "osapi.h"
#include "os_type.h"
#include "user_interface.h"
#include "c_string.h"
#include <string.h>
#include "nodemcu_mdns.h"
#if 0
......@@ -484,7 +484,7 @@ mdns_send_service(struct nodemcu_mdns_info *info, u16_t id, struct ip_addr *dst_
hdr->numextrarr = htons(1);
query = (char*) hdr + SIZEOF_DNS_HDR;
query_end = (char *) p->payload + p->tot_len;
c_strlcpy(tmpBuf, service_name_with_suffix, sizeof(tmpBuf));
strlcpy(tmpBuf, service_name_with_suffix, sizeof(tmpBuf));
pHostname = tmpBuf;
--pHostname;
......@@ -618,9 +618,9 @@ mdns_send_service(struct nodemcu_mdns_info *info, u16_t id, struct ip_addr *dst_
ans.type = htons(DNS_RRTYPE_SRV);
ans.class = htons(dns_class);
ans.ttl = htonl(min(max_ttl, 300));
c_strlcpy(tmpBuf,ms_info->host_name, sizeof(tmpBuf));
c_strlcat(tmpBuf, ".", sizeof(tmpBuf));
c_strlcat(tmpBuf, MDNS_LOCAL, sizeof(tmpBuf));
strlcpy(tmpBuf,ms_info->host_name, sizeof(tmpBuf));
strlcat(tmpBuf, ".", sizeof(tmpBuf));
strlcat(tmpBuf, MDNS_LOCAL, sizeof(tmpBuf));
length = os_strlen(tmpBuf) + MDNS_LENGTH_ADD;
ans.len = htons(SIZEOF_MDNS_SERVICE + length);
length = 0;
......@@ -931,9 +931,9 @@ mdns_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, struct ip_addr *addr,
actual_rr = DNS_RRTYPE_PTR;
}
} else {
c_strlcpy(tmpBuf,ms_info->host_name, sizeof(tmpBuf));
c_strlcat(tmpBuf, ".", sizeof(tmpBuf));
c_strlcat(tmpBuf, MDNS_LOCAL, sizeof(tmpBuf));
strlcpy(tmpBuf,ms_info->host_name, sizeof(tmpBuf));
strlcat(tmpBuf, ".", sizeof(tmpBuf));
strlcat(tmpBuf, MDNS_LOCAL, sizeof(tmpBuf));
no_rr_name = tmpBuf;
if (mdns_compare_name((unsigned char *) tmpBuf,
......@@ -944,9 +944,9 @@ mdns_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, struct ip_addr *addr,
actual_rr = DNS_RRTYPE_A;
}
} else {
c_strlcpy(tmpBuf,ms_info->host_desc, sizeof(tmpBuf));
c_strlcat(tmpBuf, ".", sizeof(tmpBuf));
c_strlcat(tmpBuf, service_name_with_suffix, sizeof(tmpBuf));
strlcpy(tmpBuf,ms_info->host_desc, sizeof(tmpBuf));
strlcat(tmpBuf, ".", sizeof(tmpBuf));
strlcat(tmpBuf, service_name_with_suffix, sizeof(tmpBuf));
if (mdns_compare_name((unsigned char *) tmpBuf,
(unsigned char *) qptr, (unsigned char *) hdr) == 0) {
if (qry_type == DNS_RRTYPE_TXT || qry_type == DNS_RRTYPE_SRV || qry_type == DNS_RRTYPE_ANY) {
......@@ -1003,7 +1003,7 @@ mdns_set_servicename(const char *name) {
if (service_name_with_suffix) {
os_free(service_name_with_suffix);
}
service_name_with_suffix = c_strdup(tmpBuf);
service_name_with_suffix = strdup(tmpBuf);
}
static u8_t reg_counter;
......@@ -1029,15 +1029,15 @@ mdns_dup_info(const struct nodemcu_mdns_info *info) {
// calculate length
int len = sizeof(struct nodemcu_mdns_info);
len += c_strlen(info->host_name) + 1;
len += c_strlen(info->host_desc) + 1;
len += c_strlen(info->service_name) + 1;
len += strlen(info->host_name) + 1;
len += strlen(info->host_desc) + 1;
len += strlen(info->service_name) + 1;
int i;
for (i = 0; i < sizeof(info->txt_data) / sizeof(info->txt_data[0]) && info->txt_data[i]; i++) {
len += c_strlen(info->txt_data[i]) + 1;
len += strlen(info->txt_data[i]) + 1;
}
#define COPY_OVER(dest, src, p) len = c_strlen(src) + 1; memcpy(p, src, len); dest = p; p += len
#define COPY_OVER(dest, src, p) len = strlen(src) + 1; memcpy(p, src, len); dest = p; p += len
result = (struct nodemcu_mdns_info *) os_zalloc(len);
if (result) {
......
......@@ -5,7 +5,7 @@
#include "platform.h"
#include "hw_timer.h"
#include "task/task.h"
#include "c_stdlib.h"
#include <stdlib.h>
#include "pcm.h"
......
......@@ -13,8 +13,8 @@
#include "lauxlib.h"
#include "task/task.h"
#include "c_string.h"
#include "c_stdlib.h"
#include <string.h>
#include <stdlib.h>
#include "pcm.h"
......@@ -58,9 +58,9 @@ void pcm_data_play( task_param_t param, uint8 prio )
if (lua_type( L, -1 ) == LUA_TSTRING) {
data = lua_tolstring( L, -1, &string_len );
if (string_len > buf->buf_size) {
uint8_t *new_data = (uint8_t *) c_malloc( string_len );
uint8_t *new_data = (uint8_t *) malloc( string_len );
if (new_data) {
if (buf->data) c_free( buf->data );
if (buf->data) free( buf->data );
buf->buf_size = string_len;
buf->data = new_data;
}
......@@ -70,7 +70,7 @@ void pcm_data_play( task_param_t param, uint8 prio )
if (data) {
size_t to_copy = string_len > buf->buf_size ? buf->buf_size : string_len;
c_memcpy( buf->data, data, to_copy );
memcpy( buf->data, data, to_copy );
buf->rpos = 0;
buf->len = to_copy;
......
......@@ -2,8 +2,8 @@
#include "platform.h"
#include "common.h"
#include "c_string.h"
#include "c_stdio.h"
#include <string.h>
#include <stdio.h>
void cmn_platform_init(void)
{
......@@ -102,7 +102,7 @@ uint32_t platform_flash_write( const void *from, uint32_t toaddr, uint32_t size
{
rest = toaddr & blkmask;
temp = toaddr & ~blkmask; // this is the actual aligned address
// c_memcpy( tmpdata, ( const void* )temp, blksize );
// memcpy( tmpdata, ( const void* )temp, blksize );
platform_s_flash_read( tmpdata, temp, blksize );
for( i = rest; size && ( i < blksize ); i ++, size --, pfrom ++ )
tmpdata[ i ] = *pfrom;
......@@ -125,7 +125,7 @@ uint32_t platform_flash_write( const void *from, uint32_t toaddr, uint32_t size
// And the final part of a block if needed
if( rest )
{
// c_memcpy( tmpdata, ( const void* )toaddr, blksize );
// memcpy( tmpdata, ( const void* )toaddr, blksize );
platform_s_flash_read( tmpdata, toaddr, blksize );
for( i = 0; size && ( i < rest ); i ++, size --, pfrom ++ )
tmpdata[ i ] = *pfrom;
......
......@@ -6,7 +6,8 @@
#include "user_config.h"
#include "flash_api.h"
#include "spi_flash.h"
#include "c_stdio.h"
#include <stdio.h>
#include <string.h>
uint32_t flash_detect_size_byte(void)
{
......@@ -25,7 +26,7 @@ uint32_t flash_detect_size_byte(void)
dummy_size = FLASH_SIZE_256KBYTE;
while ((dummy_size < FLASH_SIZE_16MBYTE) &&
(SPI_FLASH_RESULT_OK == flash_read(dummy_size, (uint32 *)data_new, FLASH_BUFFER_SIZE_DETECT)) &&
(0 != os_memcmp(data_orig, data_new, FLASH_BUFFER_SIZE_DETECT))
(0 != memcmp(data_orig, data_new, FLASH_BUFFER_SIZE_DETECT))
)
{
dummy_size *= 2;
......
......@@ -17,8 +17,8 @@
* a small numeric value that is known not to clash.
*******************************************************************************/
#include "platform.h"
#include "c_stdio.h"
#include "c_stdlib.h"
#include <stdio.h>
#include <stdlib.h>
#include "ets_sys.h"
#include "os_type.h"
#include "osapi.h"
......@@ -444,7 +444,7 @@ bool platform_hw_timer_init(os_param_t owner, FRC1_TIMER_SOURCE_TYPE source_type
timer_user *tu = find_tu_and_remove(owner);
if (!tu) {
tu = (timer_user *) c_malloc(sizeof(*tu));
tu = (timer_user *) malloc(sizeof(*tu));
if (!tu) {
return false;
}
......
......@@ -2,9 +2,9 @@
#include "platform.h"
#include "common.h"
#include "c_stdio.h"
#include "c_string.h"
#include "c_stdlib.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "llimits.h"
#include "gpio.h"
#include "user_interface.h"
......@@ -320,7 +320,7 @@ int platform_gpio_register_intr_hook(uint32_t bits, platform_hook_function hook)
}
// These return NULL if the count = 0 so only error check if > 0)
nh.entry = c_malloc( nh.count * sizeof(*(nh.entry)) );
nh.entry = malloc( nh.count * sizeof(*(nh.entry)) );
if (nh.count && !(nh.entry)) {
return 0; // Allocation failure
}
......@@ -345,7 +345,7 @@ int platform_gpio_register_intr_hook(uint32_t bits, platform_hook_function hook)
platform_gpio_hook = nh;
ETS_GPIO_INTR_ENABLE();
c_free(oh.entry);
free(oh.entry);
return 1;
}
#endif // GPIO_INTERRUPT_HOOK_ENABLE
......@@ -865,15 +865,15 @@ uint32_t platform_s_flash_write( const void *from, uint32_t toaddr, uint32_t siz
uint32_t *apbuf = NULL;
uint32_t fromaddr = (uint32_t)from;
if( (fromaddr & blkmask ) || (fromaddr >= INTERNAL_FLASH_MAPPED_ADDRESS)) {
apbuf = (uint32_t *)c_malloc(size);
apbuf = (uint32_t *)malloc(size);
if(!apbuf)
return 0;
c_memcpy(apbuf, from, size);
memcpy(apbuf, from, size);
}
system_soft_wdt_feed ();
r = flash_write(toaddr, apbuf?(uint32 *)apbuf:(uint32 *)from, size);
if(apbuf)
c_free(apbuf);
free(apbuf);
if(SPI_FLASH_RESULT_OK == r)
return size;
else{
......@@ -903,10 +903,10 @@ uint32_t platform_s_flash_read( void *to, uint32_t fromaddr, uint32_t size )
r = flash_read(fromaddr, to2, size2);
if(SPI_FLASH_RESULT_OK == r)
{
c_memmove(to,to2,size2); // This is overlapped so must be memmove and not memcpy
memmove(to,to2,size2); // This is overlapped so must be memmove and not memcpy
char back[ INTERNAL_FLASH_READ_UNIT_SIZE ] __attribute__ ((aligned(INTERNAL_FLASH_READ_UNIT_SIZE)));
r=flash_read(fromaddr+size2,(uint32*)back,INTERNAL_FLASH_READ_UNIT_SIZE);
c_memcpy((uint8_t*)to+size2,back,INTERNAL_FLASH_READ_UNIT_SIZE);
memcpy((uint8_t*)to+size2,back,INTERNAL_FLASH_READ_UNIT_SIZE);
}
}
else
......@@ -1022,7 +1022,7 @@ uint32_t platform_rcr_write (uint8_t rec_id, const void *inrec, uint8_t n) {
rec[0] = 0; rec[nwords] = 0;
((platform_rcr_t *) rec)->id = rec_id;
((platform_rcr_t *) rec)->len = nwords;
c_memcpy(rec+1, inrec, n); // let memcpy handle 0 and odd byte cases
memcpy(rec+1, inrec, n); // let memcpy handle 0 and odd byte cases
// find previous copy if any and exit if the replacement is the same value
uint8_t np = platform_rcr_read (rec_id, (void **) &prev);
......@@ -1063,19 +1063,19 @@ uint32_t platform_rcr_write (uint8_t rec_id, const void *inrec, uint8_t n) {
}
if (pass == 2) memcpy(buf + l, rec, reclen);
l += nwords + 1;
if (pass == 1) buf = c_malloc(l * WORDSIZE);
if (pass == 1) buf = malloc(l * WORDSIZE);
if (l >= FLASH_SECTOR_WORDS || !buf)
return ~0;
}
platform_flash_erase_sector(flash_addr/INTERNAL_FLASH_SECTOR_SIZE);
platform_s_flash_write(buf, flash_addr, l*WORDSIZE);
c_free(buf);
free(buf);
}
return nwords*WORDSIZE;
}
void* platform_print_deprecation_note( const char *msg, const char *time_frame)
{
c_printf( "Warning, deprecated API! %s. It will be removed %s. See documentation for details.\n", msg, time_frame );
printf( "Warning, deprecated API! %s. It will be removed %s. See documentation for details.\n", msg, time_frame );
}
......@@ -6,7 +6,7 @@
#ifdef LUA_USE_MODULES_U8G2
#include <string.h>
#include "c_stdlib.h"
#include <stdlib.h>
#include "platform.h"
......@@ -189,7 +189,7 @@ uint8_t u8x8_byte_nodemcu_i2c(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *
{
// the user pointer initially contains the i2c id
int id = (int)hal;
if (!(hal = c_malloc( sizeof ( hal_i2c_t ) )))
if (!(hal = malloc( sizeof ( hal_i2c_t ) )))
return 0;
hal->id = id;
u8x8->user_ptr = hal;
......@@ -240,7 +240,7 @@ uint8_t u8x8_byte_nodemcu_spi(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *
// the user pointer initially contains the spi host id
int host = (int)hal;
if (!(hal = c_malloc( sizeof ( hal_spi_t ) )))
if (!(hal = malloc( sizeof ( hal_spi_t ) )))
return 0;
hal->host = host;
u8x8->user_ptr = hal;
......@@ -260,7 +260,7 @@ uint8_t u8x8_byte_nodemcu_spi(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *
case U8X8_MSG_BYTE_START_TRANSFER:
hal->buffer.size = 256;
if (!(hal->buffer.data = (uint8_t *)c_malloc( hal->buffer.size )))
if (!(hal->buffer.data = (uint8_t *)malloc( hal->buffer.size )))
return 0;
hal->buffer.used = 0;
......@@ -274,13 +274,13 @@ uint8_t u8x8_byte_nodemcu_spi(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *
while (hal->buffer.size - hal->buffer.used < arg_int) {
hal->buffer.size *= 2;
uint8_t *tmp;
if (!(tmp = (uint8_t *)c_malloc( hal->buffer.size ))) {
c_free( hal->buffer.data );
if (!(tmp = (uint8_t *)malloc( hal->buffer.size ))) {
free( hal->buffer.data );
hal->buffer.data = NULL;
return 0;
}
os_memcpy( tmp, hal->buffer.data, hal->buffer.used );
c_free( hal->buffer.data );
free( hal->buffer.data );
hal->buffer.data = tmp;
}
os_memcpy( hal->buffer.data + hal->buffer.used, arg_ptr, arg_int );
......@@ -295,7 +295,7 @@ uint8_t u8x8_byte_nodemcu_spi(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *
u8x8_gpio_SetCS( u8x8, u8x8->display_info->chip_disable_level );
c_free( hal->buffer.data );
free( hal->buffer.data );
hal->buffer.data = NULL;
break;
......
......@@ -5,7 +5,7 @@
#ifdef LUA_USE_MODULES_UCG
#include <string.h>
#include "c_stdlib.h"
#include <stdlib.h>
#include "platform.h"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment