Commit e49f2bb1 authored by Johny Mattsson's avatar Johny Mattsson
Browse files

Remove conflicting libc, rename c_xx and os_xx to xx.

c_strtod and c_getenv are kept since strtod doesn't appear in the SDK's libc,
and we want our own c_getenv to initialize the Lua main anyway.
parent 3a3e9ee0
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
#include "module.h" #include "module.h"
#include "c_limits.h" #include <limits.h>
#include "lauxlib.h" #include "lauxlib.h"
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
#include "module.h" #include "module.h"
#include "lauxlib.h" #include "lauxlib.h"
#include "platform.h" #include "platform.h"
#include "c_math.h" #include <math.h>
#include "user_interface.h" #include "user_interface.h"
/****************************************************/ /****************************************************/
......
#include "module.h" #include "module.h"
#include "lauxlib.h" #include "lauxlib.h"
#include "platform.h" #include "platform.h"
#include "c_stdlib.h" #include <stdlib.h>
#include "c_string.h" #include <string.h>
#include "esp_misc.h" #include "esp_misc.h"
static const uint32_t bmp085_i2c_id = 0; static const uint32_t bmp085_i2c_id = 0;
......
...@@ -38,9 +38,9 @@ ...@@ -38,9 +38,9 @@
// #include <assert.h> // #include <assert.h>
#include "module.h" #include "module.h"
#include "c_string.h" #include <string.h>
#include "c_math.h" #include <math.h>
#include "c_limits.h" #include <limits.h>
#include "lauxlib.h" #include "lauxlib.h"
#include "flash_api.h" #include "flash_api.h"
#include "ctype.h" #include "ctype.h"
...@@ -340,7 +340,7 @@ static int json_integer_option(lua_State *l, int optindex, int *setting, ...@@ -340,7 +340,7 @@ static int json_integer_option(lua_State *l, int optindex, int *setting,
if (!lua_isnil(l, optindex)) { if (!lua_isnil(l, optindex)) {
value = luaL_checkinteger(l, optindex); value = luaL_checkinteger(l, optindex);
c_sprintf(errmsg, "expected integer between %d and %d", min, max); sprintf(errmsg, "expected integer between %d and %d", min, max);
luaL_argcheck(l, min <= value && value <= max, 1, errmsg); luaL_argcheck(l, min <= value && value <= max, 1, errmsg);
*setting = value; *setting = value;
} }
...@@ -774,8 +774,8 @@ static void json_append_number(lua_State *l, json_config_t *cfg, ...@@ -774,8 +774,8 @@ static void json_append_number(lua_State *l, json_config_t *cfg,
strbuf_ensure_empty_length(json, FPCONV_G_FMT_BUFSIZE); strbuf_ensure_empty_length(json, FPCONV_G_FMT_BUFSIZE);
// len = fpconv_g_fmt(strbuf_empty_ptr(json), num, cfg->encode_number_precision); // len = fpconv_g_fmt(strbuf_empty_ptr(json), num, cfg->encode_number_precision);
c_sprintf(strbuf_empty_ptr(json), LUA_NUMBER_FMT, (LUA_NUMBER)num); sprintf(strbuf_empty_ptr(json), LUA_NUMBER_FMT, (LUA_NUMBER)num);
len = c_strlen(strbuf_empty_ptr(json)); len = strlen(strbuf_empty_ptr(json));
strbuf_extend_length(json, len); strbuf_extend_length(json, len);
} }
...@@ -1148,7 +1148,7 @@ static int json_is_invalid_number(json_parse_t *json) ...@@ -1148,7 +1148,7 @@ static int json_is_invalid_number(json_parse_t *json)
return 0; /* Ordinary number */ return 0; /* Ordinary number */
} }
char tmp[4]; // conv to lower. because c_strncasecmp == c_strcmp char tmp[4]; // conv to lower. because strncasecmp == strcmp
int i; int i;
for (i = 0; i < 3; ++i) for (i = 0; i < 3; ++i)
{ {
...@@ -1160,9 +1160,9 @@ static int json_is_invalid_number(json_parse_t *json) ...@@ -1160,9 +1160,9 @@ static int json_is_invalid_number(json_parse_t *json)
tmp[3] = 0; tmp[3] = 0;
/* Reject inf/nan */ /* Reject inf/nan */
if (!c_strncasecmp(tmp, "inf", 3)) if (!strncasecmp(tmp, "inf", 3))
return 1; return 1;
if (!c_strncasecmp(tmp, "nan", 3)) if (!strncasecmp(tmp, "nan", 3))
return 1; return 1;
/* Pass all other numbers which may still be invalid, but /* Pass all other numbers which may still be invalid, but
...@@ -1238,17 +1238,17 @@ static void json_next_token(json_parse_t *json, json_token_t *token) ...@@ -1238,17 +1238,17 @@ static void json_next_token(json_parse_t *json, json_token_t *token)
} }
json_next_number_token(json, token); json_next_number_token(json, token);
return; return;
} else if (!c_strncmp(json->ptr, "true", 4)) { } else if (!strncmp(json->ptr, "true", 4)) {
token->type = T_BOOLEAN; token->type = T_BOOLEAN;
token->value.boolean = 1; token->value.boolean = 1;
json->ptr += 4; json->ptr += 4;
return; return;
} else if (!c_strncmp(json->ptr, "false", 5)) { } else if (!strncmp(json->ptr, "false", 5)) {
token->type = T_BOOLEAN; token->type = T_BOOLEAN;
token->value.boolean = 0; token->value.boolean = 0;
json->ptr += 5; json->ptr += 5;
return; return;
} else if (!c_strncmp(json->ptr, "null", 4)) { } else if (!strncmp(json->ptr, "null", 4)) {
token->type = T_NULL; token->type = T_NULL;
json->ptr += 4; json->ptr += 4;
return; return;
......
...@@ -4,8 +4,8 @@ ...@@ -4,8 +4,8 @@
#include "lauxlib.h" #include "lauxlib.h"
#include "platform.h" #include "platform.h"
#include "c_string.h" #include <string.h>
#include "c_stdlib.h" #include <stdlib.h>
#include "c_types.h" #include "c_types.h"
#include "mem.h" #include "mem.h"
...@@ -38,13 +38,13 @@ static void coap_received(void *arg, char *pdata, unsigned short len) ...@@ -38,13 +38,13 @@ static void coap_received(void *arg, char *pdata, unsigned short len)
// static uint8_t buf[MAX_MESSAGE_SIZE+1] = {0}; // +1 for string '\0' // static uint8_t buf[MAX_MESSAGE_SIZE+1] = {0}; // +1 for string '\0'
uint8_t buf[MAX_MESSAGE_SIZE+1] = {0}; // +1 for string '\0' uint8_t buf[MAX_MESSAGE_SIZE+1] = {0}; // +1 for string '\0'
c_memset(buf, 0, sizeof(buf)); // wipe prev data memset(buf, 0, sizeof(buf)); // wipe prev data
if (len > MAX_MESSAGE_SIZE) { if (len > MAX_MESSAGE_SIZE) {
NODE_DBG("Request Entity Too Large.\n"); // NOTE: should response 4.13 to client... NODE_DBG("Request Entity Too Large.\n"); // NOTE: should response 4.13 to client...
return; return;
} }
// c_memcpy(buf, pdata, len); // memcpy(buf, pdata, len);
size_t rsplen = coap_server_respond(pdata, len, buf, MAX_MESSAGE_SIZE+1); size_t rsplen = coap_server_respond(pdata, len, buf, MAX_MESSAGE_SIZE+1);
...@@ -53,12 +53,12 @@ static void coap_received(void *arg, char *pdata, unsigned short len) ...@@ -53,12 +53,12 @@ static void coap_received(void *arg, char *pdata, unsigned short len)
if (espconn_get_connection_info (pesp_conn, &pr, 0) != ESPCONN_OK) if (espconn_get_connection_info (pesp_conn, &pr, 0) != ESPCONN_OK)
return; return;
pesp_conn->proto.udp->remote_port = pr->remote_port; pesp_conn->proto.udp->remote_port = pr->remote_port;
os_memmove (pesp_conn->proto.udp->remote_ip, pr->remote_ip, 4); memmove (pesp_conn->proto.udp->remote_ip, pr->remote_ip, 4);
// The remot_info apparently should *not* be os_free()d, fyi // The remot_info apparently should *not* be free()d, fyi
espconn_sent(pesp_conn, (unsigned char *)buf, rsplen); espconn_sent(pesp_conn, (unsigned char *)buf, rsplen);
// c_memset(buf, 0, sizeof(buf)); // memset(buf, 0, sizeof(buf));
} }
static void coap_sent(void *arg) static void coap_sent(void *arg)
...@@ -85,7 +85,7 @@ static int coap_create( lua_State* L, const char* mt ) ...@@ -85,7 +85,7 @@ static int coap_create( lua_State* L, const char* mt )
lua_setmetatable(L, -2); lua_setmetatable(L, -2);
// create the espconn struct // create the espconn struct
pesp_conn = (struct espconn *)c_zalloc(sizeof(struct espconn)); pesp_conn = (struct espconn *)zalloc(sizeof(struct espconn));
if(!pesp_conn) if(!pesp_conn)
return luaL_error(L, "not enough memory"); return luaL_error(L, "not enough memory");
...@@ -95,9 +95,9 @@ static int coap_create( lua_State* L, const char* mt ) ...@@ -95,9 +95,9 @@ static int coap_create( lua_State* L, const char* mt )
pesp_conn->proto.tcp = NULL; pesp_conn->proto.tcp = NULL;
pesp_conn->proto.udp = NULL; pesp_conn->proto.udp = NULL;
pesp_conn->proto.udp = (esp_udp *)c_zalloc(sizeof(esp_udp)); pesp_conn->proto.udp = (esp_udp *)zalloc(sizeof(esp_udp));
if(!pesp_conn->proto.udp){ if(!pesp_conn->proto.udp){
c_free(pesp_conn); free(pesp_conn);
cud->pesp_conn = pesp_conn = NULL; cud->pesp_conn = pesp_conn = NULL;
return luaL_error(L, "not enough memory"); return luaL_error(L, "not enough memory");
} }
...@@ -135,9 +135,9 @@ static int coap_delete( lua_State* L, const char* mt ) ...@@ -135,9 +135,9 @@ static int coap_delete( lua_State* L, const char* mt )
{ {
if(cud->pesp_conn->proto.udp->remote_port || cud->pesp_conn->proto.udp->local_port) if(cud->pesp_conn->proto.udp->remote_port || cud->pesp_conn->proto.udp->local_port)
espconn_delete(cud->pesp_conn); espconn_delete(cud->pesp_conn);
c_free(cud->pesp_conn->proto.udp); free(cud->pesp_conn->proto.udp);
cud->pesp_conn->proto.udp = NULL; cud->pesp_conn->proto.udp = NULL;
c_free(cud->pesp_conn); free(cud->pesp_conn);
cud->pesp_conn = NULL; cud->pesp_conn = NULL;
} }
...@@ -174,7 +174,7 @@ static int coap_start( lua_State* L, const char* mt ) ...@@ -174,7 +174,7 @@ static int coap_start( lua_State* L, const char* mt )
ip = "0.0.0.0"; ip = "0.0.0.0";
} }
ipaddr.addr = ipaddr_addr(ip); ipaddr.addr = ipaddr_addr(ip);
c_memcpy(pesp_conn->proto.udp->local_ip, &ipaddr.addr, 4); memcpy(pesp_conn->proto.udp->local_ip, &ipaddr.addr, 4);
NODE_DBG("UDP ip is set: "); NODE_DBG("UDP ip is set: ");
NODE_DBG(IPSTR, IP2STR(&ipaddr.addr)); NODE_DBG(IPSTR, IP2STR(&ipaddr.addr));
NODE_DBG("\n"); NODE_DBG("\n");
...@@ -239,7 +239,7 @@ static void coap_response_handler(void *arg, char *pdata, unsigned short len) ...@@ -239,7 +239,7 @@ static void coap_response_handler(void *arg, char *pdata, unsigned short len)
pkt.content.len = 0; pkt.content.len = 0;
// static uint8_t buf[MAX_MESSAGE_SIZE+1] = {0}; // +1 for string '\0' // static uint8_t buf[MAX_MESSAGE_SIZE+1] = {0}; // +1 for string '\0'
uint8_t buf[MAX_MESSAGE_SIZE+1] = {0}; // +1 for string '\0' uint8_t buf[MAX_MESSAGE_SIZE+1] = {0}; // +1 for string '\0'
c_memset(buf, 0, sizeof(buf)); // wipe prev data memset(buf, 0, sizeof(buf)); // wipe prev data
int rc; int rc;
if( len > MAX_MESSAGE_SIZE ) if( len > MAX_MESSAGE_SIZE )
...@@ -247,7 +247,7 @@ static void coap_response_handler(void *arg, char *pdata, unsigned short len) ...@@ -247,7 +247,7 @@ static void coap_response_handler(void *arg, char *pdata, unsigned short len)
NODE_DBG("Request Entity Too Large.\n"); // NOTE: should response 4.13 to client... NODE_DBG("Request Entity Too Large.\n"); // NOTE: should response 4.13 to client...
return; return;
} }
c_memcpy(buf, pdata, len); memcpy(buf, pdata, len);
if (0 != (rc = coap_parse(&pkt, buf, len))){ if (0 != (rc = coap_parse(&pkt, buf, len))){
NODE_DBG("Bad packet rc=%d\n", rc); NODE_DBG("Bad packet rc=%d\n", rc);
...@@ -275,7 +275,7 @@ static void coap_response_handler(void *arg, char *pdata, unsigned short len) ...@@ -275,7 +275,7 @@ static void coap_response_handler(void *arg, char *pdata, unsigned short len)
uint32_t ip = 0, port = 0; uint32_t ip = 0, port = 0;
coap_tid_t id = COAP_INVALID_TID; coap_tid_t id = COAP_INVALID_TID;
c_memcpy(&ip, pesp_conn->proto.udp->remote_ip, sizeof(ip)); memcpy(&ip, pesp_conn->proto.udp->remote_ip, sizeof(ip));
port = pesp_conn->proto.udp->remote_port; port = pesp_conn->proto.udp->remote_port;
coap_transaction_id(ip, port, &pkt, &id); coap_transaction_id(ip, port, &pkt, &id);
...@@ -307,7 +307,7 @@ end: ...@@ -307,7 +307,7 @@ end:
if(pesp_conn->proto.udp->remote_port || pesp_conn->proto.udp->local_port) if(pesp_conn->proto.udp->remote_port || pesp_conn->proto.udp->local_port)
espconn_delete(pesp_conn); espconn_delete(pesp_conn);
} }
// c_memset(buf, 0, sizeof(buf)); // memset(buf, 0, sizeof(buf));
} }
// Lua: client:request( [CON], uri, [payload] ) // Lua: client:request( [CON], uri, [payload] )
...@@ -358,7 +358,7 @@ static int coap_request( lua_State* L, coap_method_t m ) ...@@ -358,7 +358,7 @@ static int coap_request( lua_State* L, coap_method_t m )
pesp_conn->proto.udp->local_port = espconn_port(); pesp_conn->proto.udp->local_port = espconn_port();
if(uri->host.length){ if(uri->host.length){
c_memcpy(host, uri->host.s, uri->host.length); memcpy(host, uri->host.s, uri->host.length);
host[uri->host.length] = '\0'; host[uri->host.length] = '\0';
ipaddr.addr = ipaddr_addr(host); ipaddr.addr = ipaddr_addr(host);
...@@ -366,7 +366,7 @@ static int coap_request( lua_State* L, coap_method_t m ) ...@@ -366,7 +366,7 @@ static int coap_request( lua_State* L, coap_method_t m )
NODE_DBG(host); NODE_DBG(host);
NODE_DBG("\n"); NODE_DBG("\n");
c_memcpy(pesp_conn->proto.udp->remote_ip, &ipaddr.addr, 4); memcpy(pesp_conn->proto.udp->remote_ip, &ipaddr.addr, 4);
NODE_DBG("UDP ip is set: "); NODE_DBG("UDP ip is set: ");
NODE_DBG(IPSTR, IP2STR(&ipaddr.addr)); NODE_DBG(IPSTR, IP2STR(&ipaddr.addr));
NODE_DBG("\n"); NODE_DBG("\n");
...@@ -375,7 +375,7 @@ static int coap_request( lua_State* L, coap_method_t m ) ...@@ -375,7 +375,7 @@ static int coap_request( lua_State* L, coap_method_t m )
coap_pdu_t *pdu = coap_new_pdu(); // should call coap_delete_pdu() somewhere coap_pdu_t *pdu = coap_new_pdu(); // should call coap_delete_pdu() somewhere
if(!pdu){ if(!pdu){
if(uri) if(uri)
c_free(uri); free(uri);
return luaL_error (L, "alloc fail"); return luaL_error (L, "alloc fail");
} }
...@@ -426,7 +426,7 @@ static int coap_request( lua_State* L, coap_method_t m ) ...@@ -426,7 +426,7 @@ static int coap_request( lua_State* L, coap_method_t m )
} }
if(uri) if(uri)
c_free((void *)uri); free((void *)uri);
NODE_DBG("coap_request is called.\n"); NODE_DBG("coap_request is called.\n");
return 0; return 0;
...@@ -451,13 +451,13 @@ static int coap_regist( lua_State* L, const char* mt, int isvar ) ...@@ -451,13 +451,13 @@ static int coap_regist( lua_State* L, const char* mt, int isvar )
h = function_entry; h = function_entry;
while(NULL!=h->next){ // goto the end of the list while(NULL!=h->next){ // goto the end of the list
if(h->name!= NULL && c_strcmp(h->name, name)==0) // key exist, override it if(h->name!= NULL && strcmp(h->name, name)==0) // key exist, override it
break; break;
h = h->next; h = h->next;
} }
if(h->name==NULL || c_strcmp(h->name, name)!=0){ // not exists. make a new one. if(h->name==NULL || strcmp(h->name, name)!=0){ // not exists. make a new one.
h->next = (coap_luser_entry *)c_zalloc(sizeof(coap_luser_entry)); h->next = (coap_luser_entry *)zalloc(sizeof(coap_luser_entry));
h = h->next; h = h->next;
if(h == NULL) if(h == NULL)
return luaL_error(L, "not enough memory"); return luaL_error(L, "not enough memory");
......
// Module for cryptography // Module for cryptography
#include <c_errno.h> #include <errno.h>
#include "module.h" #include "module.h"
#include "lauxlib.h" #include "lauxlib.h"
#include "platform.h" #include "platform.h"
#include "c_types.h" #include "c_types.h"
#include "c_stdlib.h" #include <stdlib.h>
#include "flash_fs.h" #include "flash_fs.h"
#include "../crypto/digests.h" #include "../crypto/digests.h"
#include "../crypto/mech.h" #include "../crypto/mech.h"
...@@ -71,7 +71,7 @@ static int crypto_base64_encode( lua_State* L ) ...@@ -71,7 +71,7 @@ static int crypto_base64_encode( lua_State* L )
int len; int len;
const char* msg = luaL_checklstring(L, 1, &len); const char* msg = luaL_checklstring(L, 1, &len);
int blen = (len + 2) / 3 * 4; int blen = (len + 2) / 3 * 4;
char* out = (char*)c_malloc(blen); char* out = (char*)malloc(blen);
int j = 0, i; int j = 0, i;
for (i = 0; i < len; i += 3) { for (i = 0; i < len; i += 3) {
int a = msg[i]; int a = msg[i];
...@@ -83,7 +83,7 @@ static int crypto_base64_encode( lua_State* L ) ...@@ -83,7 +83,7 @@ static int crypto_base64_encode( lua_State* L )
out[j++] = (i + 2 < len) ? bytes64[(c & 63)] : 61; out[j++] = (i + 2 < len) ? bytes64[(c & 63)] : 61;
} }
lua_pushlstring(L, out, j); lua_pushlstring(L, out, j);
c_free(out); free(out);
return 1; return 1;
} }
...@@ -96,14 +96,14 @@ static int crypto_hex_encode( lua_State* L) ...@@ -96,14 +96,14 @@ static int crypto_hex_encode( lua_State* L)
{ {
int len; int len;
const char* msg = luaL_checklstring(L, 1, &len); const char* msg = luaL_checklstring(L, 1, &len);
char* out = (char*)c_malloc(len * 2); char* out = (char*)malloc(len * 2);
int i, j = 0; int i, j = 0;
for (i = 0; i < len; i++) { for (i = 0; i < len; i++) {
out[j++] = crypto_hexbytes[msg[i] >> 4]; out[j++] = crypto_hexbytes[msg[i] >> 4];
out[j++] = crypto_hexbytes[msg[i] & 0xf]; out[j++] = crypto_hexbytes[msg[i] & 0xf];
} }
lua_pushlstring(L, out, len*2); lua_pushlstring(L, out, len*2);
c_free(out); free(out);
return 1; return 1;
} }
#endif #endif
...@@ -118,12 +118,12 @@ static int crypto_mask( lua_State* L ) ...@@ -118,12 +118,12 @@ static int crypto_mask( lua_State* L )
const char* msg = luaL_checklstring(L, 1, &len); const char* msg = luaL_checklstring(L, 1, &len);
const char* mask = luaL_checklstring(L, 2, &mask_len); const char* mask = luaL_checklstring(L, 2, &mask_len);
int i; int i;
char* copy = (char*)c_malloc(len); char* copy = (char*)malloc(len);
for (i = 0; i < len; i++) { for (i = 0; i < len; i++) {
copy[i] = msg[i] ^ mask[i % 4]; copy[i] = msg[i] ^ mask[i % 4];
} }
lua_pushlstring(L, copy, len); lua_pushlstring(L, copy, len);
c_free(copy); free(copy);
return 1; return 1;
} }
...@@ -169,7 +169,7 @@ static int crypto_new_hash (lua_State *L) ...@@ -169,7 +169,7 @@ static int crypto_new_hash (lua_State *L)
if (!mi) if (!mi)
return bad_mech (L); return bad_mech (L);
void *ctx = os_malloc (mi->ctx_size); void *ctx = malloc (mi->ctx_size);
if (ctx==NULL) if (ctx==NULL)
return bad_mem (L); return bad_mem (L);
...@@ -237,7 +237,7 @@ static int crypto_hash_gcdelete (lua_State *L) ...@@ -237,7 +237,7 @@ static int crypto_hash_gcdelete (lua_State *L)
dudat = (digest_user_datum_t *)luaL_checkudata(L, 1, "crypto.hash"); dudat = (digest_user_datum_t *)luaL_checkudata(L, 1, "crypto.hash");
luaL_argcheck(L, dudat, 1, "crypto.hash expected"); luaL_argcheck(L, dudat, 1, "crypto.hash expected");
os_free(dudat->ctx); free(dudat->ctx);
return 0; return 0;
} }
...@@ -325,7 +325,7 @@ static int crypto_encdec (lua_State *L, bool enc) ...@@ -325,7 +325,7 @@ static int crypto_encdec (lua_State *L, bool enc)
size_t bs = mech->block_size; size_t bs = mech->block_size;
size_t outlen = ((dlen + bs -1) / bs) * bs; size_t outlen = ((dlen + bs -1) / bs) * bs;
char *buf = (char *)os_zalloc (outlen); char *buf = (char *)zalloc (outlen);
if (!buf) if (!buf)
return luaL_error (L, "crypto init failed"); return luaL_error (L, "crypto init failed");
...@@ -339,14 +339,14 @@ static int crypto_encdec (lua_State *L, bool enc) ...@@ -339,14 +339,14 @@ static int crypto_encdec (lua_State *L, bool enc)
}; };
if (!mech->run (&op)) if (!mech->run (&op))
{ {
os_free (buf); free (buf);
return luaL_error (L, "crypto op failed"); return luaL_error (L, "crypto op failed");
} }
else else
{ {
lua_pushlstring (L, buf, outlen); lua_pushlstring (L, buf, outlen);
// note: if lua_pushlstring runs out of memory, we leak buf :( // note: if lua_pushlstring runs out of memory, we leak buf :(
os_free (buf); free (buf);
return 1; return 1;
} }
} }
......
...@@ -3,7 +3,8 @@ ...@@ -3,7 +3,8 @@
#include "module.h" #include "module.h"
#include "lauxlib.h" #include "lauxlib.h"
#include "lmem.h" #include "lmem.h"
#include "c_string.h" #include <string.h>
#include <stdint.h>
#define BASE64_INVALID '\xff' #define BASE64_INVALID '\xff'
#define BASE64_PADDING '=' #define BASE64_PADDING '='
#define ISBASE64(c) (unbytes64[c] != BASE64_INVALID) #define ISBASE64(c) (unbytes64[c] != BASE64_INVALID)
...@@ -18,7 +19,7 @@ static uint8 *toBase64 ( lua_State* L, const uint8 *msg, size_t *len){ ...@@ -18,7 +19,7 @@ static uint8 *toBase64 ( lua_State* L, const uint8 *msg, size_t *len){
uint8 * q, *out = (uint8 *)luaM_malloc(L, (n + 2) / 3 * 4); uint8 * q, *out = (uint8 *)luaM_malloc(L, (n + 2) / 3 * 4);
uint8 bytes64[sizeof(b64)]; uint8 bytes64[sizeof(b64)];
c_memcpy(bytes64, b64, sizeof(b64)); //Avoid lots of flash unaligned fetches memcpy(bytes64, b64, sizeof(b64)); //Avoid lots of flash unaligned fetches
for (i = 0, q = out; i < n; i += 3) { for (i = 0, q = out; i < n; i += 3) {
int a = msg[i]; int a = msg[i];
...@@ -44,7 +45,7 @@ static uint8 *fromBase64 ( lua_State* L, const uint8 *enc_msg, size_t *len){ ...@@ -44,7 +45,7 @@ static uint8 *fromBase64 ( lua_State* L, const uint8 *enc_msg, size_t *len){
if (n & 3) if (n & 3)
luaL_error (L, "Invalid base64 string"); luaL_error (L, "Invalid base64 string");
c_memset(unbytes64, BASE64_INVALID, sizeof(unbytes64)); memset(unbytes64, BASE64_INVALID, sizeof(unbytes64));
for (i = 0; i < sizeof(b64)-1; i++) unbytes64[b64[i]] = i; // sequential so no exceptions for (i = 0; i < sizeof(b64)-1; i++) unbytes64[b64[i]] = i; // sequential so no exceptions
if (enc_msg[n-1] == BASE64_PADDING) { if (enc_msg[n-1] == BASE64_PADDING) {
......
This diff is collapsed.
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
#include "c_types.h" #include "c_types.h"
#include "flash_fs.h" #include "flash_fs.h"
#include "c_string.h" #include <string.h>
static volatile int file_fd = FS_OPEN_OK - 1; static volatile int file_fd = FS_OPEN_OK - 1;
...@@ -20,7 +20,7 @@ static int file_open( lua_State* L ) ...@@ -20,7 +20,7 @@ static int file_open( lua_State* L )
} }
const char *fname = luaL_checklstring( L, 1, &len ); const char *fname = luaL_checklstring( L, 1, &len );
luaL_argcheck(L, len < FS_NAME_MAX_LENGTH && c_strlen(fname) == len, 1, "filename invalid"); luaL_argcheck(L, len < FS_NAME_MAX_LENGTH && strlen(fname) == len, 1, "filename invalid");
const char *mode = luaL_optstring(L, 2, "r"); const char *mode = luaL_optstring(L, 2, "r");
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
#include "platform.h" #include "platform.h"
#include "user_interface.h" #include "user_interface.h"
#include "c_types.h" #include "c_types.h"
#include "c_string.h" #include <string.h>
#include "gpio.h" #include "gpio.h"
#undef INTERRUPT #undef INTERRUPT
......
...@@ -14,13 +14,13 @@ static int http_callback_registry = LUA_NOREF; ...@@ -14,13 +14,13 @@ static int http_callback_registry = LUA_NOREF;
static void http_callback( char * response, int http_status, char * full_response ) static void http_callback( char * response, int http_status, char * full_response )
{ {
#if defined(HTTPCLIENT_DEBUG_ON) #if defined(HTTPCLIENT_DEBUG_ON)
c_printf( "http_status=%d\n", http_status ); printf( "http_status=%d\n", http_status );
if ( http_status != HTTP_STATUS_GENERIC_ERROR ) if ( http_status != HTTP_STATUS_GENERIC_ERROR )
{ {
if (full_response != NULL) { if (full_response != NULL) {
c_printf( "strlen(full_response)=%d\n", strlen( full_response ) ); printf( "strlen(full_response)=%d\n", strlen( full_response ) );
} }
c_printf( "response=%s<EOF>\n", response ); printf( "response=%s<EOF>\n", response );
} }
#endif #endif
if (http_callback_registry != LUA_NOREF) if (http_callback_registry != LUA_NOREF)
......
...@@ -4,8 +4,8 @@ ...@@ -4,8 +4,8 @@
#include "module.h" #include "module.h"
#include "lauxlib.h" #include "lauxlib.h"
#include "platform.h" #include "platform.h"
#include "c_stdlib.h" #include <stdlib.h>
#include "c_string.h" #include <string.h>
#include "user_interface.h" #include "user_interface.h"
#include "esp_system.h" #include "esp_system.h"
......
...@@ -3,8 +3,8 @@ ...@@ -3,8 +3,8 @@
#include "module.h" #include "module.h"
#include "lauxlib.h" #include "lauxlib.h"
#include "c_string.h" #include <string.h>
#include "c_stdlib.h" #include <stdlib.h>
#include "c_types.h" #include "c_types.h"
#include "mem.h" #include "mem.h"
...@@ -43,16 +43,16 @@ static int mdns_register(lua_State *L) ...@@ -43,16 +43,16 @@ static int mdns_register(lua_State *L)
luaL_checktype(L, -2, LUA_TSTRING); luaL_checktype(L, -2, LUA_TSTRING);
const char *key = luaL_checkstring(L, -2); const char *key = luaL_checkstring(L, -2);
if (c_strcmp(key, "port") == 0) { if (strcmp(key, "port") == 0) {
info.service_port = luaL_checknumber(L, -1); info.service_port = luaL_checknumber(L, -1);
} else if (c_strcmp(key, "service") == 0) { } else if (strcmp(key, "service") == 0) {
info.service_name = luaL_checkstring(L, -1); info.service_name = luaL_checkstring(L, -1);
} else if (c_strcmp(key, "description") == 0) { } else if (strcmp(key, "description") == 0) {
info.host_desc = luaL_checkstring(L, -1); info.host_desc = luaL_checkstring(L, -1);
} else { } else {
int len = c_strlen(key) + 1; int len = strlen(key) + 1;
const char *value = luaL_checkstring(L, -1); const char *value = luaL_checkstring(L, -1);
char *p = alloca(len + c_strlen(value) + 1); char *p = alloca(len + strlen(value) + 1);
strcpy(p, key); strcpy(p, key);
strcat(p, "="); strcat(p, "=");
strcat(p, value); strcat(p, value);
......
This diff is collapsed.
This diff is collapsed.
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
#include "lrodefs.h" #include "lrodefs.h"
#include "c_types.h" #include "c_types.h"
#include "c_string.h" #include <string.h>
#include "driver/uart.h" #include "driver/uart.h"
#include "user_interface.h" #include "user_interface.h"
#include "flash_api.h" #include "flash_api.h"
...@@ -276,9 +276,9 @@ static int node_key( lua_State* L ) ...@@ -276,9 +276,9 @@ static int node_key( lua_State* L )
if (str == NULL) if (str == NULL)
return luaL_error( L, "wrong arg type" ); return luaL_error( L, "wrong arg type" );
if (sl == 5 && c_strcmp(str, "short") == 0) { if (sl == 5 && strcmp(str, "short") == 0) {
ref = &short_key_ref; ref = &short_key_ref;
} else if (sl == 4 && c_strcmp(str, "long") == 0) { } else if (sl == 4 && strcmp(str, "long") == 0) {
ref = &long_key_ref; ref = &long_key_ref;
} else { } else {
ref = &short_key_ref; ref = &short_key_ref;
...@@ -311,9 +311,9 @@ static int node_input( lua_State* L ) ...@@ -311,9 +311,9 @@ static int node_input( lua_State* L )
{ {
lua_Load *load = &gLoad; lua_Load *load = &gLoad;
if (load->line_position == 0) { if (load->line_position == 0) {
c_memcpy(load->line, s, l); memcpy(load->line, s, l);
load->line[l + 1] = '\0'; load->line[l + 1] = '\0';
load->line_position = c_strlen(load->line) + 1; load->line_position = strlen(load->line) + 1;
load->done = 1; load->done = 1;
NODE_DBG("Get command:\n"); NODE_DBG("Get command:\n");
NODE_DBG(load->line); // buggy here NODE_DBG(load->line); // buggy here
...@@ -328,7 +328,7 @@ static int output_redir_ref = LUA_NOREF; ...@@ -328,7 +328,7 @@ static int output_redir_ref = LUA_NOREF;
static int serial_debug = 1; static int serial_debug = 1;
void output_redirect(const char *str) { void output_redirect(const char *str) {
lua_State *L = lua_getstate(); lua_State *L = lua_getstate();
// if(c_strlen(str)>=TX_BUFF_SIZE){ // if(strlen(str)>=TX_BUFF_SIZE){
// NODE_ERR("output too long.\n"); // NODE_ERR("output too long.\n");
// return; // return;
// } // }
...@@ -402,13 +402,13 @@ static int node_compile( lua_State* L ) ...@@ -402,13 +402,13 @@ static int node_compile( lua_State* L )
return luaL_error(L, "filename too long"); return luaL_error(L, "filename too long");
char output[FS_NAME_MAX_LENGTH]; char output[FS_NAME_MAX_LENGTH];
c_strcpy(output, fname); strcpy(output, fname);
// check here that filename end with ".lua". // check here that filename end with ".lua".
if (len < 4 || (c_strcmp( output + len - 4, ".lua") != 0) ) if (len < 4 || (strcmp( output + len - 4, ".lua") != 0) )
return luaL_error(L, "not a .lua file"); return luaL_error(L, "not a .lua file");
output[c_strlen(output) - 2] = 'c'; output[strlen(output) - 2] = 'c';
output[c_strlen(output) - 1] = '\0'; output[strlen(output) - 1] = '\0';
NODE_DBG(output); NODE_DBG(output);
NODE_DBG("\n"); NODE_DBG("\n");
if (luaL_loadfsfile(L, fname) != 0) { if (luaL_loadfsfile(L, fname) != 0) {
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
#include "ets_sys.h" #include "ets_sys.h"
#include "os_type.h" #include "os_type.h"
#include "osapi.h" #include "osapi.h"
#include "c_stdlib.h" #include <stdlib.h>
#include "module.h" #include "module.h"
#include "lauxlib.h" #include "lauxlib.h"
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
#include "c_types.h" #include "c_types.h"
#include "user_interface.h" #include "user_interface.h"
#include "driver/rotary.h" #include "driver/rotary.h"
#include "../libc/c_stdlib.h" #include <stdlib.h>
#define MASK(x) (1 << ROTARY_ ## x ## _INDEX) #define MASK(x) (1 << ROTARY_ ## x ## _INDEX)
...@@ -143,7 +143,7 @@ static int lrotary_setup( lua_State* L ) ...@@ -143,7 +143,7 @@ static int lrotary_setup( lua_State* L )
callback_free(L, id, ROTARY_ALL); callback_free(L, id, ROTARY_ALL);
if (!data[id]) { if (!data[id]) {
data[id] = (DATA *) os_zalloc(sizeof(DATA)); data[id] = (DATA *) zalloc(sizeof(DATA));
if (!data[id]) { if (!data[id]) {
return -1; return -1;
} }
...@@ -202,7 +202,7 @@ static int lrotary_close( lua_State* L ) ...@@ -202,7 +202,7 @@ static int lrotary_close( lua_State* L )
DATA *d = data[id]; DATA *d = data[id];
if (d) { if (d) {
data[id] = NULL; data[id] = NULL;
os_free(d); free(d);
} }
if (rotary_close( id )) { if (rotary_close( id )) {
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "rtc/rtctime.h" #include "rtc/rtctime.h"
#define RTCTIME_SLEEP_ALIGNED rtctime_deep_sleep_until_aligned_us #define RTCTIME_SLEEP_ALIGNED rtctime_deep_sleep_until_aligned_us
#include "rtc/rtcfifo.h" #include "rtc/rtcfifo.h"
#include <string.h>
// rtcfifo.prepare ([{sensor_count=n, interval_us=m, storage_begin=x, storage_end=y}]) // rtcfifo.prepare ([{sensor_count=n, interval_us=m, storage_begin=x, storage_end=y}])
static int rtcfifo_prepare (lua_State *L) static int rtcfifo_prepare (lua_State *L)
......
...@@ -38,7 +38,7 @@ ...@@ -38,7 +38,7 @@
#include "os_type.h" #include "os_type.h"
#include "osapi.h" #include "osapi.h"
#include "lwip/udp.h" #include "lwip/udp.h"
#include "c_stdlib.h" #include <stdlib.h>
#include "user_modules.h" #include "user_modules.h"
#include "lwip/dns.h" #include "lwip/dns.h"
#include "user_interface.h" #include "user_interface.h"
...@@ -53,7 +53,7 @@ ...@@ -53,7 +53,7 @@
#define MAX_ATTEMPTS 5 #define MAX_ATTEMPTS 5
#if 0 #if 0
# define sntp_dbg(...) c_printf(__VA_ARGS__) # define sntp_dbg(...) printf(__VA_ARGS__)
#else #else
# define sntp_dbg(...) # define sntp_dbg(...)
#endif #endif
...@@ -110,7 +110,7 @@ static void cleanup (lua_State *L) ...@@ -110,7 +110,7 @@ static void cleanup (lua_State *L)
udp_remove (state->pcb); udp_remove (state->pcb);
luaL_unref (L, LUA_REGISTRYINDEX, state->sync_cb_ref); luaL_unref (L, LUA_REGISTRYINDEX, state->sync_cb_ref);
luaL_unref (L, LUA_REGISTRYINDEX, state->err_cb_ref); luaL_unref (L, LUA_REGISTRYINDEX, state->err_cb_ref);
os_free (state); free (state);
state = 0; state = 0;
} }
...@@ -328,7 +328,7 @@ static int sntp_sync (lua_State *L) ...@@ -328,7 +328,7 @@ static int sntp_sync (lua_State *L)
if (state) if (state)
return luaL_error (L, "sync in progress"); return luaL_error (L, "sync in progress");
state = (sntp_state_t *)c_malloc (sizeof (sntp_state_t)); state = (sntp_state_t *)malloc (sizeof (sntp_state_t));
if (!state) if (!state)
sync_err ("out of memory"); sync_err ("out of memory");
...@@ -386,7 +386,7 @@ error: ...@@ -386,7 +386,7 @@ error:
{ {
if (state->pcb) if (state->pcb)
udp_remove (state->pcb); udp_remove (state->pcb);
c_free (state); free (state);
state = 0; state = 0;
} }
return luaL_error (L, errmsg); return luaL_error (L, errmsg);
......
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