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.
This commit is contained in:
parent
3a3e9ee0fd
commit
e49f2bb13f
2
Makefile
2
Makefile
|
@ -9,7 +9,7 @@ SDK_DIR:=$(TOP_DIR)/rtos-sdk
|
|||
|
||||
# This is, sadly, the cleanest way to resolve the different non-standard
|
||||
# conventions for sized integers across the various components.
|
||||
BASIC_TYPES=-Du32_t=uint32_t -Du16_t=uint16_t -Du8_t=uint8_t -Duint32=uint32_t -Duint16=uint16_t -Duint8=uint8_t -Dsint32=int32_t -Dsint16=int16_t -Dsint8=int8_t
|
||||
BASIC_TYPES=-Du32_t=uint32_t -Du16_t=uint16_t -Du8_t=uint8_t -Ds32_t=int32_t -Ds16_t=int16_t -Duint32=uint32_t -Duint16=uint16_t -Duint8=uint8_t -Dsint32=int32_t -Dsint16=int16_t -Dsint8=int8_t
|
||||
|
||||
# Include dirs, ensure the overrides come first
|
||||
INCLUDE_DIRS=$(TOP_DIR)/sdk-overrides/include $(SDK_DIR)/include $(SDK_DIR)/include/espressif $(SDK_DIR)/include/lwip $(SDK_DIR)/include/lwip/ipv4 $(SDK_DIR)/include/lwip/ipv6 $(SDK_DIR)/extra_include
|
||||
|
|
|
@ -26,7 +26,6 @@ SUBDIRS= \
|
|||
driver \
|
||||
json \
|
||||
platform \
|
||||
libc \
|
||||
lua \
|
||||
coap \
|
||||
mqtt \
|
||||
|
@ -72,7 +71,6 @@ COMPONENTS_eagle.app.v6 = \
|
|||
json/libjson.a \
|
||||
platform/libplatform.a \
|
||||
task/libtask.a \
|
||||
libc/liblibc.a \
|
||||
lua/liblua.a \
|
||||
coap/coap.a \
|
||||
mqtt/mqtt.a \
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#include "cjson_mem.h"
|
||||
#include "../lua/lauxlib.h"
|
||||
#include <c_stdlib.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
static lua_State *gL;
|
||||
static const char errfmt[] = "cjson %salloc: out of mem (%d bytes)";
|
||||
|
@ -12,7 +12,7 @@ void cjson_mem_setlua (lua_State *L)
|
|||
|
||||
void *cjson_mem_malloc (uint32_t sz)
|
||||
{
|
||||
void *p = (void*)c_malloc (sz);
|
||||
void *p = (void*)malloc (sz);
|
||||
if (!p && gL)
|
||||
luaL_error (gL, errfmt, "m", sz);
|
||||
return p;
|
||||
|
@ -21,7 +21,7 @@ void *cjson_mem_malloc (uint32_t sz)
|
|||
|
||||
void *cjson_mem_realloc (void *o, uint32_t sz)
|
||||
{
|
||||
void *p = (void*)c_realloc (o, sz);
|
||||
void *p = (void*)realloc (o, sz);
|
||||
if (!p && gL)
|
||||
luaL_error (gL, errfmt, "re", sz);
|
||||
return p;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#ifndef _CJSON_MEM_H_
|
||||
#define _CJSON_MEM_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include "../lua/lua.h"
|
||||
|
||||
void cjson_mem_setlua (lua_State *L);
|
||||
|
|
|
@ -28,10 +28,10 @@
|
|||
* fpconv_* will around these issues with a translation buffer if required.
|
||||
*/
|
||||
|
||||
#include "c_stdio.h"
|
||||
#include "c_stdlib.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
// #include <assert.h>
|
||||
#include "c_string.h"
|
||||
#include <string.h>
|
||||
|
||||
#include "fpconv.h"
|
||||
|
||||
|
@ -54,7 +54,7 @@ static void fpconv_update_locale()
|
|||
{
|
||||
char buf[8];
|
||||
|
||||
c_sprintf(buf, "%g", 0.5);
|
||||
sprintf(buf, "%g", 0.5);
|
||||
|
||||
/* Failing this test might imply the platform has a buggy dtoa
|
||||
* implementation or wide characters */
|
||||
|
@ -125,7 +125,7 @@ double fpconv_strtod(const char *nptr, char **endptr)
|
|||
/* Duplicate number into buffer */
|
||||
if (buflen >= FPCONV_G_FMT_BUFSIZE) {
|
||||
/* Handle unusually large numbers */
|
||||
buf = c_malloc(buflen + 1);
|
||||
buf = malloc(buflen + 1);
|
||||
if (!buf) {
|
||||
NODE_ERR("not enough memory\n");
|
||||
return;
|
||||
|
@ -134,18 +134,18 @@ double fpconv_strtod(const char *nptr, char **endptr)
|
|||
/* This is the common case.. */
|
||||
buf = localbuf;
|
||||
}
|
||||
c_memcpy(buf, nptr, buflen);
|
||||
memcpy(buf, nptr, buflen);
|
||||
buf[buflen] = 0;
|
||||
|
||||
/* Update decimal point character if found */
|
||||
dp = c_strchr(buf, '.');
|
||||
dp = strchr(buf, '.');
|
||||
if (dp)
|
||||
*dp = locale_decimal_point;
|
||||
|
||||
value = c_strtod(buf, &endbuf);
|
||||
*endptr = (char *)&nptr[endbuf - buf];
|
||||
if (buflen >= FPCONV_G_FMT_BUFSIZE)
|
||||
c_free(buf);
|
||||
free(buf);
|
||||
|
||||
return value;
|
||||
}
|
||||
|
@ -183,13 +183,13 @@ int fpconv_g_fmt(char *str, double num, int precision)
|
|||
|
||||
/* Pass through when decimal point character is dot. */
|
||||
if (locale_decimal_point == '.'){
|
||||
c_sprintf(str, fmt, num);
|
||||
return c_strlen(str);
|
||||
sprintf(str, fmt, num);
|
||||
return strlen(str);
|
||||
}
|
||||
|
||||
/* snprintf() to a buffer then translate for other decimal point characters */
|
||||
c_sprintf(buf, fmt, num);
|
||||
len = c_strlen(buf);
|
||||
sprintf(buf, fmt, num);
|
||||
len = strlen(buf);
|
||||
|
||||
/* Copy into target location. Translate decimal point if required */
|
||||
b = buf;
|
||||
|
|
|
@ -22,10 +22,10 @@
|
|||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "c_stdio.h"
|
||||
#include "c_stdlib.h"
|
||||
#include "c_stdarg.h"
|
||||
#include "c_string.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "strbuf.h"
|
||||
#include "cjson_mem.h"
|
||||
|
@ -103,11 +103,11 @@ void strbuf_free(strbuf_t *s)
|
|||
debug_stats(s);
|
||||
|
||||
if (s->buf) {
|
||||
c_free(s->buf);
|
||||
free(s->buf);
|
||||
s->buf = NULL;
|
||||
}
|
||||
if (s->dynamic)
|
||||
c_free(s);
|
||||
free(s);
|
||||
}
|
||||
|
||||
char *strbuf_free_to_string(strbuf_t *s, int *len)
|
||||
|
@ -123,7 +123,7 @@ char *strbuf_free_to_string(strbuf_t *s, int *len)
|
|||
*len = s->length;
|
||||
|
||||
if (s->dynamic)
|
||||
c_free(s);
|
||||
free(s);
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
|
|
@ -22,8 +22,8 @@
|
|||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "c_stdlib.h"
|
||||
#include "c_stdarg.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include "user_config.h"
|
||||
|
||||
/* Size: Total bytes allocated to *buf
|
||||
|
@ -128,13 +128,13 @@ static inline void strbuf_append_char_unsafe(strbuf_t *s, const char c)
|
|||
static inline void strbuf_append_mem(strbuf_t *s, const char *c, int len)
|
||||
{
|
||||
strbuf_ensure_empty_length(s, len);
|
||||
c_memcpy(s->buf + s->length, c, len);
|
||||
memcpy(s->buf + s->length, c, len);
|
||||
s->length += len;
|
||||
}
|
||||
|
||||
static inline void strbuf_append_mem_unsafe(strbuf_t *s, const char *c, int len)
|
||||
{
|
||||
c_memcpy(s->buf + s->length, c, len);
|
||||
memcpy(s->buf + s->length, c, len);
|
||||
s->length += len;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#include "user_config.h"
|
||||
#include "c_stdio.h"
|
||||
#include "c_string.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "coap.h"
|
||||
#include "uri.h"
|
||||
|
||||
|
@ -10,12 +10,12 @@ extern const coap_endpoint_t endpoints[];
|
|||
#ifdef COAP_DEBUG
|
||||
void coap_dumpHeader(coap_header_t *hdr)
|
||||
{
|
||||
c_printf("Header:\n");
|
||||
c_printf(" ver 0x%02X\n", hdr->ver);
|
||||
c_printf(" t 0x%02X\n", hdr->ver);
|
||||
c_printf(" tkl 0x%02X\n", hdr->tkl);
|
||||
c_printf(" code 0x%02X\n", hdr->code);
|
||||
c_printf(" id 0x%02X%02X\n", hdr->id[0], hdr->id[1]);
|
||||
printf("Header:\n");
|
||||
printf(" ver 0x%02X\n", hdr->ver);
|
||||
printf(" t 0x%02X\n", hdr->ver);
|
||||
printf(" tkl 0x%02X\n", hdr->tkl);
|
||||
printf(" code 0x%02X\n", hdr->code);
|
||||
printf(" id 0x%02X%02X\n", hdr->id[0], hdr->id[1]);
|
||||
}
|
||||
|
||||
void coap_dump(const uint8_t *buf, size_t buflen, bool bare)
|
||||
|
@ -23,14 +23,14 @@ void coap_dump(const uint8_t *buf, size_t buflen, bool bare)
|
|||
if (bare)
|
||||
{
|
||||
while(buflen--)
|
||||
c_printf("%02X%s", *buf++, (buflen > 0) ? " " : "");
|
||||
printf("%02X%s", *buf++, (buflen > 0) ? " " : "");
|
||||
}
|
||||
else
|
||||
{
|
||||
c_printf("Dump: ");
|
||||
printf("Dump: ");
|
||||
while(buflen--)
|
||||
c_printf("%02X%s", *buf++, (buflen > 0) ? " " : "");
|
||||
c_printf("\n");
|
||||
printf("%02X%s", *buf++, (buflen > 0) ? " " : "");
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@ -100,7 +100,7 @@ int coap_buildToken(const coap_buffer_t *tokbuf, const coap_header_t *hdr, uint8
|
|||
return COAP_ERR_UNSUPPORTED;
|
||||
|
||||
if (hdr->tkl > 0)
|
||||
c_memcpy(p, tokbuf->p, hdr->tkl);
|
||||
memcpy(p, tokbuf->p, hdr->tkl);
|
||||
|
||||
// http://tools.ietf.org/html/rfc7252#section-3.1
|
||||
// inject options
|
||||
|
@ -260,12 +260,12 @@ int coap_buildOptionHeader(uint32_t optDelta, size_t length, uint8_t *buf, size_
|
|||
void coap_dumpOptions(coap_option_t *opts, size_t numopt)
|
||||
{
|
||||
size_t i;
|
||||
c_printf(" Options:\n");
|
||||
printf(" Options:\n");
|
||||
for (i=0;i<numopt;i++)
|
||||
{
|
||||
c_printf(" 0x%02X [ ", opts[i].num);
|
||||
printf(" 0x%02X [ ", opts[i].num);
|
||||
coap_dump(opts[i].buf.p, opts[i].buf.len, true);
|
||||
c_printf(" ]\n");
|
||||
printf(" ]\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -273,9 +273,9 @@ void coap_dumpPacket(coap_packet_t *pkt)
|
|||
{
|
||||
coap_dumpHeader(&pkt->hdr);
|
||||
coap_dumpOptions(pkt->opts, pkt->numopts);
|
||||
c_printf("Payload: ");
|
||||
printf("Payload: ");
|
||||
coap_dump(pkt->payload.p, pkt->payload.len, true);
|
||||
c_printf("\n");
|
||||
printf("\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -325,7 +325,7 @@ int coap_buffer_to_string(char *strbuf, size_t strbuflen, const coap_buffer_t *b
|
|||
{
|
||||
if (buf->len+1 > strbuflen)
|
||||
return COAP_ERR_BUFFER_TOO_SMALL;
|
||||
c_memcpy(strbuf, buf->p, buf->len);
|
||||
memcpy(strbuf, buf->p, buf->len);
|
||||
strbuf[buf->len] = 0;
|
||||
return 0;
|
||||
}
|
||||
|
@ -360,7 +360,7 @@ int coap_build(uint8_t *buf, size_t *buflen, const coap_packet_t *pkt)
|
|||
p += rc;
|
||||
left -= rc;
|
||||
|
||||
c_memcpy(p, pkt->opts[i].buf.p, pkt->opts[i].buf.len);
|
||||
memcpy(p, pkt->opts[i].buf.p, pkt->opts[i].buf.len);
|
||||
p += pkt->opts[i].buf.len;
|
||||
left -= pkt->opts[i].buf.len;
|
||||
running_delta = pkt->opts[i].num;
|
||||
|
@ -373,7 +373,7 @@ int coap_build(uint8_t *buf, size_t *buflen, const coap_packet_t *pkt)
|
|||
if (*buflen < 4 + 1 + pkt->payload.len + opts_len)
|
||||
return COAP_ERR_BUFFER_TOO_SMALL;
|
||||
buf[4 + opts_len] = 0xFF; // payload marker
|
||||
c_memcpy(buf+5 + opts_len, pkt->payload.p, pkt->payload.len);
|
||||
memcpy(buf+5 + opts_len, pkt->payload.p, pkt->payload.len);
|
||||
*buflen = opts_len + 5 + pkt->payload.len;
|
||||
}
|
||||
else
|
||||
|
@ -471,7 +471,7 @@ int coap_make_request(coap_rw_buffer_t *scratch, coap_packet_t *pkt, coap_msgtyp
|
|||
|
||||
/* split arg into Uri-* options */
|
||||
// const char *addr = uri->host.s;
|
||||
// if(uri->host.length && (c_strlen(addr) != uri->host.length || c_memcmp(addr, uri->host.s, uri->host.length) != 0)){
|
||||
// if(uri->host.length && (strlen(addr) != uri->host.length || memcmp(addr, uri->host.s, uri->host.length) != 0)){
|
||||
if(uri->host.length){
|
||||
/* add Uri-Host */
|
||||
// addr is destination address
|
||||
|
@ -525,9 +525,9 @@ int coap_handle_req(coap_rw_buffer_t *scratch, const coap_packet_t *inpkt, coap_
|
|||
goto next;
|
||||
for (i=0;i<ep->path->count;i++)
|
||||
{
|
||||
if (opt[i].buf.len != c_strlen(ep->path->elems[i]))
|
||||
if (opt[i].buf.len != strlen(ep->path->elems[i]))
|
||||
goto next;
|
||||
if (0 != c_memcmp(ep->path->elems[i], opt[i].buf.p, opt[i].buf.len))
|
||||
if (0 != memcmp(ep->path->elems[i], opt[i].buf.p, opt[i].buf.len))
|
||||
goto next;
|
||||
}
|
||||
// pre-path match!
|
||||
|
@ -551,5 +551,5 @@ void coap_setup(void)
|
|||
|
||||
inline int
|
||||
check_token(coap_packet_t *pkt) {
|
||||
return pkt->tok.len == the_token.len && c_memcmp(pkt->tok.p, the_token.p, the_token.len) == 0;
|
||||
return pkt->tok.len == the_token.len && memcmp(pkt->tok.p, the_token.p, the_token.len) == 0;
|
||||
}
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "c_stdint.h"
|
||||
#include "c_stddef.h"
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include "lualib.h"
|
||||
#include "lauxlib.h"
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#include "c_string.h"
|
||||
#include <string.h>
|
||||
#include "coap_io.h"
|
||||
#include "node.h"
|
||||
#include "espconn.h"
|
||||
|
@ -16,10 +16,10 @@ coap_tid_t coap_send(struct espconn *pesp_conn, coap_pdu_t *pdu) {
|
|||
espconn_sent(pesp_conn, (unsigned char *)(pdu->msg.p), pdu->msg.len);
|
||||
|
||||
if(pesp_conn->type == ESPCONN_TCP){
|
||||
c_memcpy(&ip, pesp_conn->proto.tcp->remote_ip, sizeof(ip));
|
||||
memcpy(&ip, pesp_conn->proto.tcp->remote_ip, sizeof(ip));
|
||||
port = pesp_conn->proto.tcp->remote_port;
|
||||
}else{
|
||||
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;
|
||||
}
|
||||
coap_transaction_id(ip, port, pdu->pkt, &id);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#include "user_config.h"
|
||||
#include "c_types.h"
|
||||
#include "c_stdlib.h"
|
||||
#include <ctype.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "coap.h"
|
||||
|
||||
|
@ -51,7 +51,7 @@ size_t coap_server_respond(char *req, unsigned short reqlen, char *rsp, unsigned
|
|||
#endif
|
||||
}
|
||||
if(rsppkt.content.p){
|
||||
c_free(rsppkt.content.p);
|
||||
free(rsppkt.content.p);
|
||||
rsppkt.content.p = NULL;
|
||||
rsppkt.content.len = 0;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#include "node.h"
|
||||
#include "coap_timer.h"
|
||||
#include "os_type.h"
|
||||
#include "esp_timer.h"
|
||||
|
||||
static os_timer_t coap_timer;
|
||||
static coap_tick_t basetime = 0;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#include "c_stdio.h"
|
||||
#include "c_string.h"
|
||||
#include "c_stdlib.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "coap.h"
|
||||
|
||||
#include "lua.h"
|
||||
|
@ -21,14 +21,14 @@ void endpoint_setup(void)
|
|||
static const coap_endpoint_path_t path_well_known_core = {2, {".well-known", "core"}};
|
||||
static int handle_get_well_known_core(const coap_endpoint_t *ep, coap_rw_buffer_t *scratch, const coap_packet_t *inpkt, coap_packet_t *outpkt, uint8_t id_hi, uint8_t id_lo)
|
||||
{
|
||||
outpkt->content.p = (uint8_t *)c_zalloc(MAX_PAYLOAD_SIZE); // this should be free-ed when outpkt is built in coap_server_respond()
|
||||
outpkt->content.p = (uint8_t *)zalloc(MAX_PAYLOAD_SIZE); // this should be free-ed when outpkt is built in coap_server_respond()
|
||||
if(outpkt->content.p == NULL){
|
||||
NODE_DBG("not enough memory\n");
|
||||
return COAP_ERR_BUFFER_TOO_SMALL;
|
||||
}
|
||||
outpkt->content.len = MAX_PAYLOAD_SIZE;
|
||||
build_well_known_rsp(outpkt->content.p, outpkt->content.len);
|
||||
return coap_make_response(scratch, outpkt, (const uint8_t *)outpkt->content.p, c_strlen(outpkt->content.p), id_hi, id_lo, &inpkt->tok, COAP_RSPCODE_CONTENT, COAP_CONTENTTYPE_APPLICATION_LINKFORMAT);
|
||||
return coap_make_response(scratch, outpkt, (const uint8_t *)outpkt->content.p, strlen(outpkt->content.p), id_hi, id_lo, &inpkt->tok, COAP_RSPCODE_CONTENT, COAP_CONTENTTYPE_APPLICATION_LINKFORMAT);
|
||||
}
|
||||
|
||||
static const coap_endpoint_path_t path_variable = {2, {"v1", "v"}};
|
||||
|
@ -48,19 +48,19 @@ static int handle_get_variable(const coap_endpoint_t *ep, coap_rw_buffer_t *scra
|
|||
{
|
||||
coap_luser_entry *h = ep->user_entry->next; // ->next: skip the first entry(head)
|
||||
while(NULL != h){
|
||||
if (opt[count-1].buf.len != c_strlen(h->name))
|
||||
if (opt[count-1].buf.len != strlen(h->name))
|
||||
{
|
||||
h = h->next;
|
||||
continue;
|
||||
}
|
||||
if (0 == c_memcmp(h->name, opt[count-1].buf.p, opt[count-1].buf.len))
|
||||
if (0 == memcmp(h->name, opt[count-1].buf.p, opt[count-1].buf.len))
|
||||
{
|
||||
NODE_DBG("/v1/v/");
|
||||
NODE_DBG((char *)h->name);
|
||||
NODE_DBG(" match.\n");
|
||||
if(h->L == NULL)
|
||||
return coap_make_response(scratch, outpkt, NULL, 0, id_hi, id_lo, &inpkt->tok, COAP_RSPCODE_NOT_FOUND, COAP_CONTENTTYPE_NONE);
|
||||
if(c_strlen(h->name))
|
||||
if(strlen(h->name))
|
||||
{
|
||||
n = lua_gettop(h->L);
|
||||
lua_getglobal(h->L, h->name);
|
||||
|
@ -71,7 +71,7 @@ static int handle_get_variable(const coap_endpoint_t *ep, coap_rw_buffer_t *scra
|
|||
} else {
|
||||
const char *res = lua_tostring(h->L,-1);
|
||||
lua_settop(h->L, n);
|
||||
return coap_make_response(scratch, outpkt, (const uint8_t *)res, c_strlen(res), id_hi, id_lo, &inpkt->tok, COAP_RSPCODE_CONTENT, h->content_type);
|
||||
return coap_make_response(scratch, outpkt, (const uint8_t *)res, strlen(res), id_hi, id_lo, &inpkt->tok, COAP_RSPCODE_CONTENT, h->content_type);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -105,12 +105,12 @@ static int handle_post_function(const coap_endpoint_t *ep, coap_rw_buffer_t *scr
|
|||
{
|
||||
coap_luser_entry *h = ep->user_entry->next; // ->next: skip the first entry(head)
|
||||
while(NULL != h){
|
||||
if (opt[count-1].buf.len != c_strlen(h->name))
|
||||
if (opt[count-1].buf.len != strlen(h->name))
|
||||
{
|
||||
h = h->next;
|
||||
continue;
|
||||
}
|
||||
if (0 == c_memcmp(h->name, opt[count-1].buf.p, opt[count-1].buf.len))
|
||||
if (0 == memcmp(h->name, opt[count-1].buf.p, opt[count-1].buf.len))
|
||||
{
|
||||
NODE_DBG("/v1/f/");
|
||||
NODE_DBG((char *)h->name);
|
||||
|
@ -119,7 +119,7 @@ static int handle_post_function(const coap_endpoint_t *ep, coap_rw_buffer_t *scr
|
|||
if(h->L == NULL)
|
||||
return coap_make_response(scratch, outpkt, NULL, 0, id_hi, id_lo, &inpkt->tok, COAP_RSPCODE_NOT_FOUND, COAP_CONTENTTYPE_NONE);
|
||||
|
||||
if(c_strlen(h->name))
|
||||
if(strlen(h->name))
|
||||
{
|
||||
n = lua_gettop(h->L);
|
||||
lua_getglobal(h->L, h->name);
|
||||
|
@ -176,7 +176,7 @@ static int handle_post_command(const coap_endpoint_t *ep, coap_rw_buffer_t *scra
|
|||
lua_Load *load = &gLoad;
|
||||
if(load->line_position == 0){
|
||||
coap_buffer_to_string(load->line, load->len,&inpkt->payload);
|
||||
load->line_position = c_strlen(load->line)+1;
|
||||
load->line_position = strlen(load->line)+1;
|
||||
// load->line[load->line_position-1] = '\n';
|
||||
// load->line[load->line_position] = 0;
|
||||
// load->line_position++;
|
||||
|
@ -222,7 +222,7 @@ void build_well_known_rsp(char *rsp, uint16_t rsplen)
|
|||
int i;
|
||||
uint16_t len = rsplen;
|
||||
|
||||
c_memset(rsp, 0, len);
|
||||
memset(rsp, 0, len);
|
||||
|
||||
len--; // Null-terminated string
|
||||
|
||||
|
@ -233,57 +233,57 @@ void build_well_known_rsp(char *rsp, uint16_t rsplen)
|
|||
continue;
|
||||
}
|
||||
if (NULL == ep->user_entry){
|
||||
if (0 < c_strlen(rsp)) {
|
||||
c_strncat(rsp, ",", len);
|
||||
if (0 < strlen(rsp)) {
|
||||
strncat(rsp, ",", len);
|
||||
len--;
|
||||
}
|
||||
|
||||
c_strncat(rsp, "<", len);
|
||||
strncat(rsp, "<", len);
|
||||
len--;
|
||||
|
||||
for (i = 0; i < ep->path->count; i++) {
|
||||
c_strncat(rsp, "/", len);
|
||||
strncat(rsp, "/", len);
|
||||
len--;
|
||||
|
||||
c_strncat(rsp, ep->path->elems[i], len);
|
||||
len -= c_strlen(ep->path->elems[i]);
|
||||
strncat(rsp, ep->path->elems[i], len);
|
||||
len -= strlen(ep->path->elems[i]);
|
||||
}
|
||||
|
||||
c_strncat(rsp, ">;", len);
|
||||
strncat(rsp, ">;", len);
|
||||
len -= 2;
|
||||
|
||||
c_strncat(rsp, ep->core_attr, len);
|
||||
len -= c_strlen(ep->core_attr);
|
||||
strncat(rsp, ep->core_attr, len);
|
||||
len -= strlen(ep->core_attr);
|
||||
} else {
|
||||
coap_luser_entry *h = ep->user_entry->next; // ->next: skip the first entry(head)
|
||||
while(NULL != h){
|
||||
if (0 < c_strlen(rsp)) {
|
||||
c_strncat(rsp, ",", len);
|
||||
if (0 < strlen(rsp)) {
|
||||
strncat(rsp, ",", len);
|
||||
len--;
|
||||
}
|
||||
|
||||
c_strncat(rsp, "<", len);
|
||||
strncat(rsp, "<", len);
|
||||
len--;
|
||||
|
||||
for (i = 0; i < ep->path->count; i++) {
|
||||
c_strncat(rsp, "/", len);
|
||||
strncat(rsp, "/", len);
|
||||
len--;
|
||||
|
||||
c_strncat(rsp, ep->path->elems[i], len);
|
||||
len -= c_strlen(ep->path->elems[i]);
|
||||
strncat(rsp, ep->path->elems[i], len);
|
||||
len -= strlen(ep->path->elems[i]);
|
||||
}
|
||||
|
||||
c_strncat(rsp, "/", len);
|
||||
strncat(rsp, "/", len);
|
||||
len--;
|
||||
|
||||
c_strncat(rsp, h->name, len);
|
||||
len -= c_strlen(h->name);
|
||||
strncat(rsp, h->name, len);
|
||||
len -= strlen(h->name);
|
||||
|
||||
c_strncat(rsp, ">;", len);
|
||||
strncat(rsp, ">;", len);
|
||||
len -= 2;
|
||||
|
||||
c_strncat(rsp, ep->core_attr, len);
|
||||
len -= c_strlen(ep->core_attr);
|
||||
strncat(rsp, ep->core_attr, len);
|
||||
len -= strlen(ep->core_attr);
|
||||
|
||||
h = h->next;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#include "hash.h"
|
||||
#include "c_string.h"
|
||||
#include <string.h>
|
||||
/* Caution: When changing this, update COAP_DEFAULT_WKC_HASHKEY
|
||||
* accordingly (see int coap_hash_path());
|
||||
*/
|
||||
|
@ -20,7 +20,7 @@ void coap_hash(const unsigned char *s, unsigned int len, coap_key_t h) {
|
|||
|
||||
void coap_transaction_id(const uint32_t ip, const uint32_t port, const coap_packet_t *pkt, coap_tid_t *id) {
|
||||
coap_key_t h;
|
||||
c_memset(h, 0, sizeof(coap_key_t));
|
||||
memset(h, 0, sizeof(coap_key_t));
|
||||
|
||||
/* Compare the transport address. */
|
||||
coap_hash((const unsigned char *)&(port), sizeof(port), h);
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
#include "c_string.h"
|
||||
#include "c_stdlib.h"
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "node.h"
|
||||
|
||||
static inline coap_queue_t *
|
||||
coap_malloc_node(void) {
|
||||
return (coap_queue_t *)c_zalloc(sizeof(coap_queue_t));
|
||||
return (coap_queue_t *)zalloc(sizeof(coap_queue_t));
|
||||
}
|
||||
|
||||
void coap_free_node(coap_queue_t *node) {
|
||||
c_free(node);
|
||||
free(node);
|
||||
}
|
||||
|
||||
int coap_insert_node(coap_queue_t **queue, coap_queue_t *node) {
|
||||
|
@ -73,7 +73,7 @@ coap_queue_t * coap_new_node(void) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
c_memset(node, 0, sizeof(*node));
|
||||
memset(node, 0, sizeof(*node));
|
||||
return node;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,38 +1,38 @@
|
|||
#include "c_stdlib.h"
|
||||
#include <stdlib.h>
|
||||
#include "pdu.h"
|
||||
|
||||
coap_pdu_t * coap_new_pdu(void) {
|
||||
coap_pdu_t *pdu = NULL;
|
||||
pdu = (coap_pdu_t *)c_zalloc(sizeof(coap_pdu_t));
|
||||
pdu = (coap_pdu_t *)zalloc(sizeof(coap_pdu_t));
|
||||
if(!pdu){
|
||||
NODE_DBG("coap_new_pdu malloc error.\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pdu->scratch.p = (uint8_t *)c_zalloc(MAX_REQ_SCRATCH_SIZE);
|
||||
pdu->scratch.p = (uint8_t *)zalloc(MAX_REQ_SCRATCH_SIZE);
|
||||
if(!pdu->scratch.p){
|
||||
NODE_DBG("coap_new_pdu malloc error.\n");
|
||||
c_free(pdu);
|
||||
free(pdu);
|
||||
return NULL;
|
||||
}
|
||||
pdu->scratch.len = MAX_REQ_SCRATCH_SIZE;
|
||||
|
||||
pdu->pkt = (coap_packet_t *)c_zalloc(sizeof(coap_packet_t));
|
||||
pdu->pkt = (coap_packet_t *)zalloc(sizeof(coap_packet_t));
|
||||
if(!pdu->pkt){
|
||||
NODE_DBG("coap_new_pdu malloc error.\n");
|
||||
c_free(pdu->scratch.p);
|
||||
c_free(pdu);
|
||||
free(pdu->scratch.p);
|
||||
free(pdu);
|
||||
return NULL;
|
||||
}
|
||||
pdu->pkt->content.p = NULL;
|
||||
pdu->pkt->content.len = 0;
|
||||
|
||||
pdu->msg.p = (uint8_t *)c_zalloc(MAX_REQUEST_SIZE+1); // +1 for string '\0'
|
||||
pdu->msg.p = (uint8_t *)zalloc(MAX_REQUEST_SIZE+1); // +1 for string '\0'
|
||||
if(!pdu->msg.p){
|
||||
NODE_DBG("coap_new_pdu malloc error.\n");
|
||||
c_free(pdu->pkt);
|
||||
c_free(pdu->scratch.p);
|
||||
c_free(pdu);
|
||||
free(pdu->pkt);
|
||||
free(pdu->scratch.p);
|
||||
free(pdu);
|
||||
return NULL;
|
||||
}
|
||||
pdu->msg.len = MAX_REQUEST_SIZE;
|
||||
|
@ -44,22 +44,22 @@ void coap_delete_pdu(coap_pdu_t *pdu){
|
|||
return;
|
||||
|
||||
if(pdu->scratch.p){
|
||||
c_free(pdu->scratch.p);
|
||||
free(pdu->scratch.p);
|
||||
pdu->scratch.p = NULL;
|
||||
pdu->scratch.len = 0;
|
||||
}
|
||||
|
||||
if(pdu->pkt){
|
||||
c_free(pdu->pkt);
|
||||
free(pdu->pkt);
|
||||
pdu->pkt = NULL;
|
||||
}
|
||||
|
||||
if(pdu->msg.p){
|
||||
c_free(pdu->msg.p);
|
||||
free(pdu->msg.p);
|
||||
pdu->msg.p = NULL;
|
||||
pdu->msg.len = 0;
|
||||
}
|
||||
|
||||
c_free(pdu);
|
||||
free(pdu);
|
||||
pdu = NULL;
|
||||
}
|
||||
|
|
|
@ -6,23 +6,23 @@
|
|||
* README for terms of use.
|
||||
*/
|
||||
|
||||
#include "c_stdlib.h"
|
||||
#include "c_types.h"
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include "str.h"
|
||||
|
||||
str * coap_new_string(size_t size) {
|
||||
str *s = (str *)c_malloc(sizeof(str) + size + 1);
|
||||
str *s = (str *)malloc(sizeof(str) + size + 1);
|
||||
if ( !s ) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
c_memset(s, 0, sizeof(str));
|
||||
memset(s, 0, sizeof(str));
|
||||
s->s = ((unsigned char *)s) + sizeof(str);
|
||||
return s;
|
||||
}
|
||||
|
||||
void coap_delete_string(str *s) {
|
||||
c_free(s);
|
||||
free(s);
|
||||
}
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
#ifndef _COAP_STR_H_
|
||||
#define _COAP_STR_H_
|
||||
|
||||
#include "c_string.h"
|
||||
#include <string.h>
|
||||
|
||||
typedef struct {
|
||||
size_t length; /* length of string */
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
/* uri.c -- helper functions for URI treatment
|
||||
*/
|
||||
|
||||
#include "c_stdio.h"
|
||||
#include "c_stdlib.h"
|
||||
#include "c_string.h"
|
||||
#include "c_ctype.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include "coap.h"
|
||||
#include "uri.h"
|
||||
|
@ -43,7 +43,7 @@ int coap_split_uri(unsigned char *str_var, size_t len, coap_uri_t *uri) {
|
|||
if (!str_var || !uri)
|
||||
return -1;
|
||||
|
||||
c_memset(uri, 0, sizeof(coap_uri_t));
|
||||
memset(uri, 0, sizeof(coap_uri_t));
|
||||
uri->port = COAP_DEFAULT_PORT;
|
||||
|
||||
/* search for scheme */
|
||||
|
@ -394,16 +394,16 @@ int coap_split_query(coap_rw_buffer_t *scratch, coap_packet_t *pkt, const unsign
|
|||
coap_uri_t * coap_new_uri(const unsigned char *uri, unsigned int length) {
|
||||
unsigned char *result;
|
||||
|
||||
result = (unsigned char *)c_malloc(length + 1 + sizeof(coap_uri_t));
|
||||
result = (unsigned char *)malloc(length + 1 + sizeof(coap_uri_t));
|
||||
|
||||
if (!result)
|
||||
return NULL;
|
||||
|
||||
c_memcpy(URI_DATA(result), uri, length);
|
||||
memcpy(URI_DATA(result), uri, length);
|
||||
URI_DATA(result)[length] = '\0'; /* make it zero-terminated */
|
||||
|
||||
if (coap_split_uri(URI_DATA(result), length, (coap_uri_t *)result) < 0) {
|
||||
c_free(result);
|
||||
free(result);
|
||||
return NULL;
|
||||
}
|
||||
return (coap_uri_t *)result;
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
#include "osapi.h"
|
||||
#include "mem.h"
|
||||
#include <string.h>
|
||||
#include <c_errno.h>
|
||||
#include <errno.h>
|
||||
|
||||
#ifdef MD2_ENABLE
|
||||
#include "ssl/ssl_crypto.h"
|
||||
|
@ -109,7 +109,7 @@ int ICACHE_FLASH_ATTR crypto_hash (const digest_mech_info_t *mi,
|
|||
if (!mi)
|
||||
return EINVAL;
|
||||
|
||||
void *ctx = (void *)os_malloc (mi->ctx_size);
|
||||
void *ctx = (void *)malloc (mi->ctx_size);
|
||||
if (!ctx)
|
||||
return ENOMEM;
|
||||
|
||||
|
@ -117,7 +117,7 @@ int ICACHE_FLASH_ATTR crypto_hash (const digest_mech_info_t *mi,
|
|||
mi->update (ctx, data, data_len);
|
||||
mi->finalize (digest, ctx);
|
||||
|
||||
os_free (ctx);
|
||||
free (ctx);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -130,13 +130,13 @@ int ICACHE_FLASH_ATTR crypto_fhash (const digest_mech_info_t *mi,
|
|||
return EINVAL;
|
||||
|
||||
// Initialise
|
||||
void *ctx = (void *)os_malloc (mi->ctx_size);
|
||||
void *ctx = (void *)malloc (mi->ctx_size);
|
||||
if (!ctx)
|
||||
return ENOMEM;
|
||||
mi->create (ctx);
|
||||
|
||||
// Hash bytes from file in blocks
|
||||
uint8_t* buffer = (uint8_t*)os_malloc (mi->block_size);
|
||||
uint8_t* buffer = (uint8_t*)malloc (mi->block_size);
|
||||
if (!buffer)
|
||||
return ENOMEM;
|
||||
|
||||
|
@ -149,8 +149,8 @@ int ICACHE_FLASH_ATTR crypto_fhash (const digest_mech_info_t *mi,
|
|||
// Finish up
|
||||
mi->finalize (digest, ctx);
|
||||
|
||||
os_free (buffer);
|
||||
os_free (ctx);
|
||||
free (buffer);
|
||||
free (ctx);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -163,7 +163,7 @@ int ICACHE_FLASH_ATTR crypto_hmac (const digest_mech_info_t *mi,
|
|||
if (!mi)
|
||||
return EINVAL;
|
||||
|
||||
void *ctx = (void *)os_malloc (mi->ctx_size);
|
||||
void *ctx = (void *)malloc (mi->ctx_size);
|
||||
if (!ctx)
|
||||
return ENOMEM;
|
||||
|
||||
|
@ -200,6 +200,6 @@ int ICACHE_FLASH_ATTR crypto_hmac (const digest_mech_info_t *mi,
|
|||
mi->update (ctx, digest, mi->digest_size);
|
||||
mi->finalize (digest, ctx);
|
||||
|
||||
os_free (ctx);
|
||||
free (ctx);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -13,15 +13,15 @@ typedef size_t ( *read_fn )(int fd, void *ptr, size_t len);
|
|||
*
|
||||
* Typical usage (if not using the crypto_xxxx() functions below):
|
||||
* digest_mech_info_t *mi = crypto_digest_mech (chosen_algorithm);
|
||||
* void *ctx = os_malloc (mi->ctx_size);
|
||||
* void *ctx = malloc (mi->ctx_size);
|
||||
* mi->create (ctx);
|
||||
* mi->update (ctx, data, len);
|
||||
* ...
|
||||
* uint8_t *digest = os_malloc (mi->digest_size);
|
||||
* uint8_t *digest = malloc (mi->digest_size);
|
||||
* mi->finalize (digest, ctx);
|
||||
* ...
|
||||
* os_free (ctx);
|
||||
* os_free (digest);
|
||||
* free (ctx);
|
||||
* free (digest);
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
|
||||
#include "mech.h"
|
||||
#include "sdk-aes.h"
|
||||
#include "c_string.h"
|
||||
#include <string.h>
|
||||
|
||||
/* ----- AES ---------------------------------------------------------- */
|
||||
|
||||
|
@ -58,7 +58,7 @@ static bool do_aes (crypto_op_t *co, bool with_cbc)
|
|||
|
||||
char iv[AES_BLOCKSIZE] = { 0 };
|
||||
if (with_cbc && co->ivlen)
|
||||
c_memcpy (iv, co->iv, co->ivlen < AES_BLOCKSIZE ? co->ivlen : AES_BLOCKSIZE);
|
||||
memcpy (iv, co->iv, co->ivlen < AES_BLOCKSIZE ? co->ivlen : AES_BLOCKSIZE);
|
||||
|
||||
const char *src = co->data;
|
||||
char *dst = co->out;
|
||||
|
@ -68,7 +68,7 @@ static bool do_aes (crypto_op_t *co, bool with_cbc)
|
|||
{
|
||||
char block[AES_BLOCKSIZE] = { 0 };
|
||||
size_t n = left > AES_BLOCKSIZE ? AES_BLOCKSIZE : left;
|
||||
c_memcpy (block, src, n);
|
||||
memcpy (block, src, n);
|
||||
|
||||
if (with_cbc && co->op == OP_ENCRYPT)
|
||||
{
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
|
||||
#include "user_interface.h"
|
||||
#include "platform.h"
|
||||
#include "c_stdio.h"
|
||||
#include <stdio.h>
|
||||
#include "dht.h"
|
||||
|
||||
#ifndef LOW
|
||||
|
|
|
@ -33,7 +33,7 @@ LOCAL void ICACHE_RAM_ATTR key_intr_handler(void *arg);
|
|||
struct single_key_param *ICACHE_FLASH_ATTR
|
||||
key_init_single(uint8 gpio_id, uint32 gpio_name, uint8 gpio_func, key_function long_press, key_function short_press)
|
||||
{
|
||||
struct single_key_param *single_key = (struct single_key_param *)os_zalloc(sizeof(struct single_key_param));
|
||||
struct single_key_param *single_key = (struct single_key_param *)zalloc(sizeof(struct single_key_param));
|
||||
|
||||
single_key->gpio_id = gpio_id;
|
||||
single_key->gpio_name = gpio_name;
|
||||
|
|
|
@ -12,8 +12,8 @@
|
|||
|
||||
#include "platform.h"
|
||||
#include "c_types.h"
|
||||
#include "../libc/c_stdlib.h"
|
||||
#include "../libc/c_stdio.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include "driver/rotary.h"
|
||||
#include "user_interface.h"
|
||||
#include "esp_system.h"
|
||||
|
@ -88,7 +88,7 @@ int rotary_close(uint32_t channel)
|
|||
rotary_clear_pin(d->phase_b_pin);
|
||||
rotary_clear_pin(d->press_pin);
|
||||
|
||||
os_free(d);
|
||||
free(d);
|
||||
|
||||
set_gpio_bits();
|
||||
|
||||
|
@ -178,7 +178,7 @@ static uint32_t ICACHE_RAM_ATTR rotary_interrupt(uint32_t ret_gpio_status)
|
|||
if (HAS_QUEUE_SPACE(d)) {
|
||||
QUEUE_STATUS(d, new_status);
|
||||
if (!task_queued) {
|
||||
if (task_post_medium(d->tasknumber, (os_param_t) &task_queued)) {
|
||||
if (task_post_medium(d->tasknumber, (task_param_t) &task_queued)) {
|
||||
task_queued = 1;
|
||||
}
|
||||
}
|
||||
|
@ -208,7 +208,7 @@ int rotary_setup(uint32_t channel, int phase_a, int phase_b, int press, task_han
|
|||
}
|
||||
}
|
||||
|
||||
DATA *d = (DATA *) os_zalloc(sizeof(DATA));
|
||||
DATA *d = (DATA *) zalloc(sizeof(DATA));
|
||||
if (!d) {
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -650,7 +650,7 @@ void ICACHE_FLASH_ATTR
|
|||
void ICACHE_FLASH_ATTR
|
||||
spi_task_init(void)
|
||||
{
|
||||
spiQueue = (os_event_t*)os_malloc(sizeof(os_event_t)*SPI_QUEUE_LEN);
|
||||
spiQueue = (os_event_t*)malloc(sizeof(os_event_t)*SPI_QUEUE_LEN);
|
||||
system_os_task(spi_task,USER_TASK_PRIO_1,spiQueue,SPI_QUEUE_LEN);
|
||||
}
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@ static char * ICACHE_FLASH_ATTR esp_strdup( const char * str )
|
|||
{
|
||||
return(NULL);
|
||||
}
|
||||
char * new_str = (char *) os_malloc( os_strlen( str ) + 1 ); /* 1 for null character */
|
||||
char * new_str = (char *) malloc( os_strlen( str ) + 1 ); /* 1 for null character */
|
||||
if ( new_str == NULL )
|
||||
{
|
||||
HTTPCLIENT_DEBUG( "esp_strdup: malloc error" );
|
||||
|
@ -132,7 +132,7 @@ static void ICACHE_FLASH_ATTR http_receive_callback( void * arg, char * buf, uns
|
|||
/* Let's do the equivalent of a realloc(). */
|
||||
const int new_size = req->buffer_size + len;
|
||||
char * new_buffer;
|
||||
if ( new_size > BUFFER_SIZE_MAX || NULL == (new_buffer = (char *) os_malloc( new_size ) ) )
|
||||
if ( new_size > BUFFER_SIZE_MAX || NULL == (new_buffer = (char *) malloc( new_size ) ) )
|
||||
{
|
||||
HTTPCLIENT_DEBUG( "Response too long (%d)\n", new_size );
|
||||
req->buffer[0] = '\0'; /* Discard the buffer to avoid using an incomplete response. */
|
||||
|
@ -149,7 +149,7 @@ static void ICACHE_FLASH_ATTR http_receive_callback( void * arg, char * buf, uns
|
|||
os_memcpy( new_buffer + req->buffer_size - 1 /*overwrite the null character*/, buf, len ); /* Append new data. */
|
||||
new_buffer[new_size - 1] = '\0'; /* Make sure there is an end of string. */
|
||||
|
||||
os_free( req->buffer );
|
||||
free( req->buffer );
|
||||
req->buffer = new_buffer;
|
||||
req->buffer_size = new_size;
|
||||
}
|
||||
|
@ -174,7 +174,7 @@ static void ICACHE_FLASH_ATTR http_send_callback( void * arg )
|
|||
else
|
||||
#endif
|
||||
espconn_send( conn, (uint8_t *) req->post_data, strlen( req->post_data ) );
|
||||
os_free( req->post_data );
|
||||
free( req->post_data );
|
||||
req->post_data = NULL;
|
||||
}
|
||||
}
|
||||
|
@ -198,7 +198,7 @@ static void ICACHE_FLASH_ATTR http_connect_callback( void * arg )
|
|||
|
||||
if(req->headers == NULL) /* Avoid NULL pointer, it may cause exception */
|
||||
{
|
||||
req->headers = (char *)os_malloc(sizeof(char));
|
||||
req->headers = (char *)malloc(sizeof(char));
|
||||
req->headers[0] = '\0';
|
||||
}
|
||||
|
||||
|
@ -221,7 +221,7 @@ static void ICACHE_FLASH_ATTR http_connect_callback( void * arg )
|
|||
#endif
|
||||
espconn_send( conn, (uint8_t *) buf, len );
|
||||
if(req->headers != NULL)
|
||||
os_free( req->headers );
|
||||
free( req->headers );
|
||||
req->headers = NULL;
|
||||
HTTPCLIENT_DEBUG( "Sending request header\n" );
|
||||
}
|
||||
|
@ -239,7 +239,7 @@ static void ICACHE_FLASH_ATTR http_disconnect_callback( void * arg )
|
|||
|
||||
if ( conn->proto.tcp != NULL )
|
||||
{
|
||||
os_free( conn->proto.tcp );
|
||||
free( conn->proto.tcp );
|
||||
}
|
||||
if ( conn->reverse != NULL )
|
||||
{
|
||||
|
@ -295,16 +295,16 @@ static void ICACHE_FLASH_ATTR http_disconnect_callback( void * arg )
|
|||
req->callback_handle( body, http_status, req->buffer );
|
||||
}
|
||||
if (req->buffer) {
|
||||
os_free( req->buffer );
|
||||
free( req->buffer );
|
||||
}
|
||||
os_free( req->hostname );
|
||||
os_free( req->method );
|
||||
os_free( req->path );
|
||||
os_free( req );
|
||||
free( req->hostname );
|
||||
free( req->method );
|
||||
free( req->path );
|
||||
free( req );
|
||||
}
|
||||
/* Fix memory leak. */
|
||||
espconn_delete( conn );
|
||||
os_free( conn );
|
||||
free( conn );
|
||||
}
|
||||
|
||||
|
||||
|
@ -349,16 +349,16 @@ static void ICACHE_FLASH_ATTR http_dns_callback( const char * hostname, ip_addr_
|
|||
{
|
||||
req->callback_handle( "", -1, "" );
|
||||
}
|
||||
os_free( req );
|
||||
free( req );
|
||||
}
|
||||
else
|
||||
{
|
||||
HTTPCLIENT_DEBUG( "DNS found %s " IPSTR "\n", hostname, IP2STR( addr ) );
|
||||
|
||||
struct espconn * conn = (struct espconn *) os_zalloc( sizeof(struct espconn) );
|
||||
struct espconn * conn = (struct espconn *) zalloc( sizeof(struct espconn) );
|
||||
conn->type = ESPCONN_TCP;
|
||||
conn->state = ESPCONN_NONE;
|
||||
conn->proto.tcp = (esp_tcp *) os_zalloc( sizeof(esp_tcp) );
|
||||
conn->proto.tcp = (esp_tcp *) zalloc( sizeof(esp_tcp) );
|
||||
conn->proto.tcp->local_port = espconn_port();
|
||||
conn->proto.tcp->remote_port = req->port;
|
||||
conn->reverse = req;
|
||||
|
@ -393,7 +393,7 @@ void ICACHE_FLASH_ATTR http_raw_request( const char * hostname, int port, bool s
|
|||
{
|
||||
HTTPCLIENT_DEBUG( "DNS request\n" );
|
||||
|
||||
request_args_t * req = (request_args_t *) os_zalloc( sizeof(request_args_t) );
|
||||
request_args_t * req = (request_args_t *) zalloc( sizeof(request_args_t) );
|
||||
req->hostname = esp_strdup( hostname );
|
||||
req->port = port;
|
||||
req->secure = secure;
|
||||
|
@ -402,7 +402,7 @@ void ICACHE_FLASH_ATTR http_raw_request( const char * hostname, int port, bool s
|
|||
req->headers = esp_strdup( headers );
|
||||
req->post_data = esp_strdup( post_data );
|
||||
req->buffer_size = 1;
|
||||
req->buffer = (char *) os_malloc( 1 );
|
||||
req->buffer = (char *) malloc( 1 );
|
||||
req->buffer[0] = '\0'; /* Empty string. */
|
||||
req->callback_handle = callback_handle;
|
||||
req->timeout = HTTP_REQUEST_TIMEOUT_MS;
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#ifndef READLINE_APP_H
|
||||
#define READLINE_APP_H
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
bool uart_getc(char *c);
|
||||
|
||||
#endif /* READLINE_APP_H */
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include "eagle_soc.h"
|
||||
#include "c_types.h"
|
||||
#include "os_type.h"
|
||||
#include "task/task.h"
|
||||
|
||||
#define RX_BUFF_SIZE 0x100
|
||||
#define TX_BUFF_SIZE 100
|
||||
|
@ -101,7 +102,7 @@ typedef struct {
|
|||
int buff_uart_no; //indicate which uart use tx/rx buffer
|
||||
} UartDevice;
|
||||
|
||||
void uart_init(UartBautRate uart0_br, UartBautRate uart1_br, os_signal_t sig_input);
|
||||
void uart_init(UartBautRate uart0_br, UartBautRate uart1_br, task_handle_t sig_input);
|
||||
void uart0_alt(uint8 on);
|
||||
void uart0_sendStr(const char *str);
|
||||
void uart0_putc(const char c);
|
||||
|
|
|
@ -38,13 +38,13 @@ extern void luaL_assertfail(const char *file, int line, const char *message);
|
|||
#define NODE_ERROR
|
||||
|
||||
#ifdef NODE_DEBUG
|
||||
#define NODE_DBG c_printf
|
||||
#define NODE_DBG printf
|
||||
#else
|
||||
#define NODE_DBG
|
||||
#endif /* NODE_DEBUG */
|
||||
|
||||
#ifdef NODE_ERROR
|
||||
#define NODE_ERR c_printf
|
||||
#define NODE_ERR printf
|
||||
#else
|
||||
#define NODE_ERR
|
||||
#endif /* NODE_ERROR */
|
||||
|
|
|
@ -1,43 +0,0 @@
|
|||
|
||||
#############################################################
|
||||
# Required variables for each makefile
|
||||
# Discard this section from all parent makefiles
|
||||
# Expected variables (with automatic defaults):
|
||||
# CSRCS (all "C" files in the dir)
|
||||
# SUBDIRS (all subdirs with a Makefile)
|
||||
# GEN_LIBS - list of libs to be generated ()
|
||||
# GEN_IMAGES - list of images to be generated ()
|
||||
# COMPONENTS_xxx - a list of libs/objs in the form
|
||||
# subdir/lib to be extracted and rolled up into
|
||||
# a generated lib/image xxx.a ()
|
||||
#
|
||||
ifndef PDIR
|
||||
GEN_LIBS = liblibc.a
|
||||
endif
|
||||
|
||||
#############################################################
|
||||
# Configuration i.e. compile options etc.
|
||||
# Target specific stuff (defines etc.) goes in here!
|
||||
# Generally values applying to a tree are captured in the
|
||||
# makefile at its root level - these are then overridden
|
||||
# for a subtree within the makefile rooted therein
|
||||
#
|
||||
#DEFINES +=
|
||||
|
||||
#############################################################
|
||||
# Recursion Magic - Don't touch this!!
|
||||
#
|
||||
# Each subtree potentially has an include directory
|
||||
# corresponding to the common APIs applicable to modules
|
||||
# rooted at that subtree. Accordingly, the INCLUDE PATH
|
||||
# of a module can only contain the include directories up
|
||||
# its parent path, and not its siblings
|
||||
#
|
||||
# Required for each makefile to inherit from the parent
|
||||
#
|
||||
|
||||
INCLUDES := $(INCLUDES) -I $(PDIR)include
|
||||
INCLUDES += -I ./
|
||||
PDIR := ../$(PDIR)
|
||||
sinclude $(PDIR)Makefile
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
#include "c_ctype.h"
|
||||
#include "c_types.h"
|
||||
|
||||
// int isalnum(int c){}
|
||||
// int isalpha(int c){}
|
||||
// int iscntrl(int c){}
|
||||
// int isdigit(int c){}
|
||||
// // int isgraph(int c){}
|
||||
// int islower(int c){}
|
||||
// int isprint(int c){}
|
||||
// int ispunct(int c){}
|
||||
// int isspace(int c){}
|
||||
// int isupper(int c){}
|
||||
// int isxdigit(int c){}
|
||||
// int tolower(int c){}
|
||||
// int toupper(int c){}
|
|
@ -1,42 +0,0 @@
|
|||
#ifndef _C_CTYPE_H_
|
||||
#define _C_CTYPE_H_
|
||||
|
||||
#if 0
|
||||
int isalnum(int);
|
||||
int isalpha(int);
|
||||
int iscntrl(int);
|
||||
int isdigit(int);
|
||||
// int isgraph(int);
|
||||
int islower(int);
|
||||
int isprint(int);
|
||||
int ispunct(int);
|
||||
int isspace(int);
|
||||
int isupper(int);
|
||||
int isxdigit(int);
|
||||
int tolower(int);
|
||||
int toupper(int);
|
||||
|
||||
#if !defined(__STRICT_ANSI__) || defined(__cplusplus) || __STDC_VERSION__ >= 199901L
|
||||
// int isblank(int);
|
||||
#endif
|
||||
|
||||
#ifndef __STRICT_ANSI__
|
||||
// int isascii(int);
|
||||
// int toascii(int);
|
||||
#define _tolower(__c) ((unsigned char)(__c) - 'A' + 'a')
|
||||
#define _toupper(__c) ((unsigned char)(__c) - 'a' + 'A')
|
||||
#endif
|
||||
|
||||
#define _U 01
|
||||
#define _L 02
|
||||
#define _N 04
|
||||
#define _S 010
|
||||
#define _P 020
|
||||
#define _C 040
|
||||
#define _X 0100
|
||||
#define _B 0200
|
||||
|
||||
/* For C++ backward-compatibility only. */
|
||||
// extern char _ctype_[];
|
||||
#endif
|
||||
#endif /* _C_CTYPE_H_ */
|
|
@ -1,19 +0,0 @@
|
|||
#ifndef __c_errno_h
|
||||
#define __c_errno_h
|
||||
|
||||
#include <errno.h>
|
||||
// #ifndef errno
|
||||
// extern int errno;
|
||||
// #endif
|
||||
|
||||
// #define EDOM 1
|
||||
// #define ERANGE 2
|
||||
// #define EILSEQ 4
|
||||
// #define ESIGNUM 3
|
||||
// #define EINVAL 5
|
||||
// #define ENOMEM 6
|
||||
|
||||
#endif
|
||||
|
||||
/* end of c_errno.h */
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
#ifndef __c_fcntl_h
|
||||
#define __c_fcntl_h
|
||||
|
||||
#include <fcntl.h>
|
||||
|
||||
#endif
|
||||
|
||||
/* end of c_fcntl.h */
|
||||
|
|
@ -1,58 +0,0 @@
|
|||
#ifndef __c_limits_h
|
||||
#define __c_limits_h
|
||||
|
||||
#include <limits.h>
|
||||
#if 0
|
||||
#define CHAR_BIT 8
|
||||
/* max number of bits for smallest object that is not a bit-field (byte) */
|
||||
#define SCHAR_MIN (-128)
|
||||
/* mimimum value for an object of type signed char */
|
||||
#define SCHAR_MAX 127
|
||||
/* maximum value for an object of type signed char */
|
||||
#define UCHAR_MAX 255
|
||||
/* maximum value for an object of type unsigned char */
|
||||
#ifdef __FEATURE_SIGNED_CHAR
|
||||
#define CHAR_MIN (-128)
|
||||
/* minimum value for an object of type char */
|
||||
#define CHAR_MAX 127
|
||||
/* maximum value for an object of type char */
|
||||
#else
|
||||
#define CHAR_MIN 0
|
||||
/* minimum value for an object of type char */
|
||||
#define CHAR_MAX 255
|
||||
/* maximum value for an object of type char */
|
||||
#endif
|
||||
|
||||
#define SHRT_MIN (-0x8000)
|
||||
/* minimum value for an object of type short int */
|
||||
#define SHRT_MAX 0x7fff
|
||||
/* maximum value for an object of type short int */
|
||||
#define USHRT_MAX 65535
|
||||
/* maximum value for an object of type unsigned short int */
|
||||
#define INT_MIN (~0x7fffffff) /* -2147483648 and 0x80000000 are unsigned */
|
||||
/* minimum value for an object of type int */
|
||||
#define INT_MAX 0x7fffffff
|
||||
/* maximum value for an object of type int */
|
||||
#define UINT_MAX 0xffffffffU
|
||||
/* maximum value for an object of type unsigned int */
|
||||
#define LONG_MIN (~0x7fffffffL)
|
||||
/* minimum value for an object of type long int */
|
||||
#define LONG_MAX 0x7fffffffL
|
||||
/* maximum value for an object of type long int */
|
||||
#define ULONG_MAX 0xffffffffUL
|
||||
/* maximum value for an object of type unsigned long int */
|
||||
#if !defined(__STRICT_ANSI__) || (defined(__STDC_VERSION__) && 199901L <= __STDC_VERSION__)
|
||||
#define LLONG_MIN (~0x7fffffffffffffffLL)
|
||||
/* minimum value for an object of type long long int */
|
||||
#define LLONG_MAX 0x7fffffffffffffffLL
|
||||
/* maximum value for an object of type long long int */
|
||||
#define ULLONG_MAX 0xffffffffffffffffULL
|
||||
/* maximum value for an object of type unsigned long int */
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/* end of c_limits.h */
|
||||
|
|
@ -1,62 +0,0 @@
|
|||
/*
|
||||
c_locale.h
|
||||
Values appropriate for the formatting of monetary and other
|
||||
numberic quantities.
|
||||
*/
|
||||
|
||||
#ifndef _C_LOCALE_H_
|
||||
#define _C_LOCALE_H_
|
||||
|
||||
#include <locale.h>
|
||||
|
||||
#if 0
|
||||
#ifndef NULL
|
||||
#define NULL 0
|
||||
#endif
|
||||
|
||||
#define LC_ALL 0
|
||||
#define LC_COLLATE 1
|
||||
#define LC_CTYPE 2
|
||||
#define LC_MONETARY 3
|
||||
#define LC_NUMERIC 4
|
||||
#define LC_TIME 5
|
||||
#define LC_MESSAGES 6
|
||||
|
||||
struct lconv
|
||||
{
|
||||
char *decimal_point;
|
||||
char *thousands_sep;
|
||||
char *grouping;
|
||||
char *int_curr_symbol;
|
||||
char *currency_symbol;
|
||||
char *mon_decimal_point;
|
||||
char *mon_thousands_sep;
|
||||
char *mon_grouping;
|
||||
char *positive_sign;
|
||||
char *negative_sign;
|
||||
char int_frac_digits;
|
||||
char frac_digits;
|
||||
char p_cs_precedes;
|
||||
char p_sep_by_space;
|
||||
char n_cs_precedes;
|
||||
char n_sep_by_space;
|
||||
char p_sign_posn;
|
||||
char n_sign_posn;
|
||||
char int_n_cs_precedes;
|
||||
char int_n_sep_by_space;
|
||||
char int_n_sign_posn;
|
||||
char int_p_cs_precedes;
|
||||
char int_p_sep_by_space;
|
||||
char int_p_sign_posn;
|
||||
};
|
||||
|
||||
#ifndef _REENT_ONLY
|
||||
// char *setlocale(int category, const char *locale);
|
||||
struct lconv *localeconv(void);
|
||||
#endif
|
||||
|
||||
// struct _reent;
|
||||
// char *_setlocale_r(struct _reent *, int category, const char *locale);
|
||||
// struct lconv *_localeconv_r(struct _reent *);
|
||||
#endif
|
||||
#endif /* _C_LOCALE_H_ */
|
|
@ -1,229 +0,0 @@
|
|||
#include "c_math.h"
|
||||
#include "c_types.h"
|
||||
#include "user_config.h"
|
||||
|
||||
double floor(double x)
|
||||
{
|
||||
return (double) (x < 0.f ? (((int) x) - 1) : ((int) x));
|
||||
}
|
||||
|
||||
#define MAXEXP 2031 /* (MAX_EXP * 16) - 1 */
|
||||
#define MINEXP -2047 /* (MIN_EXP * 16) - 1 */
|
||||
#define HUGE MAXFLOAT
|
||||
|
||||
double a1[] ICACHE_STORE_ATTR ICACHE_RODATA_ATTR =
|
||||
{
|
||||
1.0,
|
||||
0.95760328069857365,
|
||||
0.91700404320467123,
|
||||
0.87812608018664974,
|
||||
0.84089641525371454,
|
||||
0.80524516597462716,
|
||||
0.77110541270397041,
|
||||
0.73841307296974966,
|
||||
0.70710678118654752,
|
||||
0.67712777346844637,
|
||||
0.64841977732550483,
|
||||
0.62092890603674203,
|
||||
0.59460355750136054,
|
||||
0.56939431737834583,
|
||||
0.54525386633262883,
|
||||
0.52213689121370692,
|
||||
0.50000000000000000
|
||||
};
|
||||
double a2[] ICACHE_STORE_ATTR ICACHE_RODATA_ATTR =
|
||||
{
|
||||
0.24114209503420288E-17,
|
||||
0.92291566937243079E-18,
|
||||
-0.15241915231122319E-17,
|
||||
-0.35421849765286817E-17,
|
||||
-0.31286215245415074E-17,
|
||||
-0.44654376565694490E-17,
|
||||
0.29306999570789681E-17,
|
||||
0.11260851040933474E-17
|
||||
};
|
||||
double p1 ICACHE_STORE_ATTR ICACHE_RODATA_ATTR = 0.833333333333332114e-1;
|
||||
double p2 ICACHE_STORE_ATTR ICACHE_RODATA_ATTR = 0.125000000005037992e-1;
|
||||
double p3 ICACHE_STORE_ATTR ICACHE_RODATA_ATTR = 0.223214212859242590e-2;
|
||||
double p4 ICACHE_STORE_ATTR ICACHE_RODATA_ATTR = 0.434457756721631196e-3;
|
||||
double q1 ICACHE_STORE_ATTR ICACHE_RODATA_ATTR = 0.693147180559945296e0;
|
||||
double q2 ICACHE_STORE_ATTR ICACHE_RODATA_ATTR = 0.240226506959095371e0;
|
||||
double q3 ICACHE_STORE_ATTR ICACHE_RODATA_ATTR = 0.555041086640855953e-1;
|
||||
double q4 ICACHE_STORE_ATTR ICACHE_RODATA_ATTR = 0.961812905951724170e-2;
|
||||
double q5 ICACHE_STORE_ATTR ICACHE_RODATA_ATTR = 0.133335413135857847e-2;
|
||||
double q6 ICACHE_STORE_ATTR ICACHE_RODATA_ATTR = 0.154002904409897646e-3;
|
||||
double q7 ICACHE_STORE_ATTR ICACHE_RODATA_ATTR = 0.149288526805956082e-4;
|
||||
double k ICACHE_STORE_ATTR ICACHE_RODATA_ATTR = 0.442695040888963407;
|
||||
|
||||
double pow(double x, double y)
|
||||
{
|
||||
double frexp(), g, ldexp(), r, u1, u2, v, w, w1, w2, y1, y2, z;
|
||||
int iw1, m, p;
|
||||
|
||||
if (y == 0.0)
|
||||
return (1.0);
|
||||
if (x <= 0.0)
|
||||
{
|
||||
if (x == 0.0)
|
||||
{
|
||||
if (y > 0.0)
|
||||
return (x);
|
||||
//cmemsg(FP_POWO, &y);
|
||||
//return(HUGE);
|
||||
}
|
||||
else
|
||||
{
|
||||
//cmemsg(FP_POWN, &x);
|
||||
x = -x;
|
||||
}
|
||||
}
|
||||
g = frexp(x, &m);
|
||||
p = 0;
|
||||
if (g <= a1[8])
|
||||
p = 8;
|
||||
if (g <= a1[p + 4])
|
||||
p += 4;
|
||||
if (g <= a1[p + 2])
|
||||
p += 2;
|
||||
p++;
|
||||
z = ((g - a1[p]) - a2[p / 2]) / (g + a1[p]);
|
||||
z += z;
|
||||
v = z * z;
|
||||
r = (((p4 * v + p3) * v + p2) * v + p1) * v * z;
|
||||
r += k * r;
|
||||
u2 = (r + z * k) + z;
|
||||
u1 = 0.0625 * (double)(16 * m - p);
|
||||
y1 = 0.0625 * (double)((int)(16.0 * y));
|
||||
y2 = y - y1;
|
||||
w = u2 * y + u1 * y2;
|
||||
w1 = 0.0625 * (double)((int)(16.0 * w));
|
||||
w2 = w - w1;
|
||||
w = w1 + u1 * y1;
|
||||
w1 = 0.0625 * (double)((int)(16.0 * w));
|
||||
w2 += (w - w1);
|
||||
w = 0.0625 * (double)((int)(16.0 * w2));
|
||||
iw1 = 16.0 * (w1 + w);
|
||||
w2 -= w;
|
||||
while (w2 > 0.0)
|
||||
{
|
||||
iw1++;
|
||||
w2 -= 0.0625;
|
||||
}
|
||||
if (iw1 > MAXEXP)
|
||||
{
|
||||
//cmemsg(FP_POWO, &y);
|
||||
return (HUGE);
|
||||
}
|
||||
if (iw1 < MINEXP)
|
||||
{
|
||||
//cmemsg(FP_POWU, &y);
|
||||
return (0.0);
|
||||
}
|
||||
m = iw1 / 16;
|
||||
if (iw1 >= 0)
|
||||
m++;
|
||||
p = 16 * m - iw1;
|
||||
z = ((((((q7 * w2 + q6) * w2 + q5) * w2 + q4) * w2 + q3) * w2 + q2) * w2 + q1) * w2;
|
||||
z = a1[p] + a1[p] * z;
|
||||
return (ldexp(z, m));
|
||||
}
|
||||
|
||||
#if 0
|
||||
#ifndef __math_68881
|
||||
double atan(double x)
|
||||
{
|
||||
return x;
|
||||
}
|
||||
double cos(double x)
|
||||
{
|
||||
return x;
|
||||
}
|
||||
double sin(double x)
|
||||
{
|
||||
return x;
|
||||
}
|
||||
double tan(double x)
|
||||
{
|
||||
return x;
|
||||
}
|
||||
double tanh(double x)
|
||||
{
|
||||
return x;
|
||||
}
|
||||
double frexp(double x, int *y)
|
||||
{
|
||||
return x;
|
||||
}
|
||||
double modf(double x, double *y)
|
||||
{
|
||||
return x;
|
||||
}
|
||||
double ceil(double x)
|
||||
{
|
||||
return x;
|
||||
}
|
||||
double fabs(double x)
|
||||
{
|
||||
return x;
|
||||
}
|
||||
double floor(double x)
|
||||
{
|
||||
return x;
|
||||
}
|
||||
#endif /* ! defined (__math_68881) */
|
||||
|
||||
/* Non reentrant ANSI C functions. */
|
||||
|
||||
#ifndef _REENT_ONLY
|
||||
#ifndef __math_68881
|
||||
double acos(double x)
|
||||
{
|
||||
return x;
|
||||
}
|
||||
double asin(double x)
|
||||
{
|
||||
return x;
|
||||
}
|
||||
double atan2(double x, double y)
|
||||
{
|
||||
return x;
|
||||
}
|
||||
double cosh(double x)
|
||||
{
|
||||
return x;
|
||||
}
|
||||
double sinh(double x)
|
||||
{
|
||||
return x;
|
||||
}
|
||||
double exp(double x)
|
||||
{
|
||||
return x;
|
||||
}
|
||||
double ldexp(double x, int y)
|
||||
{
|
||||
return x;
|
||||
}
|
||||
double log(double x)
|
||||
{
|
||||
return x;
|
||||
}
|
||||
double log10(double x)
|
||||
{
|
||||
return x;
|
||||
}
|
||||
double pow(double x, double y)
|
||||
{
|
||||
return x;
|
||||
}
|
||||
double sqrt(double x)
|
||||
{
|
||||
return x;
|
||||
}
|
||||
double fmod(double x, double y)
|
||||
{
|
||||
return x;
|
||||
}
|
||||
#endif /* ! defined (__math_68881) */
|
||||
#endif /* ! defined (_REENT_ONLY) */
|
||||
#endif
|
|
@ -1,62 +0,0 @@
|
|||
#ifndef _C_MATH_H_
|
||||
#define _C_MATH_H_
|
||||
#include <math.h>
|
||||
|
||||
double floor(double);
|
||||
double pow(double, double);
|
||||
|
||||
#if 0
|
||||
#ifndef HUGE_VAL
|
||||
#define HUGE_VAL (1.0e99)
|
||||
#endif
|
||||
|
||||
#ifndef HUGE_VALF
|
||||
#define HUGE_VALF (1.0e999999999F)
|
||||
#endif
|
||||
|
||||
#if !defined(HUGE_VALL) && defined(_HAVE_LONG_DOUBLE)
|
||||
#define HUGE_VALL (1.0e999999999L)
|
||||
#endif
|
||||
|
||||
#if !defined(INFINITY)
|
||||
#define INFINITY (HUGE_VALF)
|
||||
#endif
|
||||
|
||||
|
||||
/* Reentrant ANSI C functions. */
|
||||
|
||||
#ifndef __math_68881
|
||||
// double atan(double);
|
||||
// double cos(double);
|
||||
// double sin(double);
|
||||
// double tan(double);
|
||||
// double tanh(double);
|
||||
// double frexp(double, int *);
|
||||
// double modf(double, double *);
|
||||
// double ceil(double);
|
||||
// double fabs(double);
|
||||
// double floor(double);
|
||||
#endif /* ! defined (__math_68881) */
|
||||
|
||||
/* Non reentrant ANSI C functions. */
|
||||
|
||||
#ifndef _REENT_ONLY
|
||||
#ifndef __math_68881
|
||||
// double acos(double);
|
||||
// double asin(double);
|
||||
// double atan2(double, double);
|
||||
// double cosh(double);
|
||||
// double sinh(double);
|
||||
// double exp(double);
|
||||
// double ldexp(double, int);
|
||||
// double log(double);
|
||||
// double log10(double);
|
||||
// double pow(double, double);
|
||||
// double sqrt(double);
|
||||
// double fmod(double, double);
|
||||
#endif /* ! defined (__math_68881) */
|
||||
#endif /* ! defined (_REENT_ONLY) */
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* _MATH_H_ */
|
|
@ -1,6 +0,0 @@
|
|||
#ifndef _C_SIGNAL_H_
|
||||
#define _C_SIGNAL_H_
|
||||
|
||||
#include <signal.h>
|
||||
|
||||
#endif /* _C_SIGNAL_H_ */
|
|
@ -1,22 +0,0 @@
|
|||
#ifndef __c_stdarg_h
|
||||
#define __c_stdarg_h
|
||||
|
||||
#if defined(__GNUC__)
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
#else
|
||||
|
||||
typedef char * va_list;
|
||||
|
||||
#define _INTSIZEOF(n) ((sizeof(n) + sizeof(int) - 1) & ~(sizeof(int) - 1))
|
||||
|
||||
#define va_start(ap,v) (ap = (va_list)&v + _INTSIZEOF(v))
|
||||
#define va_arg(ap,t) (*(t *)((ap += _INTSIZEOF(t)) - _INTSIZEOF(t)))
|
||||
#define va_end(ap) (ap = (va_list)0)
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/* end of c_stdarg.h */
|
|
@ -1,23 +0,0 @@
|
|||
#ifndef __c_stddef_h
|
||||
#define __c_stddef_h
|
||||
|
||||
typedef signed int ptrdiff_t;
|
||||
|
||||
#if !defined(offsetof)
|
||||
#define offsetof(s, m) (size_t)&(((s *)0)->m)
|
||||
#endif
|
||||
|
||||
#if !defined(__size_t)
|
||||
#define __size_t 1
|
||||
typedef unsigned int size_t; /* others (e.g. <stdio.h>) also define */
|
||||
/* the unsigned integral type of the result of the sizeof operator. */
|
||||
#endif
|
||||
|
||||
#undef NULL /* others (e.g. <stdio.h>) also define */
|
||||
#define NULL 0
|
||||
/* null pointer constant. */
|
||||
|
||||
#endif
|
||||
|
||||
/* end of c_stddef.h */
|
||||
|
|
@ -1,273 +0,0 @@
|
|||
#ifndef __c_stdint_h
|
||||
#define __c_stdint_h
|
||||
|
||||
#include "c_types.h"
|
||||
#if 0
|
||||
/*
|
||||
* Depending on compiler version __int64 or __INT64_TYPE__ should be defined.
|
||||
*/
|
||||
#ifndef __int64
|
||||
#ifdef __INT64_TYPE__
|
||||
#define __int64 __INT64_TYPE__
|
||||
#else
|
||||
#define __int64 long long
|
||||
#endif
|
||||
/* On some architectures neither of these may be defined - if so, fall
|
||||
through and error out if used. */
|
||||
#endif
|
||||
|
||||
#ifndef __STDINT_DECLS
|
||||
#define __STDINT_DECLS
|
||||
|
||||
#undef __CLIBNS
|
||||
|
||||
#ifdef __cplusplus
|
||||
namespace std {
|
||||
#define __CLIBNS std::
|
||||
extern "C" {
|
||||
#else
|
||||
#define __CLIBNS
|
||||
#endif /* __cplusplus */
|
||||
|
||||
|
||||
/*
|
||||
* 'signed' is redundant below, except for 'signed char' and if
|
||||
* the typedef is used to declare a bitfield.
|
||||
* '__int64' is used instead of 'long long' so that this header
|
||||
* can be used in --strict mode.
|
||||
*/
|
||||
|
||||
/* 7.18.1.1 */
|
||||
|
||||
/* exact-width signed integer types */
|
||||
typedef signed char int8_t;
|
||||
typedef signed short int int16_t;
|
||||
typedef signed int int32_t;
|
||||
typedef signed __int64 int64_t;
|
||||
|
||||
/* exact-width unsigned integer types */
|
||||
typedef unsigned char uint8_t;
|
||||
typedef unsigned short int uint16_t;
|
||||
typedef unsigned int uint32_t;
|
||||
typedef unsigned __int64 uint64_t;
|
||||
|
||||
/* 7.18.1.2 */
|
||||
|
||||
/* smallest type of at least n bits */
|
||||
/* minimum-width signed integer types */
|
||||
typedef signed char int_least8_t;
|
||||
typedef signed short int int_least16_t;
|
||||
typedef signed int int_least32_t;
|
||||
typedef signed __int64 int_least64_t;
|
||||
|
||||
/* minimum-width unsigned integer types */
|
||||
typedef unsigned char uint_least8_t;
|
||||
typedef unsigned short int uint_least16_t;
|
||||
typedef unsigned int uint_least32_t;
|
||||
typedef unsigned __int64 uint_least64_t;
|
||||
|
||||
/* 7.18.1.3 */
|
||||
|
||||
/* fastest minimum-width signed integer types */
|
||||
typedef signed int int_fast8_t;
|
||||
typedef signed int int_fast16_t;
|
||||
typedef signed int int_fast32_t;
|
||||
typedef signed __int64 int_fast64_t;
|
||||
|
||||
/* fastest minimum-width unsigned integer types */
|
||||
typedef unsigned int uint_fast8_t;
|
||||
typedef unsigned int uint_fast16_t;
|
||||
typedef unsigned int uint_fast32_t;
|
||||
typedef unsigned __int64 uint_fast64_t;
|
||||
|
||||
/* 7.18.1.4 integer types capable of holding object pointers */
|
||||
typedef signed int intptr_t;
|
||||
typedef unsigned int uintptr_t;
|
||||
|
||||
/* 7.18.1.5 greatest-width integer types */
|
||||
typedef signed __int64 intmax_t;
|
||||
typedef unsigned __int64 uintmax_t;
|
||||
|
||||
|
||||
#if !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS)
|
||||
|
||||
/* 7.18.2.1 */
|
||||
|
||||
/* minimum values of exact-width signed integer types */
|
||||
#define INT8_MIN -128
|
||||
#define INT16_MIN -32768
|
||||
#define INT32_MIN (~0x7fffffff) /* -2147483648 is unsigned */
|
||||
#define INT64_MIN __ESCAPE__(~0x7fffffffffffffffll) /* -9223372036854775808 is unsigned */
|
||||
|
||||
/* maximum values of exact-width signed integer types */
|
||||
#define INT8_MAX 127
|
||||
#define INT16_MAX 32767
|
||||
#define INT32_MAX 2147483647
|
||||
#define INT64_MAX __ESCAPE__(9223372036854775807ll)
|
||||
|
||||
/* maximum values of exact-width unsigned integer types */
|
||||
#define UINT8_MAX 255
|
||||
#define UINT16_MAX 65535
|
||||
#define UINT32_MAX 4294967295u
|
||||
#define UINT64_MAX __ESCAPE__(18446744073709551615ull)
|
||||
|
||||
/* 7.18.2.2 */
|
||||
|
||||
/* minimum values of minimum-width signed integer types */
|
||||
#define INT_LEAST8_MIN -128
|
||||
#define INT_LEAST16_MIN -32768
|
||||
#define INT_LEAST32_MIN (~0x7fffffff)
|
||||
#define INT_LEAST64_MIN __ESCAPE__(~0x7fffffffffffffffll)
|
||||
|
||||
/* maximum values of minimum-width signed integer types */
|
||||
#define INT_LEAST8_MAX 127
|
||||
#define INT_LEAST16_MAX 32767
|
||||
#define INT_LEAST32_MAX 2147483647
|
||||
#define INT_LEAST64_MAX __ESCAPE__(9223372036854775807ll)
|
||||
|
||||
/* maximum values of minimum-width unsigned integer types */
|
||||
#define UINT_LEAST8_MAX 255
|
||||
#define UINT_LEAST16_MAX 65535
|
||||
#define UINT_LEAST32_MAX 4294967295u
|
||||
#define UINT_LEAST64_MAX __ESCAPE__(18446744073709551615ull)
|
||||
|
||||
/* 7.18.2.3 */
|
||||
|
||||
/* minimum values of fastest minimum-width signed integer types */
|
||||
#define INT_FAST8_MIN (~0x7fffffff)
|
||||
#define INT_FAST16_MIN (~0x7fffffff)
|
||||
#define INT_FAST32_MIN (~0x7fffffff)
|
||||
#define INT_FAST64_MIN __ESCAPE__(~0x7fffffffffffffffll)
|
||||
|
||||
/* maximum values of fastest minimum-width signed integer types */
|
||||
#define INT_FAST8_MAX 2147483647
|
||||
#define INT_FAST16_MAX 2147483647
|
||||
#define INT_FAST32_MAX 2147483647
|
||||
#define INT_FAST64_MAX __ESCAPE__(9223372036854775807ll)
|
||||
|
||||
/* maximum values of fastest minimum-width unsigned integer types */
|
||||
#define UINT_FAST8_MAX 4294967295u
|
||||
#define UINT_FAST16_MAX 4294967295u
|
||||
#define UINT_FAST32_MAX 4294967295u
|
||||
#define UINT_FAST64_MAX __ESCAPE__(18446744073709551615ull)
|
||||
|
||||
/* 7.18.2.4 */
|
||||
|
||||
/* minimum value of pointer-holding signed integer type */
|
||||
#define INTPTR_MIN (~0x7fffffff)
|
||||
|
||||
/* maximum value of pointer-holding signed integer type */
|
||||
#define INTPTR_MAX 2147483647
|
||||
|
||||
/* maximum value of pointer-holding unsigned integer type */
|
||||
#define UINTPTR_MAX 4294967295u
|
||||
|
||||
/* 7.18.2.5 */
|
||||
|
||||
/* minimum value of greatest-width signed integer type */
|
||||
#define INTMAX_MIN __ESCAPE__(~0x7fffffffffffffffll)
|
||||
|
||||
/* maximum value of greatest-width signed integer type */
|
||||
#define INTMAX_MAX __ESCAPE__(9223372036854775807ll)
|
||||
|
||||
/* maximum value of greatest-width unsigned integer type */
|
||||
#define UINTMAX_MAX __ESCAPE__(18446744073709551615ull)
|
||||
|
||||
/* 7.18.3 */
|
||||
|
||||
/* limits of ptrdiff_t */
|
||||
#define PTRDIFF_MIN (~0x7fffffff)
|
||||
#define PTRDIFF_MAX 2147483647
|
||||
|
||||
/* limits of sig_atomic_t */
|
||||
#define SIG_ATOMIC_MIN (~0x7fffffff)
|
||||
#define SIG_ATOMIC_MAX 2147483647
|
||||
|
||||
/* limit of size_t */
|
||||
#define SIZE_MAX 4294967295u
|
||||
|
||||
/* limits of wchar_t */
|
||||
/* NB we have to undef and redef because they're defined in both
|
||||
* stdint.h and wchar.h */
|
||||
#undef WCHAR_MIN
|
||||
#undef WCHAR_MAX
|
||||
|
||||
#if defined(__WCHAR32) || (defined(__ARM_SIZEOF_WCHAR_T) && __ARM_SIZEOF_WCHAR_T == 4)
|
||||
#define WCHAR_MIN 0
|
||||
#define WCHAR_MAX 0xffffffffU
|
||||
#else
|
||||
#define WCHAR_MIN 0
|
||||
#define WCHAR_MAX 65535
|
||||
#endif
|
||||
|
||||
/* limits of wint_t */
|
||||
#define WINT_MIN (~0x7fffffff)
|
||||
#define WINT_MAX 2147483647
|
||||
|
||||
#endif /* __STDC_LIMIT_MACROS */
|
||||
|
||||
#if !defined(__cplusplus) || defined(__STDC_CONSTANT_MACROS)
|
||||
|
||||
/* 7.18.4.1 macros for minimum-width integer constants */
|
||||
#define INT8_C(x) (x)
|
||||
#define INT16_C(x) (x)
|
||||
#define INT32_C(x) (x)
|
||||
#define INT64_C(x) __ESCAPE__(x ## ll)
|
||||
|
||||
#define UINT8_C(x) (x ## u)
|
||||
#define UINT16_C(x) (x ## u)
|
||||
#define UINT32_C(x) (x ## u)
|
||||
#define UINT64_C(x) __ESCAPE__(x ## ull)
|
||||
|
||||
/* 7.18.4.2 macros for greatest-width integer constants */
|
||||
#define INTMAX_C(x) __ESCAPE__(x ## ll)
|
||||
#define UINTMAX_C(x) __ESCAPE__(x ## ull)
|
||||
|
||||
#endif /* __STDC_CONSTANT_MACROS */
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
} /* namespace std */
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __STDINT_DECLS */
|
||||
|
||||
#ifdef __cplusplus
|
||||
#ifndef __STDINT_NO_EXPORTS
|
||||
using ::std::int8_t;
|
||||
using ::std::int16_t;
|
||||
using ::std::int32_t;
|
||||
using ::std::int64_t;
|
||||
using ::std::uint8_t;
|
||||
using ::std::uint16_t;
|
||||
using ::std::uint32_t;
|
||||
using ::std::uint64_t;
|
||||
using ::std::int_least8_t;
|
||||
using ::std::int_least16_t;
|
||||
using ::std::int_least32_t;
|
||||
using ::std::int_least64_t;
|
||||
using ::std::uint_least8_t;
|
||||
using ::std::uint_least16_t;
|
||||
using ::std::uint_least32_t;
|
||||
using ::std::uint_least64_t;
|
||||
using ::std::int_fast8_t;
|
||||
using ::std::int_fast16_t;
|
||||
using ::std::int_fast32_t;
|
||||
using ::std::int_fast64_t;
|
||||
using ::std::uint_fast8_t;
|
||||
using ::std::uint_fast16_t;
|
||||
using ::std::uint_fast32_t;
|
||||
using ::std::uint_fast64_t;
|
||||
using ::std::intptr_t;
|
||||
using ::std::uintptr_t;
|
||||
using ::std::intmax_t;
|
||||
using ::std::uintmax_t;
|
||||
#endif
|
||||
#endif /* __cplusplus */
|
||||
#endif
|
||||
|
||||
#endif /* __c_stdint_h */
|
||||
|
||||
/* end of c_stdint.h */
|
||||
|
||||
|
||||
|
1107
app/libc/c_stdio.c
1107
app/libc/c_stdio.c
File diff suppressed because it is too large
Load Diff
|
@ -1,103 +0,0 @@
|
|||
#ifndef _C_STDIO_H_
|
||||
#define _C_STDIO_H_
|
||||
|
||||
#define __need_size_t
|
||||
|
||||
#include "c_stddef.h"
|
||||
#include "osapi.h"
|
||||
// #include "driver/uart.h"
|
||||
|
||||
// #define __need___va_list
|
||||
//#include "c_stdarg.h"
|
||||
|
||||
//struct __sFILE{
|
||||
// int _r; /* read space left for getc() */
|
||||
// int _w; /* write space left for putc() */
|
||||
//};
|
||||
// typedef struct __sFILE __FILE;
|
||||
// typedef __FILE FILE;
|
||||
|
||||
extern int c_stdin;
|
||||
extern int c_stdout;
|
||||
extern int c_stderr;
|
||||
|
||||
// #define _IOFBF 0 /* setvbuf should set fully buffered */
|
||||
// #define _IOLBF 1 /* setvbuf should set line buffered */
|
||||
// #define _IONBF 2 /* setvbuf should set unbuffered */
|
||||
|
||||
// #ifndef NULL
|
||||
// #define NULL 0
|
||||
// #endif
|
||||
|
||||
#define EOF (-1)
|
||||
|
||||
#ifdef __BUFSIZ__
|
||||
#define BUFSIZ __BUFSIZ__
|
||||
#else
|
||||
#define BUFSIZ 1024
|
||||
#endif
|
||||
|
||||
#ifndef SEEK_SET
|
||||
#define SEEK_SET 0 /* set file offset to offset */
|
||||
#endif
|
||||
#ifndef SEEK_CUR
|
||||
#define SEEK_CUR 1 /* set file offset to current plus offset */
|
||||
#endif
|
||||
#ifndef SEEK_END
|
||||
#define SEEK_END 2 /* set file offset to EOF plus offset */
|
||||
#endif
|
||||
|
||||
// #define c_malloc os_malloc
|
||||
// #define c_zalloc os_zalloc
|
||||
// #define c_free os_free
|
||||
|
||||
extern void output_redirect(const char *str);
|
||||
#define c_puts output_redirect
|
||||
|
||||
// #define c_printf os_printf
|
||||
// int c_printf(const char *c, ...);
|
||||
#if defined( LUA_NUMBER_INTEGRAL )
|
||||
#define c_sprintf os_sprintf
|
||||
#else
|
||||
#include "c_stdarg.h"
|
||||
int c_sprintf(char* s,const char *fmt, ...);
|
||||
#endif
|
||||
|
||||
#define c_vsprintf ets_vsprintf
|
||||
#define c_printf(...) do { \
|
||||
unsigned char __print_buf[BUFSIZ]; \
|
||||
c_sprintf(__print_buf, __VA_ARGS__); \
|
||||
c_puts(__print_buf); \
|
||||
} while(0)
|
||||
|
||||
// #define c_getc ets_getc
|
||||
// #define c_getchar ets_getc
|
||||
// note: contact esp to ensure the real getchar function..
|
||||
|
||||
// FILE *c_fopen(const char *_name, const char *_type);
|
||||
// FILE *c_freopen(const char *, const char *, FILE *);
|
||||
// FILE *c_tmpfile(void);
|
||||
|
||||
// int c_putchar(int);
|
||||
// int c_printf(const char *, ...);
|
||||
// int c_sprintf(char *, const char *, ...);
|
||||
// int c_getc(FILE *);
|
||||
|
||||
// int c_ungetc(int, FILE *);
|
||||
|
||||
// int c_fprintf(FILE *, const char *, ...);
|
||||
// int c_fscanf(FILE *, const char *, ...);
|
||||
// int c_fclose(FILE *);
|
||||
// int c_fflush(FILE *);
|
||||
// int c_setvbuf(FILE *, char *, int, size_t);
|
||||
// void c_clearerr(FILE *);
|
||||
// int c_fseek(FILE *, long, int);
|
||||
// long c_ftell( FILE *);
|
||||
// int c_fputs(const char *, FILE *);
|
||||
// char *c_fgets(char *, int, FILE *);
|
||||
// size_t c_fread(void *, size_t _size, size_t _n, FILE *);
|
||||
// size_t c_fwrite(const void * , size_t _size, size_t _n, FILE *);
|
||||
// int c_feof(FILE *);
|
||||
// int c_ferror(FILE *);
|
||||
|
||||
#endif /* _C_STDIO_H_ */
|
|
@ -1,65 +0,0 @@
|
|||
/*
|
||||
* c_stdlib.h
|
||||
*
|
||||
* Definitions for common types, variables, and functions.
|
||||
*/
|
||||
|
||||
#ifndef _C_STDLIB_H_
|
||||
#define _C_STDLIB_H_
|
||||
|
||||
#include "c_stddef.h"
|
||||
#include "mem.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#define EXIT_FAILURE 1
|
||||
#define EXIT_SUCCESS 0
|
||||
|
||||
#define __INT_MAX__ 2147483647
|
||||
#undef __RAND_MAX
|
||||
#if __INT_MAX__ == 32767
|
||||
#define __RAND_MAX 32767
|
||||
#else
|
||||
#define __RAND_MAX 0x7fffffff
|
||||
#endif
|
||||
#define RAND_MAX __RAND_MAX
|
||||
|
||||
#ifndef mem_realloc
|
||||
#define mem_realloc pvPortRealloc
|
||||
#endif
|
||||
#ifndef os_realloc
|
||||
#define os_realloc(p, s) mem_realloc((p), (s))
|
||||
#endif
|
||||
|
||||
#define c_free os_free
|
||||
#define c_malloc os_malloc
|
||||
#define c_zalloc os_zalloc
|
||||
#define c_realloc os_realloc
|
||||
|
||||
#define c_abs abs
|
||||
#define c_atoi atoi
|
||||
//#define c_strtod strtod
|
||||
#define c_strtol strtol
|
||||
#define c_strtoul strtoul
|
||||
|
||||
// int c_abs(int);
|
||||
|
||||
// void c_exit(int);
|
||||
|
||||
// c_getenv() get env "LUA_INIT" string for lua initialization.
|
||||
const char *c_getenv(const char *__string);
|
||||
|
||||
// void *c_malloc(size_t __size);
|
||||
// void *c_zalloc(size_t __size);
|
||||
// void c_free(void *);
|
||||
|
||||
// int c_rand(void);
|
||||
// void c_srand(unsigned int __seed);
|
||||
|
||||
// int c_atoi(const char *__nptr);
|
||||
double c_strtod(const char *__n, char **__end_PTR);
|
||||
// // long c_strtol(const char *__n, char **__end_PTR, int __base);
|
||||
// unsigned long c_strtoul(const char *__n, char **__end_PTR, int __base);
|
||||
// // long long c_strtoll(const char *__n, char **__end_PTR, int __base);
|
||||
|
||||
#endif /* _C_STDLIB_H_ */
|
|
@ -1,129 +0,0 @@
|
|||
#include "c_string.h"
|
||||
#include "c_stdlib.h"
|
||||
|
||||
// const char *c_strstr(const char * __s1, const char * __s2){
|
||||
// }
|
||||
|
||||
// char *c_strncat(char * s1, const char * s2, size_t n){
|
||||
// }
|
||||
|
||||
// size_t c_strcspn(const char * s1, const char * s2){
|
||||
// }
|
||||
|
||||
// const char *c_strpbrk(const char * s1, const char * s2){
|
||||
// }
|
||||
|
||||
// int c_strcoll(const char * s1, const char * s2){
|
||||
// }
|
||||
//
|
||||
char *c_strdup(const char *c) {
|
||||
int len = os_strlen(c) + 1;
|
||||
char *ret = os_malloc(len);
|
||||
if (ret) {
|
||||
memcpy(ret, c, len);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* $OpenBSD: strlcpy.c,v 1.8 2003/06/17 21:56:24 millert Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copy src to string dst of size siz. At most siz-1 characters
|
||||
* will be copied. Always NUL terminates (unless siz == 0).
|
||||
* Returns strlen(src); if retval >= siz, truncation occurred.
|
||||
*/
|
||||
size_t
|
||||
c_strlcpy(char *dst, const char *src, size_t siz)
|
||||
{
|
||||
register char *d = dst;
|
||||
register const char *s = src;
|
||||
register size_t n = siz;
|
||||
|
||||
/* Copy as many bytes as will fit */
|
||||
if (n != 0 && --n != 0) {
|
||||
do {
|
||||
if ((*d++ = *s++) == 0)
|
||||
break;
|
||||
} while (--n != 0);
|
||||
}
|
||||
|
||||
/* Not enough room in dst, add NUL and traverse rest of src */
|
||||
if (n == 0) {
|
||||
if (siz != 0)
|
||||
*d = '\0'; /* NUL-terminate dst */
|
||||
while (*s++)
|
||||
;
|
||||
}
|
||||
|
||||
return(s - src - 1); /* count does not include NUL */
|
||||
}
|
||||
|
||||
/* $OpenBSD: strlcat.c,v 1.11 2003/06/17 21:56:24 millert Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Appends src to string dst of size siz (unlike strncat, siz is the
|
||||
* full size of dst, not space left). At most siz-1 characters
|
||||
* will be copied. Always NUL terminates (unless siz <= strlen(dst)).
|
||||
* Returns strlen(src) + MIN(siz, strlen(initial dst)).
|
||||
* If retval >= siz, truncation occurred.
|
||||
*/
|
||||
size_t
|
||||
c_strlcat(char *dst, const char *src, size_t siz)
|
||||
{
|
||||
register char *d = dst;
|
||||
register const char *s = src;
|
||||
register size_t n = siz;
|
||||
size_t dlen;
|
||||
|
||||
/* Find the end of dst and adjust bytes left but don't go past end */
|
||||
while (n-- != 0 && *d != '\0')
|
||||
d++;
|
||||
dlen = d - dst;
|
||||
n = siz - dlen;
|
||||
|
||||
if (n == 0)
|
||||
return(dlen + strlen(s));
|
||||
while (*s != '\0') {
|
||||
if (n != 1) {
|
||||
*d++ = *s;
|
||||
n--;
|
||||
}
|
||||
s++;
|
||||
}
|
||||
*d = '\0';
|
||||
|
||||
return(dlen + (s - src)); /* count does not include NUL */
|
||||
}
|
||||
|
|
@ -1,49 +0,0 @@
|
|||
/*
|
||||
* c_string.h
|
||||
*
|
||||
* Definitions for memory and string functions.
|
||||
*/
|
||||
|
||||
#ifndef _C_STRING_H_
|
||||
#define _C_STRING_H_
|
||||
#include "c_stddef.h"
|
||||
#include "osapi.h"
|
||||
|
||||
#ifndef NULL
|
||||
#define NULL 0
|
||||
#endif
|
||||
|
||||
#define c_memcmp os_memcmp
|
||||
#define c_memcpy os_memcpy
|
||||
#define c_memset os_memset
|
||||
|
||||
#define c_strcat os_strcat
|
||||
#define c_strchr os_strchr
|
||||
#define c_strcmp os_strcmp
|
||||
#define c_strcpy os_strcpy
|
||||
#define c_strlen os_strlen
|
||||
#define c_strncmp os_strncmp
|
||||
#define c_strncpy os_strncpy
|
||||
// #define c_strstr os_strstr
|
||||
#define c_strncasecmp c_strncmp
|
||||
|
||||
#define c_strstr strstr
|
||||
#define c_strncat strncat
|
||||
#define c_strcspn strcspn
|
||||
#define c_strpbrk strpbrk
|
||||
#define c_strcoll strcoll
|
||||
#define c_strrchr strrchr
|
||||
|
||||
// const char *c_strstr(const char * __s1, const char * __s2);
|
||||
// char *c_strncat(char * __restrict /*s1*/, const char * __restrict /*s2*/, size_t n);
|
||||
// size_t c_strcspn(const char * s1, const char * s2);
|
||||
// const char *c_strpbrk(const char * /*s1*/, const char * /*s2*/);
|
||||
// int c_strcoll(const char * /*s1*/, const char * /*s2*/);
|
||||
//
|
||||
|
||||
extern size_t c_strlcpy(char *dst, const char *src, size_t siz);
|
||||
extern size_t c_strlcat(char *dst, const char *src, size_t siz);
|
||||
extern char *c_strdup(const char *src);
|
||||
|
||||
|
||||
#endif /* _C_STRING_H_ */
|
|
@ -471,7 +471,7 @@ LUA_API void lua_pushstring (lua_State *L, const char *s) {
|
|||
if (s == NULL)
|
||||
lua_pushnil(L);
|
||||
else
|
||||
lua_pushlstring(L, s, c_strlen(s));
|
||||
lua_pushlstring(L, s, strlen(s));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -56,7 +56,7 @@ LUALIB_API int luaL_argerror (lua_State *L, int narg, const char *extramsg) {
|
|||
if (!lua_getstack(L, 0, &ar)) /* no stack frame? */
|
||||
return luaL_error(L, "bad argument #%d (%s)", narg, extramsg);
|
||||
lua_getinfo(L, "n", &ar);
|
||||
if (c_strcmp(ar.namewhat, "method") == 0) {
|
||||
if (strcmp(ar.namewhat, "method") == 0) {
|
||||
narg--; /* do not count `self' */
|
||||
if (narg == 0) /* error is in the self argument itself? */
|
||||
return luaL_error(L, "calling " LUA_QS " on bad self (%s)",
|
||||
|
@ -113,7 +113,7 @@ LUALIB_API int luaL_checkoption (lua_State *L, int narg, const char *def,
|
|||
luaL_checkstring(L, narg);
|
||||
int i;
|
||||
for (i=0; lst[i]; i++)
|
||||
if (c_strcmp(lst[i], name) == 0)
|
||||
if (strcmp(lst[i], name) == 0)
|
||||
return i;
|
||||
return luaL_argerror(L, narg,
|
||||
lua_pushfstring(L, "invalid option " LUA_QS, name));
|
||||
|
@ -203,7 +203,7 @@ LUALIB_API const char *luaL_optlstring (lua_State *L, int narg,
|
|||
const char *def, size_t *len) {
|
||||
if (lua_isnoneornil(L, narg)) {
|
||||
if (len)
|
||||
*len = (def ? c_strlen(def) : 0);
|
||||
*len = (def ? strlen(def) : 0);
|
||||
return def;
|
||||
}
|
||||
else return luaL_checklstring(L, narg, len);
|
||||
|
@ -388,10 +388,10 @@ LUALIB_API int luaL_getn (lua_State *L, int t) {
|
|||
LUALIB_API const char *luaL_gsub (lua_State *L, const char *s, const char *p,
|
||||
const char *r) {
|
||||
const char *wild;
|
||||
size_t l = c_strlen(p);
|
||||
size_t l = strlen(p);
|
||||
luaL_Buffer b;
|
||||
luaL_buffinit(L, &b);
|
||||
while ((wild = c_strstr(s, p)) != NULL) {
|
||||
while ((wild = strstr(s, p)) != NULL) {
|
||||
luaL_addlstring(&b, s, wild - s); /* push prefix */
|
||||
luaL_addstring(&b, r); /* push replacement in place of pattern */
|
||||
s = wild + l; /* continue after `p' */
|
||||
|
@ -407,8 +407,8 @@ LUALIB_API const char *luaL_findtable (lua_State *L, int idx,
|
|||
const char *e;
|
||||
lua_pushvalue(L, idx);
|
||||
do {
|
||||
e = c_strchr(fname, '.');
|
||||
if (e == NULL) e = fname + c_strlen(fname);
|
||||
e = strchr(fname, '.');
|
||||
if (e == NULL) e = fname + strlen(fname);
|
||||
lua_pushlstring(L, fname, e - fname);
|
||||
lua_rawget(L, -2);
|
||||
if (lua_isnil(L, -1)) {
|
||||
|
@ -496,7 +496,7 @@ LUALIB_API void luaL_addlstring (luaL_Buffer *B, const char *s, size_t l) {
|
|||
|
||||
|
||||
LUALIB_API void luaL_addstring (luaL_Buffer *B, const char *s) {
|
||||
luaL_addlstring(B, s, c_strlen(s));
|
||||
luaL_addlstring(B, s, strlen(s));
|
||||
}
|
||||
|
||||
|
||||
|
@ -512,7 +512,7 @@ LUALIB_API void luaL_addvalue (luaL_Buffer *B) {
|
|||
size_t vl;
|
||||
const char *s = lua_tolstring(L, -1, &vl);
|
||||
if (vl <= bufffree(B)) { /* fit into buffer? */
|
||||
c_memcpy(B->p, s, vl); /* put it there */
|
||||
memcpy(B->p, s, vl); /* put it there */
|
||||
B->p += vl;
|
||||
lua_pop(L, 1); /* remove from stack */
|
||||
}
|
||||
|
@ -754,7 +754,7 @@ LUALIB_API int luaL_loadbuffer (lua_State *L, const char *buff, size_t size,
|
|||
|
||||
|
||||
LUALIB_API int (luaL_loadstring) (lua_State *L, const char *s) {
|
||||
return luaL_loadbuffer(L, s, c_strlen(s), s);
|
||||
return luaL_loadbuffer(L, s, strlen(s), s);
|
||||
}
|
||||
|
||||
|
||||
|
@ -786,7 +786,7 @@ static void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize) {
|
|||
void *nptr;
|
||||
|
||||
if (nsize == 0) {
|
||||
c_free(ptr);
|
||||
free(ptr);
|
||||
return NULL;
|
||||
}
|
||||
if (L != NULL && (mode & EGC_ALWAYS)) /* always collect memory if requested */
|
||||
|
@ -798,16 +798,16 @@ static void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize) {
|
|||
if(G(L)->memlimit > 0 && (mode & EGC_ON_MEM_LIMIT) && l_check_memlimit(L, nsize - osize))
|
||||
return NULL;
|
||||
}
|
||||
nptr = (void *)c_realloc(ptr, nsize);
|
||||
nptr = (void *)realloc(ptr, nsize);
|
||||
if (nptr == NULL && L != NULL && (mode & EGC_ON_ALLOC_FAILURE)) {
|
||||
luaC_fullgc(L); /* emergency full collection. */
|
||||
nptr = (void *)c_realloc(ptr, nsize); /* try allocation again */
|
||||
nptr = (void *)realloc(ptr, nsize); /* try allocation again */
|
||||
}
|
||||
return nptr;
|
||||
}
|
||||
|
||||
LUALIB_API void luaL_assertfail(const char *file, int line, const char *message) {
|
||||
c_printf("ASSERT@%s(%d): %s\n", file, line, message);
|
||||
printf("ASSERT@%s(%d): %s\n", file, line, message);
|
||||
}
|
||||
|
||||
static int panic (lua_State *L) {
|
||||
|
|
|
@ -11,11 +11,7 @@
|
|||
|
||||
#include "lua.h"
|
||||
|
||||
#ifdef LUA_CROSS_COMPILER
|
||||
#include <stdio.h>
|
||||
#else
|
||||
#include "c_stdio.h"
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(LUA_COMPAT_GETN)
|
||||
|
|
|
@ -45,7 +45,7 @@ static int luaB_print (lua_State *L) {
|
|||
c_fputs(s, c_stdout);
|
||||
#else
|
||||
if (i>1) luai_writestring("\t", 1);
|
||||
luai_writestring(s, c_strlen(s));
|
||||
luai_writestring(s, strlen(s));
|
||||
#endif
|
||||
lua_pop(L, 1); /* pop result */
|
||||
}
|
||||
|
@ -72,7 +72,7 @@ static int luaB_tonumber (lua_State *L) {
|
|||
char *s2;
|
||||
unsigned long n;
|
||||
luaL_argcheck(L, 2 <= base && base <= 36, 2, "base out of range");
|
||||
n = c_strtoul(s1, &s2, base);
|
||||
n = strtoul(s1, &s2, base);
|
||||
if (s1 != s2) { /* at least one valid digit? */
|
||||
while (isspace((unsigned char)(*s2))) s2++; /* skip trailing spaces */
|
||||
if (*s2 == '\0') { /* no invalid trailing characters? */
|
||||
|
@ -506,11 +506,11 @@ static int luaB_index(lua_State *L) {
|
|||
return fres;
|
||||
#endif
|
||||
const char *keyname = luaL_checkstring(L, 2);
|
||||
if (!c_strcmp(keyname, "_VERSION")) {
|
||||
if (!strcmp(keyname, "_VERSION")) {
|
||||
lua_pushliteral(L, LUA_VERSION);
|
||||
return 1;
|
||||
}
|
||||
void *res = luaR_findglobal(keyname, c_strlen(keyname));
|
||||
void *res = luaR_findglobal(keyname, strlen(keyname));
|
||||
if (!res)
|
||||
return 0;
|
||||
else {
|
||||
|
|
|
@ -81,7 +81,7 @@ static void fixjump (FuncState *fs, int pc, int dest) {
|
|||
Instruction *jmp = &fs->f->code[pc];
|
||||
int offset = dest-(pc+1);
|
||||
lua_assert(dest != NO_JUMP);
|
||||
if (c_abs(offset) > MAXARG_sBx)
|
||||
if (abs(offset) > MAXARG_sBx)
|
||||
luaX_syntaxerror(fs->ls, "control structure too long");
|
||||
SETARG_sBx(*jmp, offset);
|
||||
}
|
||||
|
|
|
@ -121,24 +121,24 @@ static int db_getinfo (lua_State *L) {
|
|||
if (!lua_getinfo(L1, options, &ar))
|
||||
return luaL_argerror(L, arg+2, "invalid option");
|
||||
lua_createtable(L, 0, 2);
|
||||
if (c_strchr(options, 'S')) {
|
||||
if (strchr(options, 'S')) {
|
||||
settabss(L, "source", ar.source);
|
||||
settabss(L, "short_src", ar.short_src);
|
||||
settabsi(L, "linedefined", ar.linedefined);
|
||||
settabsi(L, "lastlinedefined", ar.lastlinedefined);
|
||||
settabss(L, "what", ar.what);
|
||||
}
|
||||
if (c_strchr(options, 'l'))
|
||||
if (strchr(options, 'l'))
|
||||
settabsi(L, "currentline", ar.currentline);
|
||||
if (c_strchr(options, 'u'))
|
||||
if (strchr(options, 'u'))
|
||||
settabsi(L, "nups", ar.nups);
|
||||
if (c_strchr(options, 'n')) {
|
||||
if (strchr(options, 'n')) {
|
||||
settabss(L, "name", ar.name);
|
||||
settabss(L, "namewhat", ar.namewhat);
|
||||
}
|
||||
if (c_strchr(options, 'L'))
|
||||
if (strchr(options, 'L'))
|
||||
treatstackoption(L, L1, "activelines");
|
||||
if (c_strchr(options, 'f'))
|
||||
if (strchr(options, 'f'))
|
||||
treatstackoption(L, L1, "func");
|
||||
return 1; /* return table */
|
||||
}
|
||||
|
@ -227,9 +227,9 @@ static void hookf (lua_State *L, lua_Debug *ar) {
|
|||
|
||||
static int makemask (const char *smask, int count) {
|
||||
int mask = 0;
|
||||
if (c_strchr(smask, 'c')) mask |= LUA_MASKCALL;
|
||||
if (c_strchr(smask, 'r')) mask |= LUA_MASKRET;
|
||||
if (c_strchr(smask, 'l')) mask |= LUA_MASKLINE;
|
||||
if (strchr(smask, 'c')) mask |= LUA_MASKCALL;
|
||||
if (strchr(smask, 'r')) mask |= LUA_MASKRET;
|
||||
if (strchr(smask, 'l')) mask |= LUA_MASKLINE;
|
||||
if (count > 0) mask |= LUA_MASKCOUNT;
|
||||
return mask;
|
||||
}
|
||||
|
@ -312,9 +312,9 @@ static int db_debug (lua_State *L) {
|
|||
// luai_writestringerror("%s", "lua_debug>");
|
||||
if (lua_readline(L, buffer, "lua_debug>") == 0 ||
|
||||
#endif
|
||||
c_strcmp(buffer, "cont\n") == 0)
|
||||
strcmp(buffer, "cont\n") == 0)
|
||||
return 0;
|
||||
if (luaL_loadbuffer(L, buffer, c_strlen(buffer), "=(debug command)") ||
|
||||
if (luaL_loadbuffer(L, buffer, strlen(buffer), "=(debug command)") ||
|
||||
lua_pcall(L, 0, 0, 0)) {
|
||||
#if defined(LUA_USE_STDIO)
|
||||
c_fputs(lua_tostring(L, -1), c_stderr);
|
||||
|
|
|
@ -253,7 +253,7 @@ static int stripdebug (lua_State *L, Proto *f, int level) {
|
|||
TString* dummy;
|
||||
switch (level) {
|
||||
case 3:
|
||||
sizepackedlineinfo = c_strlen(cast(char *, f->packedlineinfo))+1;
|
||||
sizepackedlineinfo = strlen(cast(char *, f->packedlineinfo))+1;
|
||||
f->packedlineinfo = luaM_freearray(L, f->packedlineinfo, sizepackedlineinfo, unsigned char);
|
||||
len += sizepackedlineinfo;
|
||||
case 2:
|
||||
|
@ -344,7 +344,7 @@ LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) {
|
|||
plight = fvalue(ci->func);
|
||||
}
|
||||
status = auxgetinfo(L, what, ar, f, plight, ci);
|
||||
if (c_strchr(what, 'f')) {
|
||||
if (strchr(what, 'f')) {
|
||||
if (f != NULL)
|
||||
setclvalue(L, L->top, f)
|
||||
else if (plight != NULL)
|
||||
|
@ -353,7 +353,7 @@ LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) {
|
|||
setnilvalue(L->top);
|
||||
incr_top(L);
|
||||
}
|
||||
if (c_strchr(what, 'L'))
|
||||
if (strchr(what, 'L'))
|
||||
collectvalidlines(L, f);
|
||||
lua_unlock(L);
|
||||
return status;
|
||||
|
|
|
@ -150,9 +150,9 @@ static void DumpNumber(lua_Number x, DumpState* D)
|
|||
if(D->target.is_arm_fpa)
|
||||
{
|
||||
char *pnum=(char*)&y, temp[4];
|
||||
c_memcpy(temp,pnum,4);
|
||||
c_memcpy(pnum,pnum+4,4);
|
||||
c_memcpy(pnum+4,temp,4);
|
||||
memcpy(temp,pnum,4);
|
||||
memcpy(pnum,pnum+4,4);
|
||||
memcpy(pnum+4,temp,4);
|
||||
}
|
||||
MaybeByteSwap((char*)&y,8,D);
|
||||
DumpVar(y,D);
|
||||
|
@ -171,7 +171,7 @@ static void DumpCode(const Proto *f, DumpState* D)
|
|||
Align4(D);
|
||||
for (i=0; i<f->sizecode; i++)
|
||||
{
|
||||
c_memcpy(buf,&f->code[i],sizeof(Instruction));
|
||||
memcpy(buf,&f->code[i],sizeof(Instruction));
|
||||
MaybeByteSwap(buf,sizeof(Instruction),D);
|
||||
DumpBlock(buf,sizeof(Instruction),D);
|
||||
}
|
||||
|
@ -230,7 +230,7 @@ static void DumpDebug(const Proto* f, DumpState* D)
|
|||
int i,n;
|
||||
|
||||
#ifdef LUA_OPTIMIZE_DEBUG
|
||||
n = (D->strip || f->packedlineinfo == NULL) ? 0: c_strlen(cast(char *,f->packedlineinfo))+1;
|
||||
n = (D->strip || f->packedlineinfo == NULL) ? 0: strlen(cast(char *,f->packedlineinfo))+1;
|
||||
DumpInt(n,D);
|
||||
Align4(D);
|
||||
if (n)
|
||||
|
@ -281,7 +281,7 @@ static void DumpHeader(DumpState* D)
|
|||
char *h=buf;
|
||||
|
||||
/* This code must be kept in sync wiht luaU_header */
|
||||
c_memcpy(h,LUA_SIGNATURE,sizeof(LUA_SIGNATURE)-1);
|
||||
memcpy(h,LUA_SIGNATURE,sizeof(LUA_SIGNATURE)-1);
|
||||
h+=sizeof(LUA_SIGNATURE)-1;
|
||||
*h++=(char)LUAC_VERSION;
|
||||
*h++=(char)LUAC_FORMAT;
|
||||
|
|
|
@ -150,7 +150,7 @@ void luaF_freeproto (lua_State *L, Proto *f) {
|
|||
luaM_freearray(L, f->code, f->sizecode, Instruction);
|
||||
#ifdef LUA_OPTIMIZE_DEBUG
|
||||
if (f->packedlineinfo) {
|
||||
luaM_freearray(L, f->packedlineinfo, c_strlen(cast(char *, f->packedlineinfo))+1, unsigned char);
|
||||
luaM_freearray(L, f->packedlineinfo, strlen(cast(char *, f->packedlineinfo))+1, unsigned char);
|
||||
}
|
||||
#else
|
||||
luaM_freearray(L, f->lineinfo, f->sizelineinfo, int);
|
||||
|
|
|
@ -164,8 +164,8 @@ static int traversetable (global_State *g, Table *h) {
|
|||
markobject(g, h->metatable);
|
||||
mode = gfasttm(g, h->metatable, TM_MODE);
|
||||
if (mode && ttisstring(mode)) { /* is there a weak mode? */
|
||||
weakkey = (c_strchr(svalue(mode), 'k') != NULL);
|
||||
weakvalue = (c_strchr(svalue(mode), 'v') != NULL);
|
||||
weakkey = (strchr(svalue(mode), 'k') != NULL);
|
||||
weakvalue = (strchr(svalue(mode), 'v') != NULL);
|
||||
if (weakkey || weakvalue) { /* is really weak? */
|
||||
h->marked &= ~(KEYWEAK | VALUEWEAK); /* clear bits */
|
||||
h->marked |= cast_byte((weakkey << KEYWEAKBIT) |
|
||||
|
@ -320,7 +320,7 @@ static l_mem propagatemark (global_State *g) {
|
|||
(proto_is_readonly(p) ? 0 : sizeof(Instruction) * p->sizecode +
|
||||
#ifdef LUA_OPTIMIZE_DEBUG
|
||||
(p->packedlineinfo ?
|
||||
c_strlen(cast(char *, p->packedlineinfo))+1 :
|
||||
strlen(cast(char *, p->packedlineinfo))+1 :
|
||||
0));
|
||||
#else
|
||||
sizeof(int) * p->sizelineinfo);
|
||||
|
|
|
@ -5,10 +5,10 @@
|
|||
*/
|
||||
|
||||
|
||||
// #include "c_errno.h"
|
||||
#include "c_stdio.h"
|
||||
#include "c_stdlib.h"
|
||||
#include "c_string.h"
|
||||
// #include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "flash_fs.h"
|
||||
|
||||
#define liolib_c
|
||||
|
@ -143,7 +143,7 @@ static int aux_close (lua_State *L) {
|
|||
return (lua_tocfunction(L, -1))(L);
|
||||
#else
|
||||
int *p = tofilep(L);
|
||||
if(*p == c_stdin || *p == c_stdout || *p == c_stderr)
|
||||
if(*p == fileno(stdin) || *p == fileno(stdout) || *p == fileno(stderr))
|
||||
{
|
||||
lua_pushnil(L);
|
||||
lua_pushliteral(L, "cannot close standard file");
|
||||
|
@ -329,7 +329,7 @@ static int read_line (lua_State *L, int f) {
|
|||
luaL_pushresult(&b); /* close buffer */
|
||||
return (lua_objlen(L, -1) > 0); /* check whether read something */
|
||||
}
|
||||
l = c_strlen(p);
|
||||
l = strlen(p);
|
||||
if (l == 0 || p[l-1] != '\n')
|
||||
luaL_addsize(&b, l);
|
||||
else {
|
||||
|
@ -644,9 +644,9 @@ LUALIB_API int luaopen_io (lua_State *L) {
|
|||
#endif
|
||||
#if 0
|
||||
/* create (and set) default files */
|
||||
createstdfile(L, c_stdin, IO_INPUT, "stdin");
|
||||
createstdfile(L, c_stdout, IO_OUTPUT, "stdout");
|
||||
createstdfile(L, c_stderr, IO_STDERR, "stderr");
|
||||
createstdfile(L, stdin, IO_INPUT, "stdin");
|
||||
createstdfile(L, stdout, IO_OUTPUT, "stdout");
|
||||
createstdfile(L, stderr, IO_STDERR, "stderr");
|
||||
|
||||
#if LUA_OPTIMIZE_MEMORY != 2
|
||||
lua_pop(L, 1); /* pop environment for default files */
|
||||
|
|
|
@ -154,7 +154,7 @@ void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, TString *source) {
|
|||
|
||||
|
||||
static int check_next (LexState *ls, const char *set) {
|
||||
if (!c_strchr(set, ls->current))
|
||||
if (!strchr(set, ls->current))
|
||||
return 0;
|
||||
save_and_next(ls);
|
||||
return 1;
|
||||
|
@ -422,7 +422,7 @@ static int llex (LexState *ls, SemInfo *seminfo) {
|
|||
/* look for reserved word */
|
||||
save(ls, '\0');
|
||||
for (i = 0; i < NUM_RESERVED; i++)
|
||||
if (!c_strcmp(luaX_tokens[i], luaZ_buffer(ls->buff)))
|
||||
if (!strcmp(luaX_tokens[i], luaZ_buffer(ls->buff)))
|
||||
return i + FIRST_RESERVED;
|
||||
ts = luaX_newstring(ls, luaZ_buffer(ls->buff),
|
||||
luaZ_bufflen(ls->buff) - 1);
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
#define llimits_h
|
||||
|
||||
|
||||
//#include "c_limits.h"
|
||||
//#include <limits.h>
|
||||
|
||||
#include "lua.h"
|
||||
|
||||
|
|
|
@ -374,7 +374,7 @@ const LUA_REG_TYPE math_map[] = {
|
|||
*/
|
||||
|
||||
#if defined LUA_NUMBER_INTEGRAL
|
||||
# include "c_limits.h" /* for LONG_MAX */
|
||||
# include <limits.h> /* for LONG_MAX */
|
||||
#endif
|
||||
|
||||
LUALIB_API int luaopen_math (lua_State *L) {
|
||||
|
|
|
@ -14,9 +14,9 @@
|
|||
#define LUAC_CROSS_FILE
|
||||
|
||||
#include "lua.h"
|
||||
#include C_HEADER_STDLIB
|
||||
#include C_HEADER_STRING
|
||||
#include C_HEADER_FCNTL
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#ifndef LUA_CROSS_COMPILER
|
||||
#include "flash_fs.h"
|
||||
|
@ -103,7 +103,7 @@ static void setprogdir (lua_State *L) {
|
|||
char *lb;
|
||||
DWORD nsize = sizeof(buff)/sizeof(char);
|
||||
DWORD n = GetModuleFileNameA(NULL, buff, nsize);
|
||||
if (n == 0 || n == nsize || (lb = c_strrchr(buff, '\\')) == NULL)
|
||||
if (n == 0 || n == nsize || (lb = strrchr(buff, '\\')) == NULL)
|
||||
luaL_error(L, "unable to get ModuleFileName");
|
||||
else {
|
||||
*lb = '\0';
|
||||
|
@ -351,8 +351,8 @@ static const char * pushnexttemplate (lua_State *L, const char *path) {
|
|||
const char *l;
|
||||
while (*path == *LUA_PATHSEP) path++; /* skip separators */
|
||||
if (*path == '\0') return NULL; /* no more templates */
|
||||
l = c_strchr(path, *LUA_PATHSEP); /* find next separator */
|
||||
if (l == NULL) l = path + c_strlen(path);
|
||||
l = strchr(path, *LUA_PATHSEP); /* find next separator */
|
||||
if (l == NULL) l = path + strlen(path);
|
||||
lua_pushlstring(L, path, l - path); /* template */
|
||||
return l;
|
||||
}
|
||||
|
@ -404,7 +404,7 @@ static int loader_Lua (lua_State *L) {
|
|||
|
||||
static const char *mkfuncname (lua_State *L, const char *modname) {
|
||||
const char *funcname;
|
||||
const char *mark = c_strchr(modname, *LUA_IGMARK);
|
||||
const char *mark = strchr(modname, *LUA_IGMARK);
|
||||
if (mark) modname = mark + 1;
|
||||
funcname = luaL_gsub(L, modname, ".", LUA_OFSEP);
|
||||
funcname = lua_pushfstring(L, POF"%s", funcname);
|
||||
|
@ -429,7 +429,7 @@ static int loader_Croot (lua_State *L) {
|
|||
const char *funcname;
|
||||
const char *filename;
|
||||
const char *name = luaL_checkstring(L, 1);
|
||||
const char *p = c_strchr(name, '.');
|
||||
const char *p = strchr(name, '.');
|
||||
int stat;
|
||||
if (p == NULL) return 0; /* is root */
|
||||
lua_pushlstring(L, name, p - name);
|
||||
|
@ -474,7 +474,7 @@ static int ll_require (lua_State *L) {
|
|||
return 1; /* package is already loaded */
|
||||
}
|
||||
/* Is this a readonly table? */
|
||||
void *res = luaR_findglobal(name, c_strlen(name));
|
||||
void *res = luaR_findglobal(name, strlen(name));
|
||||
if (res) {
|
||||
lua_pushrotable(L, res);
|
||||
return 1;
|
||||
|
@ -552,7 +552,7 @@ static void modinit (lua_State *L, const char *modname) {
|
|||
lua_setfield(L, -2, "_M"); /* module._M = module */
|
||||
lua_pushstring(L, modname);
|
||||
lua_setfield(L, -2, "_NAME");
|
||||
dot = c_strrchr(modname, '.'); /* look for last dot in module name */
|
||||
dot = strrchr(modname, '.'); /* look for last dot in module name */
|
||||
if (dot == NULL) dot = modname;
|
||||
else dot++;
|
||||
/* set _PACKAGE as package name (full module name minus last part) */
|
||||
|
@ -563,7 +563,7 @@ static void modinit (lua_State *L, const char *modname) {
|
|||
|
||||
static int ll_module (lua_State *L) {
|
||||
const char *modname = luaL_checkstring(L, 1);
|
||||
if (luaR_findglobal(modname, c_strlen(modname)))
|
||||
if (luaR_findglobal(modname, strlen(modname)))
|
||||
return 0;
|
||||
int loaded = lua_gettop(L) + 1; /* index of _LOADED table */
|
||||
lua_getfield(L, LUA_REGISTRYINDEX, "_LOADED");
|
||||
|
|
|
@ -10,9 +10,9 @@
|
|||
#define LUAC_CROSS_FILE
|
||||
|
||||
#include "lua.h"
|
||||
#include C_HEADER_STDIO
|
||||
#include C_HEADER_STRING
|
||||
#include C_HEADER_STDLIB
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "ldo.h"
|
||||
#include "lmem.h"
|
||||
|
@ -25,6 +25,7 @@
|
|||
#else
|
||||
#include <limits.h>
|
||||
#endif
|
||||
|
||||
const TValue luaO_nilobject_ = {LUA_TVALUE_NIL};
|
||||
|
||||
|
||||
|
@ -113,7 +114,7 @@ int luaO_str2d (const char *s, lua_Number *result) {
|
|||
*result = cast_num(lres);
|
||||
}
|
||||
#else
|
||||
*result = cast_num(c_strtoul(s, &endptr, 16));
|
||||
*result = cast_num(strtoul(s, &endptr, 16));
|
||||
#endif
|
||||
if (*endptr == '\0') return 1; /* most common case */
|
||||
while (isspace(cast(unsigned char, *endptr))) endptr++;
|
||||
|
@ -134,7 +135,7 @@ const char *luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp) {
|
|||
int n = 1;
|
||||
pushstr(L, "");
|
||||
for (;;) {
|
||||
const char *e = c_strchr(fmt, '%');
|
||||
const char *e = strchr(fmt, '%');
|
||||
if (e == NULL) break;
|
||||
setsvalue2s(L, L->top, luaS_newlstr(L, fmt, e-fmt));
|
||||
incr_top(L);
|
||||
|
@ -164,7 +165,7 @@ const char *luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp) {
|
|||
}
|
||||
case 'p': {
|
||||
char buff[4*sizeof(void *) + 8]; /* should be enough space for a `%p' */
|
||||
c_sprintf(buff, "%p", va_arg(argp, void *));
|
||||
sprintf(buff, "%p", va_arg(argp, void *));
|
||||
pushstr(L, buff);
|
||||
break;
|
||||
}
|
||||
|
@ -203,7 +204,7 @@ const char *luaO_pushfstring (lua_State *L, const char *fmt, ...) {
|
|||
|
||||
void luaO_chunkid (char *out, const char *source, size_t bufflen) {
|
||||
if (*source == '=') {
|
||||
c_strncpy(out, source+1, bufflen); /* remove first char */
|
||||
strncpy(out, source+1, bufflen); /* remove first char */
|
||||
out[bufflen-1] = '\0'; /* ensures null termination */
|
||||
}
|
||||
else { /* out = "source", or "...source" */
|
||||
|
@ -211,26 +212,26 @@ void luaO_chunkid (char *out, const char *source, size_t bufflen) {
|
|||
size_t l;
|
||||
source++; /* skip the `@' */
|
||||
bufflen -= sizeof(" '...' ");
|
||||
l = c_strlen(source);
|
||||
c_strcpy(out, "");
|
||||
l = strlen(source);
|
||||
strcpy(out, "");
|
||||
if (l > bufflen) {
|
||||
source += (l-bufflen); /* get last part of file name */
|
||||
c_strcat(out, "...");
|
||||
strcat(out, "...");
|
||||
}
|
||||
c_strcat(out, source);
|
||||
strcat(out, source);
|
||||
}
|
||||
else { /* out = [string "string"] */
|
||||
size_t len = c_strcspn(source, "\n\r"); /* stop at first newline */
|
||||
size_t len = strcspn(source, "\n\r"); /* stop at first newline */
|
||||
bufflen -= sizeof(" [string \"...\"] ");
|
||||
if (len > bufflen) len = bufflen;
|
||||
c_strcpy(out, "[string \"");
|
||||
strcpy(out, "[string \"");
|
||||
if (source[len] != '\0') { /* must truncate? */
|
||||
c_strncat(out, source, len);
|
||||
c_strcat(out, "...");
|
||||
strncat(out, source, len);
|
||||
strcat(out, "...");
|
||||
}
|
||||
else
|
||||
c_strcat(out, source);
|
||||
c_strcat(out, "\"]");
|
||||
strcat(out, source);
|
||||
strcat(out, "\"]");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,11 +8,7 @@
|
|||
#ifndef lobject_h
|
||||
#define lobject_h
|
||||
|
||||
#ifdef LUA_CROSS_COMPILER
|
||||
#include <stdarg.h>
|
||||
#else
|
||||
#include "c_stdarg.h"
|
||||
#endif
|
||||
|
||||
#include "llimits.h"
|
||||
#include "lua.h"
|
||||
|
|
|
@ -20,10 +20,10 @@ extern const luaR_table lua_rotable[];
|
|||
void* luaR_findglobal(const char *name, unsigned len) {
|
||||
unsigned i;
|
||||
|
||||
if (c_strlen(name) > LUA_MAX_ROTABLE_NAME)
|
||||
if (strlen(name) > LUA_MAX_ROTABLE_NAME)
|
||||
return NULL;
|
||||
for (i=0; lua_rotable[i].name; i ++)
|
||||
if (*lua_rotable[i].name != '\0' && c_strlen(lua_rotable[i].name) == len && !c_strncmp(lua_rotable[i].name, name, len)) {
|
||||
if (*lua_rotable[i].name != '\0' && strlen(lua_rotable[i].name) == len && !strncmp(lua_rotable[i].name, name, len)) {
|
||||
return (void*)(lua_rotable[i].pentries);
|
||||
}
|
||||
return NULL;
|
||||
|
@ -37,7 +37,7 @@ static const TValue* luaR_auxfind(const luaR_entry *pentry, const char *strkey,
|
|||
if (pentry == NULL)
|
||||
return NULL;
|
||||
while(pentry->key.type != LUA_TNIL) {
|
||||
if ((strkey && (pentry->key.type == LUA_TSTRING) && (!c_strcmp(pentry->key.id.strkey, strkey))) ||
|
||||
if ((strkey && (pentry->key.type == LUA_TSTRING) && (!strcmp(pentry->key.id.strkey, strkey))) ||
|
||||
(!strkey && (pentry->key.type == LUA_TNUMBER) && ((luaR_numkey)pentry->key.id.numkey == numkey))) {
|
||||
res = &pentry->value;
|
||||
break;
|
||||
|
@ -120,7 +120,7 @@ void luaR_getcstr(char *dest, const TString *src, size_t maxsize) {
|
|||
if (src->tsv.len+1 > maxsize)
|
||||
dest[0] = '\0';
|
||||
else {
|
||||
c_memcpy(dest, getstr(src), src->tsv.len);
|
||||
memcpy(dest, getstr(src), src->tsv.len);
|
||||
dest[src->tsv.len] = '\0';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -67,7 +67,7 @@ static TString *newlstr (lua_State *L, const char *str, size_t l,
|
|||
ts->tsv.marked = luaC_white(G(L));
|
||||
ts->tsv.tt = LUA_TSTRING;
|
||||
if (!readonly) {
|
||||
c_memcpy(ts+1, str, l*sizeof(char));
|
||||
memcpy(ts+1, str, l*sizeof(char));
|
||||
((char *)(ts+1))[l] = '\0'; /* ending 0 */
|
||||
} else {
|
||||
*(char **)(ts+1) = (char *)str;
|
||||
|
@ -92,7 +92,7 @@ static TString *luaS_newlstr_helper (lua_State *L, const char *str, size_t l, in
|
|||
o != NULL;
|
||||
o = o->gch.next) {
|
||||
TString *ts = rawgco2ts(o);
|
||||
if (ts->tsv.len == l && (c_memcmp(str, getstr(ts), l) == 0)) {
|
||||
if (ts->tsv.len == l && (memcmp(str, getstr(ts), l) == 0)) {
|
||||
/* string may be dead */
|
||||
if (isdead(G(L), o)) changewhite(o);
|
||||
return ts;
|
||||
|
@ -115,7 +115,7 @@ static int lua_is_ptr_in_ro_area(const char *p) {
|
|||
TString *luaS_newlstr (lua_State *L, const char *str, size_t l) {
|
||||
// If the pointer is in a read-only memory and the string is at least 4 chars in length,
|
||||
// create it as a read-only string instead
|
||||
if(lua_is_ptr_in_ro_area(str) && l+1 > sizeof(char**) && l == c_strlen(str))
|
||||
if(lua_is_ptr_in_ro_area(str) && l+1 > sizeof(char**) && l == strlen(str))
|
||||
return luaS_newlstr_helper(L, str, l, LUAS_READONLY_STRING);
|
||||
else
|
||||
return luaS_newlstr_helper(L, str, l, LUAS_REGULAR_STRING);
|
||||
|
@ -123,7 +123,7 @@ TString *luaS_newlstr (lua_State *L, const char *str, size_t l) {
|
|||
|
||||
|
||||
LUAI_FUNC TString *luaS_newrolstr (lua_State *L, const char *str, size_t l) {
|
||||
if(l+1 > sizeof(char**) && l == c_strlen(str))
|
||||
if(l+1 > sizeof(char**) && l == strlen(str))
|
||||
return luaS_newlstr_helper(L, str, l, LUAS_READONLY_STRING);
|
||||
else // no point in creating a RO string, as it would actually be larger
|
||||
return luaS_newlstr_helper(L, str, l, LUAS_REGULAR_STRING);
|
||||
|
|
|
@ -17,8 +17,8 @@
|
|||
|
||||
#define sizeudata(u) (sizeof(union Udata)+(u)->len)
|
||||
|
||||
#define luaS_new(L, s) (luaS_newlstr(L, s, c_strlen(s)))
|
||||
#define luaS_newro(L, s) (luaS_newrolstr(L, s, c_strlen(s)))
|
||||
#define luaS_new(L, s) (luaS_newlstr(L, s, strlen(s)))
|
||||
#define luaS_newro(L, s) (luaS_newrolstr(L, s, strlen(s)))
|
||||
#define luaS_newliteral(L, s) (luaS_newlstr(L, "" s, \
|
||||
(sizeof(s)/sizeof(char))-1))
|
||||
|
||||
|
|
|
@ -353,7 +353,7 @@ static const char *match_capture (MatchState *ms, const char *s, int l) {
|
|||
l = check_capture(ms, l);
|
||||
len = ms->capture[l].len;
|
||||
if ((size_t)(ms->src_end-s) >= len &&
|
||||
c_memcmp(ms->capture[l].init, s, len) == 0)
|
||||
memcmp(ms->capture[l].init, s, len) == 0)
|
||||
return s+len;
|
||||
else return NULL;
|
||||
}
|
||||
|
@ -448,7 +448,7 @@ static const char *lmemfind (const char *s1, size_t l1,
|
|||
l1 = l1-l2; /* `s2' cannot be found after that */
|
||||
while (l1 > 0 && (init = (const char *)memchr(s1, *s2, l1)) != NULL) {
|
||||
init++; /* 1st char is already checked */
|
||||
if (c_memcmp(init, s2+1, l2) == 0)
|
||||
if (memcmp(init, s2+1, l2) == 0)
|
||||
return init-1;
|
||||
else { /* correct `l1' and `s1' to try again */
|
||||
l1 -= init-s1;
|
||||
|
@ -497,7 +497,7 @@ static int str_find_aux (lua_State *L, int find) {
|
|||
if (init < 0) init = 0;
|
||||
else if ((size_t)(init) > l1) init = (ptrdiff_t)l1;
|
||||
if (find && (lua_toboolean(L, 4) || /* explicit request? */
|
||||
c_strpbrk(p, SPECIALS) == NULL)) { /* or no special characters? */
|
||||
strpbrk(p, SPECIALS) == NULL)) { /* or no special characters? */
|
||||
/* do a plain search */
|
||||
const char *s2 = lmemfind(s+init, l1-init, p, l2);
|
||||
if (s2) {
|
||||
|
@ -724,7 +724,7 @@ static void addquoted (lua_State *L, luaL_Buffer *b, int arg) {
|
|||
|
||||
static const char *scanformat (lua_State *L, const char *strfrmt, char *form) {
|
||||
const char *p = strfrmt;
|
||||
while (*p != '\0' && c_strchr(FLAGS, *p) != NULL) p++; /* skip flags */
|
||||
while (*p != '\0' && strchr(FLAGS, *p) != NULL) p++; /* skip flags */
|
||||
if ((size_t)(p - strfrmt) >= sizeof(FLAGS))
|
||||
luaL_error(L, "invalid format (repeated flags)");
|
||||
if (isdigit(uchar(*p))) p++; /* skip width */
|
||||
|
@ -737,7 +737,7 @@ static const char *scanformat (lua_State *L, const char *strfrmt, char *form) {
|
|||
if (isdigit(uchar(*p)))
|
||||
luaL_error(L, "invalid format (width or precision too long)");
|
||||
*(form++) = '%';
|
||||
c_strncpy(form, strfrmt, p - strfrmt + 1);
|
||||
strncpy(form, strfrmt, p - strfrmt + 1);
|
||||
form += p - strfrmt + 1;
|
||||
*form = '\0';
|
||||
return p;
|
||||
|
@ -745,9 +745,9 @@ static const char *scanformat (lua_State *L, const char *strfrmt, char *form) {
|
|||
|
||||
|
||||
static void addintlen (char *form) {
|
||||
size_t l = c_strlen(form);
|
||||
size_t l = strlen(form);
|
||||
char spec = form[l - 1];
|
||||
c_strcpy(form + l - 1, LUA_INTFRMLEN);
|
||||
strcpy(form + l - 1, LUA_INTFRMLEN);
|
||||
form[l + sizeof(LUA_INTFRMLEN) - 2] = spec;
|
||||
form[l + sizeof(LUA_INTFRMLEN) - 1] = '\0';
|
||||
}
|
||||
|
@ -774,23 +774,23 @@ static int str_format (lua_State *L) {
|
|||
strfrmt = scanformat(L, strfrmt, form);
|
||||
switch (*strfrmt++) {
|
||||
case 'c': {
|
||||
c_sprintf(buff, form, (int)luaL_checknumber(L, arg));
|
||||
sprintf(buff, form, (int)luaL_checknumber(L, arg));
|
||||
break;
|
||||
}
|
||||
case 'd': case 'i': {
|
||||
addintlen(form);
|
||||
c_sprintf(buff, form, (LUA_INTFRM_T)luaL_checknumber(L, arg));
|
||||
sprintf(buff, form, (LUA_INTFRM_T)luaL_checknumber(L, arg));
|
||||
break;
|
||||
}
|
||||
case 'o': case 'u': case 'x': case 'X': {
|
||||
addintlen(form);
|
||||
c_sprintf(buff, form, (unsigned LUA_INTFRM_T)luaL_checknumber(L, arg));
|
||||
sprintf(buff, form, (unsigned LUA_INTFRM_T)luaL_checknumber(L, arg));
|
||||
break;
|
||||
}
|
||||
#if !defined LUA_NUMBER_INTEGRAL
|
||||
case 'e': case 'E': case 'f':
|
||||
case 'g': case 'G': {
|
||||
c_sprintf(buff, form, (double)luaL_checknumber(L, arg));
|
||||
sprintf(buff, form, (double)luaL_checknumber(L, arg));
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
|
@ -801,7 +801,7 @@ static int str_format (lua_State *L) {
|
|||
case 's': {
|
||||
size_t l;
|
||||
const char *s = luaL_checklstring(L, arg, &l);
|
||||
if (!c_strchr(form, '.') && l >= 100) {
|
||||
if (!strchr(form, '.') && l >= 100) {
|
||||
/* no precision and string is too long to be formatted;
|
||||
keep original string */
|
||||
lua_pushvalue(L, arg);
|
||||
|
@ -809,7 +809,7 @@ static int str_format (lua_State *L) {
|
|||
continue; /* skip the `addsize' at the end */
|
||||
}
|
||||
else {
|
||||
c_sprintf(buff, form, s);
|
||||
sprintf(buff, form, s);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -818,7 +818,7 @@ static int str_format (lua_State *L) {
|
|||
LUA_QL("format"), *(strfrmt - 1));
|
||||
}
|
||||
}
|
||||
luaL_addlstring(&b, buff, c_strlen(buff));
|
||||
luaL_addlstring(&b, buff, strlen(buff));
|
||||
}
|
||||
}
|
||||
luaL_pushresult(&b);
|
||||
|
|
|
@ -86,7 +86,7 @@ static Node *hashnum (const Table *t, lua_Number n) {
|
|||
int i;
|
||||
if (luai_numeq(n, 0)) /* avoid problems with -0 */
|
||||
return gnode(t, 0);
|
||||
c_memcpy(a, &n, sizeof(a));
|
||||
memcpy(a, &n, sizeof(a));
|
||||
for (i = 1; i < numints; i++) a[0] += a[i];
|
||||
return hashmod(t, a[0]);
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
#define LUAC_CROSS_FILE
|
||||
|
||||
#include "lua.h"
|
||||
#include C_HEADER_STRING
|
||||
#include <string.h>
|
||||
|
||||
#include "lobject.h"
|
||||
#include "lstate.h"
|
||||
|
|
|
@ -5,14 +5,15 @@
|
|||
*/
|
||||
|
||||
|
||||
// #include "c_signal.h"
|
||||
#include "c_stdio.h"
|
||||
#include "c_stdlib.h"
|
||||
#include "c_string.h"
|
||||
// #include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "flash_fs.h"
|
||||
#include "user_version.h"
|
||||
#include "driver/readline.h"
|
||||
#include "driver/uart.h"
|
||||
#include "esp_system.h"
|
||||
|
||||
#define lua_c
|
||||
|
||||
|
@ -167,7 +168,7 @@ static int dofsfile (lua_State *L, const char *name) {
|
|||
#endif
|
||||
|
||||
static int dostring (lua_State *L, const char *s, const char *name) {
|
||||
int status = luaL_loadbuffer(L, s, c_strlen(s), name) || docall(L, 0, 1);
|
||||
int status = luaL_loadbuffer(L, s, strlen(s), name) || docall(L, 0, 1);
|
||||
return report(L, status);
|
||||
}
|
||||
|
||||
|
@ -193,7 +194,7 @@ static int incomplete (lua_State *L, int status) {
|
|||
size_t lmsg;
|
||||
const char *msg = lua_tolstring(L, -1, &lmsg);
|
||||
const char *tp = msg + lmsg - (sizeof(LUA_QL("<eof>")) - 1);
|
||||
if (c_strstr(msg, LUA_QL("<eof>")) == tp) {
|
||||
if (strstr(msg, LUA_QL("<eof>")) == tp) {
|
||||
lua_pop(L, 1);
|
||||
return 1;
|
||||
}
|
||||
|
@ -209,7 +210,7 @@ static int pushline (lua_State *L, int firstline) {
|
|||
const char *prmt = get_prompt(L, firstline);
|
||||
if (lua_readline(L, b, prmt) == 0)
|
||||
return 0; /* no input */
|
||||
l = c_strlen(b);
|
||||
l = strlen(b);
|
||||
if (l > 0 && b[l-1] == '\n') /* line ends with newline? */
|
||||
b[l-1] = '\0'; /* remove it */
|
||||
if (firstline && b[0] == '=') /* first line starts with `=' ? */
|
||||
|
@ -276,7 +277,7 @@ static int handle_script (lua_State *L, char **argv, int n) {
|
|||
int narg = getargs(L, argv, n); /* collect arguments */
|
||||
lua_setglobal(L, "arg");
|
||||
fname = argv[n];
|
||||
if (c_strcmp(fname, "-") == 0 && c_strcmp(argv[n-1], "--") != 0)
|
||||
if (strcmp(fname, "-") == 0 && strcmp(argv[n-1], "--") != 0)
|
||||
fname = NULL; /* stdin */
|
||||
status = luaL_loadfile(L, fname);
|
||||
lua_insert(L, -(narg+1));
|
||||
|
@ -345,7 +346,7 @@ static int runargs (lua_State *L, char **argv, int n) {
|
|||
int memlimit=0;
|
||||
if (*limit == '\0') limit = argv[++i];
|
||||
lua_assert(limit != NULL);
|
||||
memlimit = c_atoi(limit);
|
||||
memlimit = atoi(limit);
|
||||
lua_gc(L, LUA_GCSETMEMLIMIT, memlimit);
|
||||
break;
|
||||
}
|
||||
|
@ -487,7 +488,7 @@ static void dojob(lua_Load *load){
|
|||
|
||||
do{
|
||||
if(load->done == 1){
|
||||
l = c_strlen(b);
|
||||
l = strlen(b);
|
||||
if (l > 0 && b[l-1] == '\n') /* line ends with newline? */
|
||||
b[l-1] = '\0'; /* remove it */
|
||||
if (load->firstline && b[0] == '=') /* first line starts with `=' ? */
|
||||
|
@ -531,8 +532,8 @@ static void dojob(lua_Load *load){
|
|||
|
||||
load->done = 0;
|
||||
load->line_position = 0;
|
||||
c_memset(load->line, 0, load->len);
|
||||
c_puts(load->prmt);
|
||||
memset(load->line, 0, load->len);
|
||||
puts(load->prmt);
|
||||
}
|
||||
|
||||
#ifndef uart_putc
|
||||
|
@ -598,7 +599,7 @@ static bool readline(lua_Load *load){
|
|||
if (load->line_position == 0)
|
||||
{
|
||||
/* Get a empty line, then go to get a new line */
|
||||
c_puts(load->prmt);
|
||||
puts(load->prmt);
|
||||
} else {
|
||||
load->done = 1;
|
||||
need_dojob = true;
|
||||
|
|
|
@ -11,17 +11,10 @@
|
|||
#ifdef LUAC_CROSS_FILE
|
||||
#include "luac_cross.h"
|
||||
#endif
|
||||
#ifdef LUA_CROSS_COMPILER
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <ctype.h>
|
||||
#else
|
||||
#include "c_stdarg.h"
|
||||
#include "c_stddef.h"
|
||||
#include "c_types.h"
|
||||
#include <ctype.h>
|
||||
#endif
|
||||
|
||||
#include <stdbool.h>
|
||||
#include "luaconf.h"
|
||||
|
||||
|
||||
|
|
|
@ -5,8 +5,6 @@
|
|||
#ifndef luac_cross_h
|
||||
#define luac_cross_h
|
||||
|
||||
#ifdef LUA_CROSS_COMPILER
|
||||
|
||||
#define C_HEADER_ASSERT <assert.h>
|
||||
#define C_HEADER_CTYPE <ctype.h>
|
||||
#define C_HEADER_ERRNO <errno.h>
|
||||
|
@ -18,59 +16,8 @@
|
|||
#define C_HEADER_STRING <string.h>
|
||||
#define C_HEADER_TIME <time.h>
|
||||
|
||||
#ifdef LUA_CROSS_COMPILER
|
||||
#define ICACHE_RODATA_ATTR
|
||||
#endif
|
||||
|
||||
#define c_abs abs
|
||||
#define c_exit exit
|
||||
#define c_fclose fclose
|
||||
#define c_feof feof
|
||||
#define c_ferror ferror
|
||||
#define c_fopen fopen
|
||||
#define c_fread fread
|
||||
#define c_free free
|
||||
#define c_freopen freopen
|
||||
#define c_getc getc
|
||||
#define c_getenv getenv
|
||||
#define c_memcmp memcmp
|
||||
#define c_memcpy memcpy
|
||||
#define c_printf printf
|
||||
#define c_puts puts
|
||||
#define c_reader reader
|
||||
#define c_realloc realloc
|
||||
#define c_sprintf sprintf
|
||||
#define c_stderr stderr
|
||||
#define c_stdin stdin
|
||||
#define c_stdout stdout
|
||||
#define c_strcat strcat
|
||||
#define c_strchr strchr
|
||||
#define c_strcmp strcmp
|
||||
#define c_strcoll strcoll
|
||||
#define c_strcpy strcpy
|
||||
#define c_strcspn strcspn
|
||||
#define c_strerror strerror
|
||||
#define c_strlen strlen
|
||||
#define c_strncat strncat
|
||||
#define c_strncmp strncmp
|
||||
#define c_strncpy strncpy
|
||||
#define c_strpbrk strpbrk
|
||||
#define c_strrchr strrchr
|
||||
#define c_strstr strstr
|
||||
double c_strtod(const char *__n, char **__end_PTR);
|
||||
#define c_strtoul strtoul
|
||||
#define c_ungetc ungetc
|
||||
|
||||
#else
|
||||
|
||||
#define C_HEADER_ASSERT "c_assert.h"
|
||||
#define C_HEADER_CTYPE "c_ctype.h"
|
||||
#define C_HEADER_ERRNO "c_errno.h"
|
||||
#define C_HEADER_FCNTL "c_fcntl.h"
|
||||
#define C_HEADER_LOCALE "c_locale.h"
|
||||
#define C_HEADER_MATH "c_math.h"
|
||||
#define C_HEADER_STDIO "c_stdio.h"
|
||||
#define C_HEADER_STDLIB "c_stdlib.h"
|
||||
#define C_HEADER_STRING "c_string.h"
|
||||
#define C_HEADER_TIME "c_time.h"
|
||||
|
||||
#endif /* LUA_CROSS_COMPILER */
|
||||
#endif /* luac_cross_h */
|
||||
|
|
|
@ -8,13 +8,8 @@
|
|||
#ifndef lconfig_h
|
||||
#define lconfig_h
|
||||
|
||||
#ifdef LUA_CROSS_COMPILER
|
||||
#include <limits.h>
|
||||
#include <stddef.h>
|
||||
#else
|
||||
#include "c_limits.h"
|
||||
#include "c_stddef.h"
|
||||
#endif
|
||||
#include "user_config.h"
|
||||
|
||||
/*
|
||||
|
@ -260,7 +255,7 @@
|
|||
#ifdef LUA_CROSS_COMPILER
|
||||
#include <stdio.h>
|
||||
else
|
||||
#include "c_stdio.h"
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
#define lua_stdin_is_tty() _isatty(_fileno(stdin))
|
||||
|
@ -312,11 +307,11 @@ else
|
|||
#define lua_saveline(L,idx) \
|
||||
if (lua_strlen(L,idx) > 0) /* non-empty line? */ \
|
||||
add_history(lua_tostring(L, idx)); /* add it to history */
|
||||
#define lua_freeline(L,b) ((void)L, c_free(b))
|
||||
#define lua_freeline(L,b) ((void)L, free(b))
|
||||
#else // #if defined(LUA_CROSS_COMPILER) && defined(LUA_USE_READLINE)
|
||||
#define lua_readline(L,b,p) \
|
||||
((void)L, c_fputs(p, c_stdout), c_fflush(c_stdout), /* show prompt */ \
|
||||
c_fgets(b, LUA_MAXINPUT, c_stdin) != NULL) /* get line */
|
||||
((void)L, fputs(p, stdout), fflush(stdout), /* show prompt */ \
|
||||
fgets(b, LUA_MAXINPUT, stdin) != NULL) /* get line */
|
||||
#define lua_saveline(L,idx) { (void)L; (void)idx; }
|
||||
#define lua_freeline(L,b) { (void)L; (void)b; }
|
||||
#endif // #if defined(LUA_USE_READLINE)
|
||||
|
@ -337,8 +332,8 @@ extern int readline4lua(const char *prompt, char *buffer, int length);
|
|||
** avoids including 'stdio.h' everywhere.)
|
||||
*/
|
||||
#if !defined(LUA_USE_STDIO)
|
||||
#define luai_writestring(s, l) c_puts(s)
|
||||
#define luai_writeline() c_puts("\n")
|
||||
#define luai_writestring(s, l) puts(s)
|
||||
#define luai_writeline() puts("\n")
|
||||
#endif // defined(LUA_USE_STDIO)
|
||||
|
||||
/*
|
||||
|
@ -346,7 +341,7 @@ extern int readline4lua(const char *prompt, char *buffer, int length);
|
|||
** (A format string with one argument is enough for Lua...)
|
||||
*/
|
||||
#if !defined(LUA_USE_STDIO)
|
||||
#define luai_writestringerror(s,p) c_printf((s), (p))
|
||||
#define luai_writestringerror(s,p) printf((s), (p))
|
||||
#endif // defined(LUA_USE_STDIO)
|
||||
|
||||
|
||||
|
@ -617,27 +612,23 @@ extern int readline4lua(const char *prompt, char *buffer, int length);
|
|||
#define LUA_NUMBER_SCAN "%lf"
|
||||
#define LUA_NUMBER_FMT "%.14g"
|
||||
#endif // #if defined LUA_NUMBER_INTEGRAL
|
||||
#define lua_number2str(s,n) c_sprintf((s), LUA_NUMBER_FMT, (n))
|
||||
#define lua_number2str(s,n) sprintf((s), LUA_NUMBER_FMT, (n))
|
||||
#define LUAI_MAXNUMBER2STR 32 /* 16 digits, sign, point, and \0 */
|
||||
#if defined LUA_NUMBER_INTEGRAL
|
||||
#if !defined LUA_INTEGRAL_LONGLONG
|
||||
#define lua_str2number(s,p) c_strtol((s), (p), 10)
|
||||
#define lua_str2number(s,p) strtol((s), (p), 10)
|
||||
#else
|
||||
#define lua_str2number(s,p) c_strtoll((s), (p), 10)
|
||||
#define lua_str2number(s,p) strtoll((s), (p), 10)
|
||||
#endif // #if !defined LUA_INTEGRAL_LONGLONG
|
||||
#else
|
||||
#define lua_str2number(s,p) c_strtod((s), (p))
|
||||
#define lua_str2number(s,p) strtod((s), (p))
|
||||
#endif // #if defined LUA_NUMBER_INTEGRAL
|
||||
|
||||
/*
|
||||
@@ The luai_num* macros define the primitive operations over numbers.
|
||||
*/
|
||||
#if defined(LUA_CORE) || defined(LUA_LIB)
|
||||
#ifdef LUA_CROSS_COMPILER
|
||||
#include <math.h>
|
||||
#else
|
||||
#include "c_math.h"
|
||||
#endif
|
||||
#define luai_numadd(a,b) ((a)+(b))
|
||||
#define luai_numsub(a,b) ((a)-(b))
|
||||
#define luai_nummul(a,b) ((a)*(b))
|
||||
|
@ -782,7 +773,7 @@ union luai_Cast { double l_d; long l_l; };
|
|||
#include <unistd.h>
|
||||
#define LUA_TMPNAMBUFSIZE 32
|
||||
#define lua_tmpnam(b,e) { \
|
||||
c_strcpy(b, "/tmp/lua_XXXXXX"); \
|
||||
strcpy(b, "/tmp/lua_XXXXXX"); \
|
||||
e = mkstemp(b); \
|
||||
if (e != -1) close(e); \
|
||||
e = (e == -1); }
|
||||
|
@ -802,7 +793,7 @@ union luai_Cast { double l_d; long l_l; };
|
|||
*/
|
||||
#if defined(LUA_USE_POPEN)
|
||||
|
||||
#define lua_popen(L,c,m) ((void)L, c_fflush(NULL), popen(c,m))
|
||||
#define lua_popen(L,c,m) ((void)L, fflush(NULL), popen(c,m))
|
||||
#define lua_pclose(L,file) ((void)L, (pclose(file) != -1))
|
||||
|
||||
#elif defined(LUA_WIN)
|
||||
|
|
|
@ -309,7 +309,7 @@ static void LoadHeader(LoadState* S)
|
|||
S->numsize=h[10]=s[10]; /* length of lua_Number */
|
||||
S->toflt=(s[11]>intck); /* check if conversion from int lua_Number to flt is needed */
|
||||
if(S->toflt) s[11]=h[11];
|
||||
IF (c_memcmp(h,s,LUAC_HEADERSIZE)!=0, "bad header");
|
||||
IF (memcmp(h,s,LUAC_HEADERSIZE)!=0, "bad header");
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -338,7 +338,7 @@ Proto* luaU_undump (lua_State* L, ZIO* Z, Mbuffer* buff, const char* name)
|
|||
void luaU_header (char* h)
|
||||
{
|
||||
int x=1;
|
||||
c_memcpy(h,LUA_SIGNATURE,sizeof(LUA_SIGNATURE)-1);
|
||||
memcpy(h,LUA_SIGNATURE,sizeof(LUA_SIGNATURE)-1);
|
||||
h+=sizeof(LUA_SIGNATURE)-1;
|
||||
*h++=(char)LUAC_VERSION;
|
||||
*h++=(char)LUAC_FORMAT;
|
||||
|
|
|
@ -7,11 +7,7 @@
|
|||
#ifndef lundump_h
|
||||
#define lundump_h
|
||||
|
||||
#ifdef LUA_CROSS_COMPILER
|
||||
#include <stdint.h>
|
||||
#else
|
||||
#include "c_stdint.h"
|
||||
#endif
|
||||
|
||||
#include "lobject.h"
|
||||
#include "lzio.h"
|
||||
|
|
|
@ -239,10 +239,10 @@ static int l_strcmp (const TString *ls, const TString *rs) {
|
|||
const char *r = getstr(rs);
|
||||
size_t lr = rs->tsv.len;
|
||||
for (;;) {
|
||||
int temp = c_strcoll(l, r);
|
||||
int temp = strcoll(l, r);
|
||||
if (temp != 0) return temp;
|
||||
else { /* strings are equal up to a `\0' */
|
||||
size_t len = c_strlen(l); /* index of first `\0' in both strings */
|
||||
size_t len = strlen(l); /* index of first `\0' in both strings */
|
||||
if (len == lr) /* r is finished? */
|
||||
return (len == ll) ? 0 : 1;
|
||||
else if (len == ll) /* l is finished? */
|
||||
|
@ -349,7 +349,7 @@ void luaV_concat (lua_State *L, int total, int last) {
|
|||
tl = 0;
|
||||
for (i=n; i>0; i--) { /* concat all strings */
|
||||
size_t l = tsvalue(top-i)->len;
|
||||
c_memcpy(buffer+tl, svalue(top-i), l);
|
||||
memcpy(buffer+tl, svalue(top-i), l);
|
||||
tl += l;
|
||||
}
|
||||
setsvalue2s(L, top-n, luaS_newlstr(L, buffer, tl));
|
||||
|
|
|
@ -62,7 +62,7 @@ size_t luaZ_read (ZIO *z, void *b, size_t n) {
|
|||
return n; /* return number of missing bytes */
|
||||
m = (n <= z->n) ? n : z->n; /* min. between n and z->n */
|
||||
if (b)
|
||||
c_memcpy(b, z->p, m);
|
||||
memcpy(b, z->p, m);
|
||||
z->n -= m;
|
||||
z->i += m;
|
||||
z->p += m;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#include "c_stdlib.h"
|
||||
#include "c_string.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "lualib.h"
|
||||
#include "lauxlib.h"
|
||||
#include "lrotable.h"
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
|
||||
#include "module.h"
|
||||
#include "c_limits.h"
|
||||
#include <limits.h>
|
||||
|
||||
#include "lauxlib.h"
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
#include "module.h"
|
||||
#include "lauxlib.h"
|
||||
#include "platform.h"
|
||||
#include "c_math.h"
|
||||
#include <math.h>
|
||||
#include "user_interface.h"
|
||||
|
||||
/****************************************************/
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
#include "module.h"
|
||||
#include "lauxlib.h"
|
||||
#include "platform.h"
|
||||
#include "c_stdlib.h"
|
||||
#include "c_string.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "esp_misc.h"
|
||||
|
||||
static const uint32_t bmp085_i2c_id = 0;
|
||||
|
|
|
@ -38,9 +38,9 @@
|
|||
|
||||
// #include <assert.h>
|
||||
#include "module.h"
|
||||
#include "c_string.h"
|
||||
#include "c_math.h"
|
||||
#include "c_limits.h"
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include <limits.h>
|
||||
#include "lauxlib.h"
|
||||
#include "flash_api.h"
|
||||
#include "ctype.h"
|
||||
|
@ -340,7 +340,7 @@ static int json_integer_option(lua_State *l, int optindex, int *setting,
|
|||
|
||||
if (!lua_isnil(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);
|
||||
*setting = value;
|
||||
}
|
||||
|
@ -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);
|
||||
// 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);
|
||||
len = c_strlen(strbuf_empty_ptr(json));
|
||||
sprintf(strbuf_empty_ptr(json), LUA_NUMBER_FMT, (LUA_NUMBER)num);
|
||||
len = strlen(strbuf_empty_ptr(json));
|
||||
|
||||
strbuf_extend_length(json, len);
|
||||
}
|
||||
|
@ -1148,7 +1148,7 @@ static int json_is_invalid_number(json_parse_t *json)
|
|||
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;
|
||||
for (i = 0; i < 3; ++i)
|
||||
{
|
||||
|
@ -1160,9 +1160,9 @@ static int json_is_invalid_number(json_parse_t *json)
|
|||
tmp[3] = 0;
|
||||
|
||||
/* Reject inf/nan */
|
||||
if (!c_strncasecmp(tmp, "inf", 3))
|
||||
if (!strncasecmp(tmp, "inf", 3))
|
||||
return 1;
|
||||
if (!c_strncasecmp(tmp, "nan", 3))
|
||||
if (!strncasecmp(tmp, "nan", 3))
|
||||
return 1;
|
||||
|
||||
/* 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)
|
|||
}
|
||||
json_next_number_token(json, token);
|
||||
return;
|
||||
} else if (!c_strncmp(json->ptr, "true", 4)) {
|
||||
} else if (!strncmp(json->ptr, "true", 4)) {
|
||||
token->type = T_BOOLEAN;
|
||||
token->value.boolean = 1;
|
||||
json->ptr += 4;
|
||||
return;
|
||||
} else if (!c_strncmp(json->ptr, "false", 5)) {
|
||||
} else if (!strncmp(json->ptr, "false", 5)) {
|
||||
token->type = T_BOOLEAN;
|
||||
token->value.boolean = 0;
|
||||
json->ptr += 5;
|
||||
return;
|
||||
} else if (!c_strncmp(json->ptr, "null", 4)) {
|
||||
} else if (!strncmp(json->ptr, "null", 4)) {
|
||||
token->type = T_NULL;
|
||||
json->ptr += 4;
|
||||
return;
|
||||
|
|
|
@ -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 "mem.h"
|
||||
|
@ -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'
|
||||
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) {
|
||||
NODE_DBG("Request Entity Too Large.\n"); // NOTE: should response 4.13 to client...
|
||||
return;
|
||||
}
|
||||
// c_memcpy(buf, pdata, len);
|
||||
// memcpy(buf, pdata, len);
|
||||
|
||||
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)
|
|||
if (espconn_get_connection_info (pesp_conn, &pr, 0) != ESPCONN_OK)
|
||||
return;
|
||||
pesp_conn->proto.udp->remote_port = pr->remote_port;
|
||||
os_memmove (pesp_conn->proto.udp->remote_ip, pr->remote_ip, 4);
|
||||
// The remot_info apparently should *not* be os_free()d, fyi
|
||||
memmove (pesp_conn->proto.udp->remote_ip, pr->remote_ip, 4);
|
||||
// The remot_info apparently should *not* be free()d, fyi
|
||||
|
||||
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)
|
||||
|
@ -85,7 +85,7 @@ static int coap_create( lua_State* L, const char* mt )
|
|||
lua_setmetatable(L, -2);
|
||||
|
||||
// create the espconn struct
|
||||
pesp_conn = (struct espconn *)c_zalloc(sizeof(struct espconn));
|
||||
pesp_conn = (struct espconn *)zalloc(sizeof(struct espconn));
|
||||
if(!pesp_conn)
|
||||
return luaL_error(L, "not enough memory");
|
||||
|
||||
|
@ -95,9 +95,9 @@ static int coap_create( lua_State* L, const char* mt )
|
|||
pesp_conn->proto.tcp = 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){
|
||||
c_free(pesp_conn);
|
||||
free(pesp_conn);
|
||||
cud->pesp_conn = pesp_conn = NULL;
|
||||
return luaL_error(L, "not enough memory");
|
||||
}
|
||||
|
@ -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)
|
||||
espconn_delete(cud->pesp_conn);
|
||||
c_free(cud->pesp_conn->proto.udp);
|
||||
free(cud->pesp_conn->proto.udp);
|
||||
cud->pesp_conn->proto.udp = NULL;
|
||||
c_free(cud->pesp_conn);
|
||||
free(cud->pesp_conn);
|
||||
cud->pesp_conn = NULL;
|
||||
}
|
||||
|
||||
|
@ -174,7 +174,7 @@ static int coap_start( lua_State* L, const char* mt )
|
|||
ip = "0.0.0.0";
|
||||
}
|
||||
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(IPSTR, IP2STR(&ipaddr.addr));
|
||||
NODE_DBG("\n");
|
||||
|
@ -239,7 +239,7 @@ static void coap_response_handler(void *arg, char *pdata, unsigned short len)
|
|||
pkt.content.len = 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'
|
||||
c_memset(buf, 0, sizeof(buf)); // wipe prev data
|
||||
memset(buf, 0, sizeof(buf)); // wipe prev data
|
||||
|
||||
int rc;
|
||||
if( len > MAX_MESSAGE_SIZE )
|
||||
|
@ -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...
|
||||
return;
|
||||
}
|
||||
c_memcpy(buf, pdata, len);
|
||||
memcpy(buf, pdata, len);
|
||||
|
||||
if (0 != (rc = coap_parse(&pkt, buf, len))){
|
||||
NODE_DBG("Bad packet rc=%d\n", rc);
|
||||
|
@ -275,7 +275,7 @@ static void coap_response_handler(void *arg, char *pdata, unsigned short len)
|
|||
uint32_t ip = 0, port = 0;
|
||||
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;
|
||||
|
||||
coap_transaction_id(ip, port, &pkt, &id);
|
||||
|
@ -307,7 +307,7 @@ end:
|
|||
if(pesp_conn->proto.udp->remote_port || pesp_conn->proto.udp->local_port)
|
||||
espconn_delete(pesp_conn);
|
||||
}
|
||||
// c_memset(buf, 0, sizeof(buf));
|
||||
// memset(buf, 0, sizeof(buf));
|
||||
}
|
||||
|
||||
// Lua: client:request( [CON], uri, [payload] )
|
||||
|
@ -358,7 +358,7 @@ static int coap_request( lua_State* L, coap_method_t m )
|
|||
pesp_conn->proto.udp->local_port = espconn_port();
|
||||
|
||||
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';
|
||||
|
||||
ipaddr.addr = ipaddr_addr(host);
|
||||
|
@ -366,7 +366,7 @@ static int coap_request( lua_State* L, coap_method_t m )
|
|||
NODE_DBG(host);
|
||||
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(IPSTR, IP2STR(&ipaddr.addr));
|
||||
NODE_DBG("\n");
|
||||
|
@ -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
|
||||
if(!pdu){
|
||||
if(uri)
|
||||
c_free(uri);
|
||||
free(uri);
|
||||
return luaL_error (L, "alloc fail");
|
||||
}
|
||||
|
||||
|
@ -426,7 +426,7 @@ static int coap_request( lua_State* L, coap_method_t m )
|
|||
}
|
||||
|
||||
if(uri)
|
||||
c_free((void *)uri);
|
||||
free((void *)uri);
|
||||
|
||||
NODE_DBG("coap_request is called.\n");
|
||||
return 0;
|
||||
|
@ -451,13 +451,13 @@ static int coap_regist( lua_State* L, const char* mt, int isvar )
|
|||
h = function_entry;
|
||||
|
||||
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;
|
||||
h = h->next;
|
||||
}
|
||||
|
||||
if(h->name==NULL || c_strcmp(h->name, name)!=0){ // not exists. make a new one.
|
||||
h->next = (coap_luser_entry *)c_zalloc(sizeof(coap_luser_entry));
|
||||
if(h->name==NULL || strcmp(h->name, name)!=0){ // not exists. make a new one.
|
||||
h->next = (coap_luser_entry *)zalloc(sizeof(coap_luser_entry));
|
||||
h = h->next;
|
||||
if(h == NULL)
|
||||
return luaL_error(L, "not enough memory");
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
// Module for cryptography
|
||||
|
||||
#include <c_errno.h>
|
||||
#include <errno.h>
|
||||
#include "module.h"
|
||||
#include "lauxlib.h"
|
||||
#include "platform.h"
|
||||
#include "c_types.h"
|
||||
#include "c_stdlib.h"
|
||||
#include <stdlib.h>
|
||||
#include "flash_fs.h"
|
||||
#include "../crypto/digests.h"
|
||||
#include "../crypto/mech.h"
|
||||
|
@ -71,7 +71,7 @@ static int crypto_base64_encode( lua_State* L )
|
|||
int len;
|
||||
const char* msg = luaL_checklstring(L, 1, &len);
|
||||
int blen = (len + 2) / 3 * 4;
|
||||
char* out = (char*)c_malloc(blen);
|
||||
char* out = (char*)malloc(blen);
|
||||
int j = 0, i;
|
||||
for (i = 0; i < len; i += 3) {
|
||||
int a = msg[i];
|
||||
|
@ -83,7 +83,7 @@ static int crypto_base64_encode( lua_State* L )
|
|||
out[j++] = (i + 2 < len) ? bytes64[(c & 63)] : 61;
|
||||
}
|
||||
lua_pushlstring(L, out, j);
|
||||
c_free(out);
|
||||
free(out);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -96,14 +96,14 @@ static int crypto_hex_encode( lua_State* L)
|
|||
{
|
||||
int 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;
|
||||
for (i = 0; i < len; i++) {
|
||||
out[j++] = crypto_hexbytes[msg[i] >> 4];
|
||||
out[j++] = crypto_hexbytes[msg[i] & 0xf];
|
||||
}
|
||||
lua_pushlstring(L, out, len*2);
|
||||
c_free(out);
|
||||
free(out);
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
@ -118,12 +118,12 @@ static int crypto_mask( lua_State* L )
|
|||
const char* msg = luaL_checklstring(L, 1, &len);
|
||||
const char* mask = luaL_checklstring(L, 2, &mask_len);
|
||||
int i;
|
||||
char* copy = (char*)c_malloc(len);
|
||||
char* copy = (char*)malloc(len);
|
||||
for (i = 0; i < len; i++) {
|
||||
copy[i] = msg[i] ^ mask[i % 4];
|
||||
}
|
||||
lua_pushlstring(L, copy, len);
|
||||
c_free(copy);
|
||||
free(copy);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -169,7 +169,7 @@ static int crypto_new_hash (lua_State *L)
|
|||
if (!mi)
|
||||
return bad_mech (L);
|
||||
|
||||
void *ctx = os_malloc (mi->ctx_size);
|
||||
void *ctx = malloc (mi->ctx_size);
|
||||
if (ctx==NULL)
|
||||
return bad_mem (L);
|
||||
|
||||
|
@ -237,7 +237,7 @@ static int crypto_hash_gcdelete (lua_State *L)
|
|||
dudat = (digest_user_datum_t *)luaL_checkudata(L, 1, "crypto.hash");
|
||||
luaL_argcheck(L, dudat, 1, "crypto.hash expected");
|
||||
|
||||
os_free(dudat->ctx);
|
||||
free(dudat->ctx);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -325,7 +325,7 @@ static int crypto_encdec (lua_State *L, bool enc)
|
|||
|
||||
size_t bs = mech->block_size;
|
||||
size_t outlen = ((dlen + bs -1) / bs) * bs;
|
||||
char *buf = (char *)os_zalloc (outlen);
|
||||
char *buf = (char *)zalloc (outlen);
|
||||
if (!buf)
|
||||
return luaL_error (L, "crypto init failed");
|
||||
|
||||
|
@ -339,14 +339,14 @@ static int crypto_encdec (lua_State *L, bool enc)
|
|||
};
|
||||
if (!mech->run (&op))
|
||||
{
|
||||
os_free (buf);
|
||||
free (buf);
|
||||
return luaL_error (L, "crypto op failed");
|
||||
}
|
||||
else
|
||||
{
|
||||
lua_pushlstring (L, buf, outlen);
|
||||
// note: if lua_pushlstring runs out of memory, we leak buf :(
|
||||
os_free (buf);
|
||||
free (buf);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,8 @@
|
|||
#include "module.h"
|
||||
#include "lauxlib.h"
|
||||
#include "lmem.h"
|
||||
#include "c_string.h"
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#define BASE64_INVALID '\xff'
|
||||
#define BASE64_PADDING '='
|
||||
#define ISBASE64(c) (unbytes64[c] != BASE64_INVALID)
|
||||
|
@ -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 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) {
|
||||
int a = msg[i];
|
||||
|
@ -44,7 +45,7 @@ static uint8 *fromBase64 ( lua_State* L, const uint8 *enc_msg, size_t *len){
|
|||
if (n & 3)
|
||||
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
|
||||
|
||||
if (enc_msg[n-1] == BASE64_PADDING) {
|
||||
|
|
|
@ -39,14 +39,16 @@
|
|||
#include "lwip/pbuf.h"
|
||||
#include "lmem.h"
|
||||
#include "platform.h"
|
||||
#include "c_stdlib.h"
|
||||
#include "c_stdio.h"
|
||||
#include "c_string.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "ctype.h"
|
||||
#include "espconn.h"
|
||||
#include "flash_fs.h"
|
||||
#include "task/task.h"
|
||||
#include "esp_wifi.h"
|
||||
#include "esp_sta.h"
|
||||
#include "esp_softap.h"
|
||||
|
||||
#define MIN(x, y) (((x) < (y)) ? (x) : (y))
|
||||
#define LITLEN(strliteral) (sizeof (strliteral) -1)
|
||||
|
@ -366,7 +368,7 @@ static void enduser_setup_check_station(void *p)
|
|||
|
||||
(void)p;
|
||||
struct ip_info ip;
|
||||
c_memset(&ip, 0, sizeof(struct ip_info));
|
||||
memset(&ip, 0, sizeof(struct ip_info));
|
||||
|
||||
wifi_get_ip_info(STATION_IF, &ip);
|
||||
|
||||
|
@ -499,33 +501,33 @@ static int enduser_setup_http_load_payload(void)
|
|||
|
||||
int payload_len = LITLEN(http_header_200) + cl_len + LITLEN(http_html_backup);
|
||||
state->http_payload_len = payload_len;
|
||||
state->http_payload_data = (char *) c_malloc(payload_len);
|
||||
state->http_payload_data = (char *) malloc(payload_len);
|
||||
if (state->http_payload_data == NULL)
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
int offset = 0;
|
||||
c_memcpy(&(state->http_payload_data[offset]), &(http_header_200), LITLEN(http_header_200));
|
||||
memcpy(&(state->http_payload_data[offset]), &(http_header_200), LITLEN(http_header_200));
|
||||
offset += LITLEN(http_header_200);
|
||||
offset += c_sprintf(state->http_payload_data + offset, cl_hdr, LITLEN(http_html_backup));
|
||||
c_memcpy(&(state->http_payload_data[offset]), &(http_html_backup), LITLEN(http_html_backup));
|
||||
offset += sprintf(state->http_payload_data + offset, cl_hdr, LITLEN(http_html_backup));
|
||||
memcpy(&(state->http_payload_data[offset]), &(http_html_backup), LITLEN(http_html_backup));
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int payload_len = LITLEN(http_header_200) + cl_len + file_len;
|
||||
state->http_payload_len = payload_len;
|
||||
state->http_payload_data = (char *) c_malloc(payload_len);
|
||||
state->http_payload_data = (char *) malloc(payload_len);
|
||||
if (state->http_payload_data == NULL)
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
int offset = 0;
|
||||
c_memcpy(&(state->http_payload_data[offset]), &(http_header_200), LITLEN(http_header_200));
|
||||
memcpy(&(state->http_payload_data[offset]), &(http_header_200), LITLEN(http_header_200));
|
||||
offset += LITLEN(http_header_200);
|
||||
offset += c_sprintf(state->http_payload_data + offset, cl_hdr, file_len);
|
||||
offset += sprintf(state->http_payload_data + offset, cl_hdr, file_len);
|
||||
fs_read(f, &(state->http_payload_data[offset]), file_len);
|
||||
|
||||
return 0;
|
||||
|
@ -652,7 +654,7 @@ static int enduser_setup_http_handle_credentials(char *data, unsigned short data
|
|||
|
||||
|
||||
struct station_config *cnf = luaM_malloc(lua_getstate(), sizeof(struct station_config));
|
||||
c_memset(cnf, 0, sizeof(struct station_config));
|
||||
memset(cnf, 0, sizeof(struct station_config));
|
||||
|
||||
int err;
|
||||
err = enduser_setup_http_urldecode(cnf->ssid, name_str_start, name_str_len, sizeof(cnf->ssid));
|
||||
|
@ -806,17 +808,17 @@ static void serve_status(struct tcp_pcb *conn)
|
|||
wifi_station_get_config(&config);
|
||||
config.ssid[31] = '\0';
|
||||
|
||||
int state_len = c_strlen(s);
|
||||
int ssid_len = c_strlen(config.ssid);
|
||||
int state_len = strlen(s);
|
||||
int ssid_len = strlen(config.ssid);
|
||||
int status_len = state_len + ssid_len + 1;
|
||||
char status_buf[status_len];
|
||||
memset(status_buf, 0, status_len);
|
||||
status_len = c_sprintf(status_buf, s, config.ssid);
|
||||
status_len = sprintf(status_buf, s, config.ssid);
|
||||
|
||||
int buf_len = sizeof(fmt) + status_len + 10; //10 = (9+1), 1 byte is '\0' and 9 are reserved for length field
|
||||
char buf[buf_len];
|
||||
memset(buf, 0, buf_len);
|
||||
int output_len = c_sprintf(buf, fmt, status_len, status_buf);
|
||||
int output_len = sprintf(buf, fmt, status_len, status_buf);
|
||||
|
||||
enduser_setup_http_serve_header(conn, buf, output_len);
|
||||
}
|
||||
|
@ -826,11 +828,11 @@ static void serve_status(struct tcp_pcb *conn)
|
|||
default:
|
||||
{
|
||||
const char *s = state[curr_state];
|
||||
int status_len = c_strlen(s);
|
||||
int status_len = strlen(s);
|
||||
int buf_len = sizeof(fmt) + status_len + 10; //10 = (9+1), 1 byte is '\0' and 9 are reserved for length field
|
||||
char buf[buf_len];
|
||||
memset(buf, 0, buf_len);
|
||||
int output_len = c_sprintf(buf, fmt, status_len, s);
|
||||
int output_len = sprintf(buf, fmt, status_len, s);
|
||||
|
||||
enduser_setup_http_serve_header(conn, buf, output_len);
|
||||
}
|
||||
|
@ -858,7 +860,7 @@ static void free_scan_listeners (void)
|
|||
while (l)
|
||||
{
|
||||
next = l->next;
|
||||
c_free (l);
|
||||
free (l);
|
||||
l = next;
|
||||
}
|
||||
state->scan_listeners = 0;
|
||||
|
@ -876,7 +878,7 @@ static void remove_scan_listener (scan_listener_t *l)
|
|||
if (*sl == l)
|
||||
{
|
||||
*sl = l->next;
|
||||
c_free (l);
|
||||
free (l);
|
||||
/* No early exit to guard against multi-entry on list */
|
||||
}
|
||||
else
|
||||
|
@ -950,7 +952,7 @@ static void on_scan_done (void *arg, STATUS status)
|
|||
/* To be able to safely escape a pathological SSID, we need 2*32 bytes */
|
||||
const size_t max_entry_sz = sizeof("{\"ssid\":\"\",\"rssi\":},") + 2*32 + 6;
|
||||
const size_t alloc_sz = hdr_sz + num_nets * max_entry_sz + 3;
|
||||
char *http = os_zalloc (alloc_sz);
|
||||
char *http = zalloc (alloc_sz);
|
||||
if (!http)
|
||||
{
|
||||
goto serve_500;
|
||||
|
@ -976,18 +978,18 @@ static void on_scan_done (void *arg, STATUS status)
|
|||
strcpy (p, entry_mid);
|
||||
p += sizeof (entry_mid) -1;
|
||||
|
||||
p += c_sprintf (p, "%d", wn->rssi);
|
||||
p += sprintf (p, "%d", wn->rssi);
|
||||
|
||||
*p++ = '}';
|
||||
}
|
||||
*p++ = ']';
|
||||
|
||||
size_t body_sz = (p - http) - hdr_sz;
|
||||
c_sprintf (http, header_fmt, body_sz);
|
||||
sprintf (http, header_fmt, body_sz);
|
||||
http[hdr_sz] = '['; /* Rewrite the \0 with the correct start of body */
|
||||
|
||||
notify_scan_listeners (http, hdr_sz + body_sz);
|
||||
c_free (http);
|
||||
free (http);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1020,7 +1022,7 @@ static err_t enduser_setup_http_recvcb(void *arg, struct tcp_pcb *http_client, s
|
|||
return ERR_OK;
|
||||
}
|
||||
|
||||
char *data = os_zalloc (p->tot_len + 1);
|
||||
char *data = zalloc (p->tot_len + 1);
|
||||
if (!data)
|
||||
return ERR_MEM;
|
||||
|
||||
|
@ -1029,9 +1031,9 @@ static err_t enduser_setup_http_recvcb(void *arg, struct tcp_pcb *http_client, s
|
|||
pbuf_free (p);
|
||||
|
||||
err_t ret = ERR_OK;
|
||||
if (c_strncmp(data, "GET ", 4) == 0)
|
||||
if (strncmp(data, "GET ", 4) == 0)
|
||||
{
|
||||
if (c_strncmp(data + 4, "/ ", 2) == 0)
|
||||
if (strncmp(data + 4, "/ ", 2) == 0)
|
||||
{
|
||||
if (enduser_setup_http_serve_html(http_client) != 0)
|
||||
{
|
||||
|
@ -1042,9 +1044,9 @@ static err_t enduser_setup_http_recvcb(void *arg, struct tcp_pcb *http_client, s
|
|||
goto free_out; /* streaming now in progress */
|
||||
}
|
||||
}
|
||||
else if (c_strncmp(data + 4, "/aplist ", 8) == 0)
|
||||
else if (strncmp(data + 4, "/aplist ", 8) == 0)
|
||||
{
|
||||
scan_listener_t *l = os_malloc (sizeof (scan_listener_t));
|
||||
scan_listener_t *l = malloc (sizeof (scan_listener_t));
|
||||
if (!l)
|
||||
{
|
||||
ENDUSER_SETUP_ERROR("out of memory", ENDUSER_SETUP_ERR_OUT_OF_MEMORY, ENDUSER_SETUP_ERR_NONFATAL);
|
||||
|
@ -1070,11 +1072,11 @@ static err_t enduser_setup_http_recvcb(void *arg, struct tcp_pcb *http_client, s
|
|||
}
|
||||
goto free_out; /* request queued */
|
||||
}
|
||||
else if (c_strncmp(data + 4, "/status ", 8) == 0)
|
||||
else if (strncmp(data + 4, "/status ", 8) == 0)
|
||||
{
|
||||
serve_status(http_client);
|
||||
}
|
||||
else if (c_strncmp(data + 4, "/update?", 8) == 0)
|
||||
else if (strncmp(data + 4, "/update?", 8) == 0)
|
||||
{
|
||||
switch (enduser_setup_http_handle_credentials(data, data_len))
|
||||
{
|
||||
|
@ -1089,7 +1091,7 @@ static err_t enduser_setup_http_recvcb(void *arg, struct tcp_pcb *http_client, s
|
|||
break;
|
||||
}
|
||||
}
|
||||
else if (c_strncmp(data + 4, "/generate_204 ", 14) == 0)
|
||||
else if (strncmp(data + 4, "/generate_204 ", 14) == 0)
|
||||
{
|
||||
/* Convince Android devices that they have internet access to avoid pesky dialogues. */
|
||||
enduser_setup_http_serve_header(http_client, http_header_204, LITLEN(http_header_204));
|
||||
|
@ -1109,7 +1111,7 @@ static err_t enduser_setup_http_recvcb(void *arg, struct tcp_pcb *http_client, s
|
|||
deferred_close (http_client);
|
||||
|
||||
free_out:
|
||||
os_free (data);
|
||||
free (data);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -1200,20 +1202,20 @@ static void enduser_setup_ap_start(void)
|
|||
ENDUSER_SETUP_DEBUG("enduser_setup_ap_start");
|
||||
|
||||
struct softap_config cnf;
|
||||
c_memset(&(cnf), 0, sizeof(struct softap_config));
|
||||
memset(&(cnf), 0, sizeof(struct softap_config));
|
||||
|
||||
#ifndef ENDUSER_SETUP_AP_SSID
|
||||
#define ENDUSER_SETUP_AP_SSID "SetupGadget"
|
||||
#endif
|
||||
|
||||
char ssid[] = ENDUSER_SETUP_AP_SSID;
|
||||
int ssid_name_len = c_strlen(ssid);
|
||||
c_memcpy(&(cnf.ssid), ssid, ssid_name_len);
|
||||
int ssid_name_len = strlen(ssid);
|
||||
memcpy(&(cnf.ssid), ssid, ssid_name_len);
|
||||
|
||||
uint8_t mac[6];
|
||||
wifi_get_macaddr(SOFTAP_IF, mac);
|
||||
cnf.ssid[ssid_name_len] = '_';
|
||||
c_sprintf(cnf.ssid + ssid_name_len + 1, "%02X%02X%02X", mac[3], mac[4], mac[5]);
|
||||
sprintf(cnf.ssid + ssid_name_len + 1, "%02X%02X%02X", mac[3], mac[4], mac[5]);
|
||||
cnf.ssid_len = ssid_name_len + 7;
|
||||
cnf.channel = 1;
|
||||
cnf.authmode = AUTH_OPEN;
|
||||
|
@ -1232,7 +1234,7 @@ static void enduser_setup_dns_recv_callback(void *arg, char *recv_data, unsigned
|
|||
struct espconn *callback_espconn = arg;
|
||||
struct ip_info ip_info;
|
||||
|
||||
uint32_t qname_len = c_strlen(&(recv_data[12])) + 1; // \0=1byte
|
||||
uint32_t qname_len = strlen(&(recv_data[12])) + 1; // \0=1byte
|
||||
uint32_t dns_reply_static_len = (uint32_t) sizeof(dns_header) + (uint32_t) sizeof(dns_body) + 2 + 4; // dns_id=2bytes, ip=4bytes
|
||||
uint32_t dns_reply_len = dns_reply_static_len + qname_len;
|
||||
|
||||
|
@ -1249,22 +1251,22 @@ static void enduser_setup_dns_recv_callback(void *arg, char *recv_data, unsigned
|
|||
}
|
||||
|
||||
|
||||
char *dns_reply = (char *) c_malloc(dns_reply_len);
|
||||
char *dns_reply = (char *) malloc(dns_reply_len);
|
||||
if (dns_reply == NULL)
|
||||
{
|
||||
ENDUSER_SETUP_ERROR_VOID("dns_recv_callback failed. Failed to allocate memory.", ENDUSER_SETUP_ERR_OUT_OF_MEMORY, ENDUSER_SETUP_ERR_NONFATAL);
|
||||
}
|
||||
|
||||
uint32_t insert_byte = 0;
|
||||
c_memcpy(&(dns_reply[insert_byte]), recv_data, 2);
|
||||
memcpy(&(dns_reply[insert_byte]), recv_data, 2);
|
||||
insert_byte += 2;
|
||||
c_memcpy(&(dns_reply[insert_byte]), dns_header, sizeof(dns_header));
|
||||
memcpy(&(dns_reply[insert_byte]), dns_header, sizeof(dns_header));
|
||||
insert_byte += (uint32_t) sizeof(dns_header);
|
||||
c_memcpy(&(dns_reply[insert_byte]), &(recv_data[12]), qname_len);
|
||||
memcpy(&(dns_reply[insert_byte]), &(recv_data[12]), qname_len);
|
||||
insert_byte += qname_len;
|
||||
c_memcpy(&(dns_reply[insert_byte]), dns_body, sizeof(dns_body));
|
||||
memcpy(&(dns_reply[insert_byte]), dns_body, sizeof(dns_body));
|
||||
insert_byte += (uint32_t) sizeof(dns_body);
|
||||
c_memcpy(&(dns_reply[insert_byte]), &(ip_info.ip), 4);
|
||||
memcpy(&(dns_reply[insert_byte]), &(ip_info.ip), 4);
|
||||
|
||||
// SDK 1.4.0 changed behaviour, for UDP server need to look up remote ip/port
|
||||
remot_info *pr = 0;
|
||||
|
@ -1273,11 +1275,11 @@ static void enduser_setup_dns_recv_callback(void *arg, char *recv_data, unsigned
|
|||
ENDUSER_SETUP_ERROR_VOID("dns_recv_callback failed. Unable to get IP of UDP sender.", ENDUSER_SETUP_ERR_CONNECTION_NOT_FOUND, ENDUSER_SETUP_ERR_FATAL);
|
||||
}
|
||||
callback_espconn->proto.udp->remote_port = pr->remote_port;
|
||||
os_memmove(callback_espconn->proto.udp->remote_ip, pr->remote_ip, 4);
|
||||
memmove(callback_espconn->proto.udp->remote_ip, pr->remote_ip, 4);
|
||||
|
||||
int8_t err;
|
||||
err = espconn_send(callback_espconn, dns_reply, dns_reply_len);
|
||||
c_free(dns_reply);
|
||||
free(dns_reply);
|
||||
if (err == ESPCONN_MEM)
|
||||
{
|
||||
ENDUSER_SETUP_ERROR_VOID("dns_recv_callback failed. Failed to allocate memory for send.", ENDUSER_SETUP_ERR_OUT_OF_MEMORY, ENDUSER_SETUP_ERR_FATAL);
|
||||
|
@ -1310,16 +1312,16 @@ static void enduser_setup_free(void)
|
|||
{
|
||||
if (state->espconn_dns_udp->proto.udp != NULL)
|
||||
{
|
||||
c_free(state->espconn_dns_udp->proto.udp);
|
||||
free(state->espconn_dns_udp->proto.udp);
|
||||
}
|
||||
c_free(state->espconn_dns_udp);
|
||||
free(state->espconn_dns_udp);
|
||||
}
|
||||
|
||||
c_free(state->http_payload_data);
|
||||
free(state->http_payload_data);
|
||||
|
||||
free_scan_listeners ();
|
||||
|
||||
c_free(state);
|
||||
free(state);
|
||||
state = NULL;
|
||||
}
|
||||
|
||||
|
@ -1332,20 +1334,20 @@ static int enduser_setup_dns_start(void)
|
|||
{
|
||||
ENDUSER_SETUP_ERROR("dns_start failed. Appears to already be started (espconn_dns_udp != NULL).", ENDUSER_SETUP_ERR_UNKOWN_ERROR, ENDUSER_SETUP_ERR_FATAL);
|
||||
}
|
||||
state->espconn_dns_udp = (struct espconn *) c_malloc(sizeof(struct espconn));
|
||||
state->espconn_dns_udp = (struct espconn *) malloc(sizeof(struct espconn));
|
||||
if (state->espconn_dns_udp == NULL)
|
||||
{
|
||||
ENDUSER_SETUP_ERROR("dns_start failed. Memory allocation failed (espconn_dns_udp == NULL).", ENDUSER_SETUP_ERR_OUT_OF_MEMORY, ENDUSER_SETUP_ERR_FATAL);
|
||||
}
|
||||
|
||||
esp_udp *esp_udp_data = (esp_udp *) c_malloc(sizeof(esp_udp));
|
||||
esp_udp *esp_udp_data = (esp_udp *) malloc(sizeof(esp_udp));
|
||||
if (esp_udp_data == NULL)
|
||||
{
|
||||
ENDUSER_SETUP_ERROR("dns_start failed. Memory allocation failed (esp_udp == NULL).", ENDUSER_SETUP_ERR_OUT_OF_MEMORY, ENDUSER_SETUP_ERR_FATAL);
|
||||
}
|
||||
|
||||
c_memset(state->espconn_dns_udp, 0, sizeof(struct espconn));
|
||||
c_memset(esp_udp_data, 0, sizeof(esp_udp));
|
||||
memset(state->espconn_dns_udp, 0, sizeof(struct espconn));
|
||||
memset(esp_udp_data, 0, sizeof(esp_udp));
|
||||
state->espconn_dns_udp->proto.udp = esp_udp_data;
|
||||
state->espconn_dns_udp->type = ESPCONN_UDP;
|
||||
state->espconn_dns_udp->state = ESPCONN_NONE;
|
||||
|
@ -1397,13 +1399,13 @@ static int enduser_setup_init(lua_State *L)
|
|||
return ENDUSER_SETUP_ERR_UNKOWN_ERROR;
|
||||
}
|
||||
|
||||
state = (enduser_setup_state_t *) os_zalloc(sizeof(enduser_setup_state_t));
|
||||
state = (enduser_setup_state_t *) zalloc(sizeof(enduser_setup_state_t));
|
||||
if (state == NULL)
|
||||
{
|
||||
ENDUSER_SETUP_ERROR("init failed. Unable to allocate memory.", ENDUSER_SETUP_ERR_OUT_OF_MEMORY, ENDUSER_SETUP_ERR_FATAL);
|
||||
return ENDUSER_SETUP_ERR_OUT_OF_MEMORY;
|
||||
}
|
||||
c_memset(state, 0, sizeof(enduser_setup_state_t));
|
||||
memset(state, 0, sizeof(enduser_setup_state_t));
|
||||
|
||||
state->lua_connected_cb_ref = LUA_NOREF;
|
||||
state->lua_err_cb_ref = LUA_NOREF;
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
#include "c_types.h"
|
||||
#include "flash_fs.h"
|
||||
#include "c_string.h"
|
||||
#include <string.h>
|
||||
|
||||
static volatile int file_fd = FS_OPEN_OK - 1;
|
||||
|
||||
|
@ -20,7 +20,7 @@ static int file_open( lua_State* L )
|
|||
}
|
||||
|
||||
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");
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
#include "platform.h"
|
||||
#include "user_interface.h"
|
||||
#include "c_types.h"
|
||||
#include "c_string.h"
|
||||
#include <string.h>
|
||||
#include "gpio.h"
|
||||
|
||||
#undef INTERRUPT
|
||||
|
|
|
@ -14,13 +14,13 @@ static int http_callback_registry = LUA_NOREF;
|
|||
static void http_callback( char * response, int http_status, char * full_response )
|
||||
{
|
||||
#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 (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
|
||||
if (http_callback_registry != LUA_NOREF)
|
||||
|
|
|
@ -4,8 +4,8 @@
|
|||
#include "module.h"
|
||||
#include "lauxlib.h"
|
||||
#include "platform.h"
|
||||
#include "c_stdlib.h"
|
||||
#include "c_string.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "user_interface.h"
|
||||
#include "esp_system.h"
|
||||
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
#include "module.h"
|
||||
#include "lauxlib.h"
|
||||
|
||||
#include "c_string.h"
|
||||
#include "c_stdlib.h"
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "c_types.h"
|
||||
#include "mem.h"
|
||||
|
@ -43,16 +43,16 @@ static int mdns_register(lua_State *L)
|
|||
luaL_checktype(L, -2, LUA_TSTRING);
|
||||
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);
|
||||
} else if (c_strcmp(key, "service") == 0) {
|
||||
} else if (strcmp(key, "service") == 0) {
|
||||
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);
|
||||
} else {
|
||||
int len = c_strlen(key) + 1;
|
||||
int len = strlen(key) + 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);
|
||||
strcat(p, "=");
|
||||
strcat(p, value);
|
||||
|
|
|
@ -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 "mem.h"
|
||||
|
@ -121,9 +121,9 @@ static void mqtt_socket_disconnected(void *arg) // tcp only
|
|||
if(mud->pesp_conn){
|
||||
mud->pesp_conn->reverse = NULL;
|
||||
if(mud->pesp_conn->proto.tcp)
|
||||
c_free(mud->pesp_conn->proto.tcp);
|
||||
free(mud->pesp_conn->proto.tcp);
|
||||
mud->pesp_conn->proto.tcp = NULL;
|
||||
c_free(mud->pesp_conn);
|
||||
free(mud->pesp_conn);
|
||||
mud->pesp_conn = NULL;
|
||||
}
|
||||
|
||||
|
@ -270,7 +270,7 @@ READPACKET:
|
|||
if(length > MQTT_BUF_SIZE || length <= 0)
|
||||
return;
|
||||
|
||||
// c_memcpy(in_buffer, pdata, length);
|
||||
// memcpy(in_buffer, pdata, length);
|
||||
uint8_t temp_buffer[MQTT_BUF_SIZE];
|
||||
mqtt_msg_init(&mud->mqtt_state.mqtt_connection, temp_buffer, MQTT_BUF_SIZE);
|
||||
mqtt_message_t *temp_msg = NULL;
|
||||
|
@ -654,12 +654,12 @@ static int mqtt_socket_client( lua_State* L )
|
|||
|
||||
lmqtt_userdata *mud;
|
||||
char tempid[20] = {0};
|
||||
c_sprintf(tempid, "%s%x", "NodeMCU_", system_get_chip_id() );
|
||||
sprintf(tempid, "%s%x", "NodeMCU_", system_get_chip_id() );
|
||||
NODE_DBG(tempid);
|
||||
NODE_DBG("\n");
|
||||
|
||||
const char *clientId = tempid, *username = NULL, *password = NULL;
|
||||
size_t idl = c_strlen(tempid);
|
||||
size_t idl = strlen(tempid);
|
||||
size_t unl = 0, pwl = 0;
|
||||
int keepalive = 0;
|
||||
int stack = 1;
|
||||
|
@ -687,9 +687,9 @@ static int mqtt_socket_client( lua_State* L )
|
|||
mud->event_timeout = 0;
|
||||
mud->connState = MQTT_INIT;
|
||||
mud->connected = false;
|
||||
c_memset(&mud->mqttTimer, 0, sizeof(ETSTimer));
|
||||
c_memset(&mud->mqtt_state, 0, sizeof(mqtt_state_t));
|
||||
c_memset(&mud->connect_info, 0, sizeof(mqtt_connect_info_t));
|
||||
memset(&mud->mqttTimer, 0, sizeof(ETSTimer));
|
||||
memset(&mud->mqtt_state, 0, sizeof(mqtt_state_t));
|
||||
memset(&mud->connect_info, 0, sizeof(mqtt_connect_info_t));
|
||||
|
||||
// set its metatable
|
||||
luaL_getmetatable(L, "mqtt.socket");
|
||||
|
@ -738,30 +738,30 @@ static int mqtt_socket_client( lua_State* L )
|
|||
}
|
||||
|
||||
// TODO: check the zalloc result.
|
||||
mud->connect_info.client_id = (uint8_t *)c_zalloc(idl+1);
|
||||
mud->connect_info.username = (uint8_t *)c_zalloc(unl + 1);
|
||||
mud->connect_info.password = (uint8_t *)c_zalloc(pwl + 1);
|
||||
mud->connect_info.client_id = (uint8_t *)zalloc(idl+1);
|
||||
mud->connect_info.username = (uint8_t *)zalloc(unl + 1);
|
||||
mud->connect_info.password = (uint8_t *)zalloc(pwl + 1);
|
||||
if(!mud->connect_info.client_id || !mud->connect_info.username || !mud->connect_info.password){
|
||||
if(mud->connect_info.client_id) {
|
||||
c_free(mud->connect_info.client_id);
|
||||
free(mud->connect_info.client_id);
|
||||
mud->connect_info.client_id = NULL;
|
||||
}
|
||||
if(mud->connect_info.username) {
|
||||
c_free(mud->connect_info.username);
|
||||
free(mud->connect_info.username);
|
||||
mud->connect_info.username = NULL;
|
||||
}
|
||||
if(mud->connect_info.password) {
|
||||
c_free(mud->connect_info.password);
|
||||
free(mud->connect_info.password);
|
||||
mud->connect_info.password = NULL;
|
||||
}
|
||||
return luaL_error(L, "not enough memory");
|
||||
}
|
||||
|
||||
c_memcpy(mud->connect_info.client_id, clientId, idl);
|
||||
memcpy(mud->connect_info.client_id, clientId, idl);
|
||||
mud->connect_info.client_id[idl] = 0;
|
||||
c_memcpy(mud->connect_info.username, username, unl);
|
||||
memcpy(mud->connect_info.username, username, unl);
|
||||
mud->connect_info.username[unl] = 0;
|
||||
c_memcpy(mud->connect_info.password, password, pwl);
|
||||
memcpy(mud->connect_info.password, password, pwl);
|
||||
mud->connect_info.password[pwl] = 0;
|
||||
|
||||
NODE_DBG("MQTT: Init info: %s, %s, %s\r\n", mud->connect_info.client_id, mud->connect_info.username, mud->connect_info.password);
|
||||
|
@ -801,35 +801,35 @@ static int mqtt_delete( lua_State* L )
|
|||
if(mud->pesp_conn){ // for client connected to tcp server, this should set NULL in disconnect cb
|
||||
mud->pesp_conn->reverse = NULL;
|
||||
if(mud->pesp_conn->proto.tcp)
|
||||
c_free(mud->pesp_conn->proto.tcp);
|
||||
free(mud->pesp_conn->proto.tcp);
|
||||
mud->pesp_conn->proto.tcp = NULL;
|
||||
c_free(mud->pesp_conn);
|
||||
free(mud->pesp_conn);
|
||||
mud->pesp_conn = NULL; // for socket, it will free this when disconnected
|
||||
}
|
||||
|
||||
// ---- alloc-ed in mqtt_socket_lwt()
|
||||
if(mud->connect_info.will_topic){
|
||||
c_free(mud->connect_info.will_topic);
|
||||
free(mud->connect_info.will_topic);
|
||||
mud->connect_info.will_topic = NULL;
|
||||
}
|
||||
|
||||
if(mud->connect_info.will_message){
|
||||
c_free(mud->connect_info.will_message);
|
||||
free(mud->connect_info.will_message);
|
||||
mud->connect_info.will_message = NULL;
|
||||
}
|
||||
// ----
|
||||
|
||||
//--------- alloc-ed in mqtt_socket_client()
|
||||
if(mud->connect_info.client_id){
|
||||
c_free(mud->connect_info.client_id);
|
||||
free(mud->connect_info.client_id);
|
||||
mud->connect_info.client_id = NULL;
|
||||
}
|
||||
if(mud->connect_info.username){
|
||||
c_free(mud->connect_info.username);
|
||||
free(mud->connect_info.username);
|
||||
mud->connect_info.username = NULL;
|
||||
}
|
||||
if(mud->connect_info.password){
|
||||
c_free(mud->connect_info.password);
|
||||
free(mud->connect_info.password);
|
||||
mud->connect_info.password = NULL;
|
||||
}
|
||||
// -------
|
||||
|
@ -938,7 +938,7 @@ static sint8 socket_dns_found(const char *name, ip_addr_t *ipaddr, void *arg)
|
|||
if(ipaddr->addr != 0)
|
||||
{
|
||||
dns_reconn_count = 0;
|
||||
c_memcpy(pesp_conn->proto.tcp->remote_ip, &(ipaddr->addr), 4);
|
||||
memcpy(pesp_conn->proto.tcp->remote_ip, &(ipaddr->addr), 4);
|
||||
NODE_DBG("TCP ip is set: ");
|
||||
NODE_DBG(IPSTR, IP2STR(&(ipaddr->addr)));
|
||||
NODE_DBG("\n");
|
||||
|
@ -976,21 +976,21 @@ static int mqtt_socket_connect( lua_State* L )
|
|||
if(mud->pesp_conn){ //TODO: should I free tcp struct directly or ask user to call close()???
|
||||
mud->pesp_conn->reverse = NULL;
|
||||
if(mud->pesp_conn->proto.tcp)
|
||||
c_free(mud->pesp_conn->proto.tcp);
|
||||
free(mud->pesp_conn->proto.tcp);
|
||||
mud->pesp_conn->proto.tcp = NULL;
|
||||
c_free(mud->pesp_conn);
|
||||
free(mud->pesp_conn);
|
||||
mud->pesp_conn = NULL;
|
||||
}
|
||||
|
||||
struct espconn *pesp_conn = NULL;
|
||||
pesp_conn = mud->pesp_conn = (struct espconn *)c_zalloc(sizeof(struct espconn));
|
||||
pesp_conn = mud->pesp_conn = (struct espconn *)zalloc(sizeof(struct espconn));
|
||||
if(!pesp_conn)
|
||||
return luaL_error(L, "not enough memory");
|
||||
|
||||
pesp_conn->proto.udp = NULL;
|
||||
pesp_conn->proto.tcp = (esp_tcp *)c_zalloc(sizeof(esp_tcp));
|
||||
pesp_conn->proto.tcp = (esp_tcp *)zalloc(sizeof(esp_tcp));
|
||||
if(!pesp_conn->proto.tcp){
|
||||
c_free(pesp_conn);
|
||||
free(pesp_conn);
|
||||
pesp_conn = mud->pesp_conn = NULL;
|
||||
return luaL_error(L, "not enough memory");
|
||||
}
|
||||
|
@ -1010,7 +1010,7 @@ static int mqtt_socket_connect( lua_State* L )
|
|||
domain = "127.0.0.1";
|
||||
}
|
||||
ipaddr.addr = ipaddr_addr(domain);
|
||||
c_memcpy(pesp_conn->proto.tcp->remote_ip, &ipaddr.addr, 4);
|
||||
memcpy(pesp_conn->proto.tcp->remote_ip, &ipaddr.addr, 4);
|
||||
NODE_DBG("TCP ip is set: ");
|
||||
NODE_DBG(IPSTR, IP2STR(&ipaddr.addr));
|
||||
NODE_DBG("\n");
|
||||
|
@ -1085,7 +1085,7 @@ static int mqtt_socket_connect( lua_State* L )
|
|||
os_timer_setfn(&mud->mqttTimer, (os_timer_func_t *)mqtt_socket_timer, mud);
|
||||
// timer started in socket_connect()
|
||||
|
||||
if((ipaddr.addr == IPADDR_NONE) && (c_memcmp(domain,"255.255.255.255",16) != 0))
|
||||
if((ipaddr.addr == IPADDR_NONE) && (memcmp(domain,"255.255.255.255",16) != 0))
|
||||
{
|
||||
host_ip.addr = 0;
|
||||
dns_reconn_count = 0;
|
||||
|
@ -1179,13 +1179,13 @@ static int mqtt_socket_on( lua_State* L )
|
|||
luaL_checkanyfunction(L, 3);
|
||||
lua_pushvalue(L, 3); // copy argument (func) to the top of stack
|
||||
|
||||
if( sl == 7 && c_strcmp(method, "connect") == 0){
|
||||
if( sl == 7 && strcmp(method, "connect") == 0){
|
||||
luaL_unref(L, LUA_REGISTRYINDEX, mud->cb_connect_ref);
|
||||
mud->cb_connect_ref = luaL_ref(L, LUA_REGISTRYINDEX);
|
||||
}else if( sl == 7 && c_strcmp(method, "offline") == 0){
|
||||
}else if( sl == 7 && strcmp(method, "offline") == 0){
|
||||
luaL_unref(L, LUA_REGISTRYINDEX, mud->cb_disconnect_ref);
|
||||
mud->cb_disconnect_ref = luaL_ref(L, LUA_REGISTRYINDEX);
|
||||
}else if( sl == 7 && c_strcmp(method, "message") == 0){
|
||||
}else if( sl == 7 && strcmp(method, "message") == 0){
|
||||
luaL_unref(L, LUA_REGISTRYINDEX, mud->cb_message_ref);
|
||||
mud->cb_message_ref = luaL_ref(L, LUA_REGISTRYINDEX);
|
||||
}else{
|
||||
|
@ -1528,30 +1528,30 @@ static int mqtt_socket_lwt( lua_State* L )
|
|||
}
|
||||
stack++;
|
||||
if(mud->connect_info.will_topic){ // free the previous one if there is any
|
||||
c_free(mud->connect_info.will_topic);
|
||||
free(mud->connect_info.will_topic);
|
||||
mud->connect_info.will_topic = NULL;
|
||||
}
|
||||
if(mud->connect_info.will_message){
|
||||
c_free(mud->connect_info.will_message);
|
||||
free(mud->connect_info.will_message);
|
||||
mud->connect_info.will_message = NULL;
|
||||
}
|
||||
|
||||
mud->connect_info.will_topic = (uint8_t*) c_zalloc( topicSize + 1 );
|
||||
mud->connect_info.will_message = (uint8_t*) c_zalloc( msgSize + 1 );
|
||||
mud->connect_info.will_topic = (uint8_t*) zalloc( topicSize + 1 );
|
||||
mud->connect_info.will_message = (uint8_t*) zalloc( msgSize + 1 );
|
||||
if(!mud->connect_info.will_topic || !mud->connect_info.will_message){
|
||||
if(mud->connect_info.will_topic){
|
||||
c_free(mud->connect_info.will_topic);
|
||||
free(mud->connect_info.will_topic);
|
||||
mud->connect_info.will_topic = NULL;
|
||||
}
|
||||
if(mud->connect_info.will_message){
|
||||
c_free(mud->connect_info.will_message);
|
||||
free(mud->connect_info.will_message);
|
||||
mud->connect_info.will_message = NULL;
|
||||
}
|
||||
return luaL_error( L, "not enough memory");
|
||||
}
|
||||
c_memcpy(mud->connect_info.will_topic, lwtTopic, topicSize);
|
||||
memcpy(mud->connect_info.will_topic, lwtTopic, topicSize);
|
||||
mud->connect_info.will_topic[topicSize] = 0;
|
||||
c_memcpy(mud->connect_info.will_message, lwtMsg, msgSize);
|
||||
memcpy(mud->connect_info.will_message, lwtMsg, msgSize);
|
||||
mud->connect_info.will_message[msgSize] = 0;
|
||||
|
||||
if ( lua_isnumber(L, stack) )
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
#include "platform.h"
|
||||
#include "lmem.h"
|
||||
|
||||
#include "c_string.h"
|
||||
#include "c_stdlib.h"
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "c_types.h"
|
||||
#include "mem.h"
|
||||
|
@ -70,7 +70,7 @@ static void net_server_disconnected(void *arg) // for tcp server only
|
|||
return;
|
||||
#if 0
|
||||
char temp[20] = {0};
|
||||
c_sprintf(temp, IPSTR, IP2STR( &(pesp_conn->proto.tcp->remote_ip) ) );
|
||||
sprintf(temp, IPSTR, IP2STR( &(pesp_conn->proto.tcp->remote_ip) ) );
|
||||
NODE_DBG("remote ");
|
||||
NODE_DBG(temp);
|
||||
NODE_DBG(":");
|
||||
|
@ -117,10 +117,10 @@ static void net_socket_disconnected(void *arg) // tcp only
|
|||
}
|
||||
|
||||
if(pesp_conn->proto.tcp)
|
||||
c_free(pesp_conn->proto.tcp);
|
||||
free(pesp_conn->proto.tcp);
|
||||
pesp_conn->proto.tcp = NULL;
|
||||
if(nud->pesp_conn)
|
||||
c_free(nud->pesp_conn);
|
||||
free(nud->pesp_conn);
|
||||
nud->pesp_conn = NULL; // espconn is already disconnected
|
||||
lua_gc(gL, LUA_GCSTOP, 0);
|
||||
if(nud->self_ref != LUA_NOREF){
|
||||
|
@ -214,10 +214,10 @@ static void net_dns_found(const char *name, ip_addr_t *ipaddr, void *arg)
|
|||
}
|
||||
// ipaddr->addr is a uint32_t ip
|
||||
char ip_str[20];
|
||||
c_memset(ip_str, 0, sizeof(ip_str));
|
||||
memset(ip_str, 0, sizeof(ip_str));
|
||||
if(ipaddr->addr != 0)
|
||||
{
|
||||
c_sprintf(ip_str, IPSTR, IP2STR(&(ipaddr->addr)));
|
||||
sprintf(ip_str, IPSTR, IP2STR(&(ipaddr->addr)));
|
||||
}
|
||||
|
||||
lua_rawgeti(gL, LUA_REGISTRYINDEX, nud->cb_dns_found_ref); // the callback function
|
||||
|
@ -237,10 +237,10 @@ static void net_dns_found(const char *name, ip_addr_t *ipaddr, void *arg)
|
|||
}else{
|
||||
// ipaddr->addr is a uint32_t ip
|
||||
char ip_str[20];
|
||||
c_memset(ip_str, 0, sizeof(ip_str));
|
||||
memset(ip_str, 0, sizeof(ip_str));
|
||||
if(ipaddr->addr != 0)
|
||||
{
|
||||
c_sprintf(ip_str, IPSTR, IP2STR(&(ipaddr->addr)));
|
||||
sprintf(ip_str, IPSTR, IP2STR(&(ipaddr->addr)));
|
||||
}
|
||||
lua_pushstring(gL, ip_str); // the ip para
|
||||
}
|
||||
|
@ -271,7 +271,7 @@ static void net_server_connected(void *arg) // for tcp only
|
|||
|
||||
#if 0
|
||||
char temp[20] = {0};
|
||||
c_sprintf(temp, IPSTR, IP2STR( &(pesp_conn->proto.tcp->remote_ip) ) );
|
||||
sprintf(temp, IPSTR, IP2STR( &(pesp_conn->proto.tcp->remote_ip) ) );
|
||||
NODE_DBG("remote ");
|
||||
NODE_DBG(temp);
|
||||
NODE_DBG(":");
|
||||
|
@ -377,9 +377,9 @@ static int net_create( lua_State* L, const char* mt )
|
|||
uint8_t stack = 1;
|
||||
bool isserver = false;
|
||||
|
||||
if (mt!=NULL && c_strcmp(mt, "net.server")==0)
|
||||
if (mt!=NULL && strcmp(mt, "net.server")==0)
|
||||
isserver = true;
|
||||
else if (mt!=NULL && c_strcmp(mt, "net.socket")==0)
|
||||
else if (mt!=NULL && strcmp(mt, "net.socket")==0)
|
||||
isserver = false;
|
||||
else
|
||||
{
|
||||
|
@ -454,7 +454,7 @@ static int net_create( lua_State* L, const char* mt )
|
|||
}
|
||||
pesp_conn = nud->pesp_conn = pUdpServer;
|
||||
} else {
|
||||
pesp_conn = nud->pesp_conn = (struct espconn *)c_zalloc(sizeof(struct espconn));
|
||||
pesp_conn = nud->pesp_conn = (struct espconn *)zalloc(sizeof(struct espconn));
|
||||
if(!pesp_conn)
|
||||
return luaL_error(L, "not enough memory");
|
||||
|
||||
|
@ -463,9 +463,9 @@ static int net_create( lua_State* L, const char* mt )
|
|||
pesp_conn->reverse = NULL;
|
||||
if( type==ESPCONN_TCP )
|
||||
{
|
||||
pesp_conn->proto.tcp = (esp_tcp *)c_zalloc(sizeof(esp_tcp));
|
||||
pesp_conn->proto.tcp = (esp_tcp *)zalloc(sizeof(esp_tcp));
|
||||
if(!pesp_conn->proto.tcp){
|
||||
c_free(pesp_conn);
|
||||
free(pesp_conn);
|
||||
pesp_conn = nud->pesp_conn = NULL;
|
||||
return luaL_error(L, "not enough memory");
|
||||
}
|
||||
|
@ -473,9 +473,9 @@ static int net_create( lua_State* L, const char* mt )
|
|||
}
|
||||
else if( type==ESPCONN_UDP )
|
||||
{
|
||||
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){
|
||||
c_free(pesp_conn);
|
||||
free(pesp_conn);
|
||||
pesp_conn = nud->pesp_conn = NULL;
|
||||
return luaL_error(L, "not enough memory");
|
||||
}
|
||||
|
@ -515,9 +515,9 @@ static int net_delete( lua_State* L, const char* mt )
|
|||
{
|
||||
NODE_DBG("net_delete is called.\n");
|
||||
bool isserver = false;
|
||||
if (mt!=NULL && c_strcmp(mt, "net.server")==0)
|
||||
if (mt!=NULL && strcmp(mt, "net.server")==0)
|
||||
isserver = true;
|
||||
else if (mt!=NULL && c_strcmp(mt, "net.socket")==0)
|
||||
else if (mt!=NULL && strcmp(mt, "net.socket")==0)
|
||||
isserver = false;
|
||||
else
|
||||
{
|
||||
|
@ -539,14 +539,14 @@ static int net_delete( lua_State* L, const char* mt )
|
|||
{
|
||||
if(nud->pesp_conn->type == ESPCONN_UDP){
|
||||
if(nud->pesp_conn->proto.udp)
|
||||
c_free(nud->pesp_conn->proto.udp);
|
||||
free(nud->pesp_conn->proto.udp);
|
||||
nud->pesp_conn->proto.udp = NULL;
|
||||
} else if (nud->pesp_conn->type == ESPCONN_TCP) {
|
||||
if(nud->pesp_conn->proto.tcp)
|
||||
c_free(nud->pesp_conn->proto.tcp);
|
||||
free(nud->pesp_conn->proto.tcp);
|
||||
nud->pesp_conn->proto.tcp = NULL;
|
||||
}
|
||||
c_free(nud->pesp_conn);
|
||||
free(nud->pesp_conn);
|
||||
}
|
||||
nud->pesp_conn = NULL; // for socket, it will free this when disconnected
|
||||
}
|
||||
|
@ -653,14 +653,14 @@ static void socket_dns_found(const char *name, ip_addr_t *ipaddr, void *arg)
|
|||
dns_reconn_count = 0;
|
||||
if( pesp_conn->type == ESPCONN_TCP )
|
||||
{
|
||||
c_memcpy(pesp_conn->proto.tcp->remote_ip, &(ipaddr->addr), 4);
|
||||
memcpy(pesp_conn->proto.tcp->remote_ip, &(ipaddr->addr), 4);
|
||||
NODE_DBG("TCP ip is set: ");
|
||||
NODE_DBG(IPSTR, IP2STR(&(ipaddr->addr)));
|
||||
NODE_DBG("\n");
|
||||
}
|
||||
else if (pesp_conn->type == ESPCONN_UDP)
|
||||
{
|
||||
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(IPSTR, IP2STR(&(ipaddr->addr)));
|
||||
NODE_DBG("\n");
|
||||
|
@ -683,9 +683,9 @@ static int net_start( lua_State* L, const char* mt )
|
|||
const char *domain;
|
||||
uint8_t stack = 1;
|
||||
|
||||
if (mt!=NULL && c_strcmp(mt, "net.server")==0)
|
||||
if (mt!=NULL && strcmp(mt, "net.server")==0)
|
||||
isserver = true;
|
||||
else if (mt!=NULL && c_strcmp(mt, "net.socket")==0)
|
||||
else if (mt!=NULL && strcmp(mt, "net.socket")==0)
|
||||
isserver = false;
|
||||
else
|
||||
{
|
||||
|
@ -744,9 +744,9 @@ static int net_start( lua_State* L, const char* mt )
|
|||
if( pesp_conn->type == ESPCONN_TCP )
|
||||
{
|
||||
if(isserver)
|
||||
c_memcpy(pesp_conn->proto.tcp->local_ip, &ipaddr.addr, 4);
|
||||
memcpy(pesp_conn->proto.tcp->local_ip, &ipaddr.addr, 4);
|
||||
else
|
||||
c_memcpy(pesp_conn->proto.tcp->remote_ip, &ipaddr.addr, 4);
|
||||
memcpy(pesp_conn->proto.tcp->remote_ip, &ipaddr.addr, 4);
|
||||
NODE_DBG("TCP ip is set: ");
|
||||
NODE_DBG(IPSTR, IP2STR(&ipaddr.addr));
|
||||
NODE_DBG("\n");
|
||||
|
@ -754,9 +754,9 @@ static int net_start( lua_State* L, const char* mt )
|
|||
else if (pesp_conn->type == ESPCONN_UDP)
|
||||
{
|
||||
if(isserver)
|
||||
c_memcpy(pesp_conn->proto.udp->local_ip, &ipaddr.addr, 4);
|
||||
memcpy(pesp_conn->proto.udp->local_ip, &ipaddr.addr, 4);
|
||||
else
|
||||
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(IPSTR, IP2STR(&ipaddr.addr));
|
||||
NODE_DBG("\n");
|
||||
|
@ -831,7 +831,7 @@ static int net_start( lua_State* L, const char* mt )
|
|||
}
|
||||
|
||||
if(!isserver){
|
||||
if((ipaddr.addr == IPADDR_NONE) && (c_memcmp(domain,"255.255.255.255",16) != 0))
|
||||
if((ipaddr.addr == IPADDR_NONE) && (memcmp(domain,"255.255.255.255",16) != 0))
|
||||
{
|
||||
host_ip.addr = 0;
|
||||
dns_reconn_count = 0;
|
||||
|
@ -865,9 +865,9 @@ static int net_close( lua_State* L, const char* mt )
|
|||
if(nud->pesp_conn == NULL)
|
||||
return 0;
|
||||
|
||||
if (mt!=NULL && c_strcmp(mt, "net.server")==0)
|
||||
if (mt!=NULL && strcmp(mt, "net.server")==0)
|
||||
isserver = true;
|
||||
else if (mt!=NULL && c_strcmp(mt, "net.socket")==0)
|
||||
else if (mt!=NULL && strcmp(mt, "net.socket")==0)
|
||||
isserver = false;
|
||||
else
|
||||
{
|
||||
|
@ -973,9 +973,9 @@ static int net_on( lua_State* L, const char* mt )
|
|||
return 0;
|
||||
}
|
||||
|
||||
if (mt!=NULL && c_strcmp(mt, "net.server")==0)
|
||||
if (mt!=NULL && strcmp(mt, "net.server")==0)
|
||||
isserver = true;
|
||||
else if (mt!=NULL && c_strcmp(mt, "net.socket")==0)
|
||||
else if (mt!=NULL && strcmp(mt, "net.socket")==0)
|
||||
isserver = false;
|
||||
else
|
||||
{
|
||||
|
@ -990,27 +990,27 @@ static int net_on( lua_State* L, const char* mt )
|
|||
luaL_checkanyfunction(L, 3);
|
||||
lua_pushvalue(L, 3); // copy argument (func) to the top of stack
|
||||
|
||||
if(!isserver && nud->pesp_conn->type == ESPCONN_TCP && sl == 10 && c_strcmp(method, "connection") == 0){
|
||||
if(!isserver && nud->pesp_conn->type == ESPCONN_TCP && sl == 10 && strcmp(method, "connection") == 0){
|
||||
if(nud->cb_connect_ref != LUA_NOREF)
|
||||
luaL_unref(L, LUA_REGISTRYINDEX, nud->cb_connect_ref);
|
||||
nud->cb_connect_ref = luaL_ref(L, LUA_REGISTRYINDEX);
|
||||
}else if(!isserver && nud->pesp_conn->type == ESPCONN_TCP && sl == 12 && c_strcmp(method, "reconnection") == 0){
|
||||
}else if(!isserver && nud->pesp_conn->type == ESPCONN_TCP && sl == 12 && strcmp(method, "reconnection") == 0){
|
||||
if(nud->cb_reconnect_ref != LUA_NOREF)
|
||||
luaL_unref(L, LUA_REGISTRYINDEX, nud->cb_reconnect_ref);
|
||||
nud->cb_reconnect_ref = luaL_ref(L, LUA_REGISTRYINDEX);
|
||||
}else if(!isserver && nud->pesp_conn->type == ESPCONN_TCP && sl == 13 && c_strcmp(method, "disconnection") == 0){
|
||||
}else if(!isserver && nud->pesp_conn->type == ESPCONN_TCP && sl == 13 && strcmp(method, "disconnection") == 0){
|
||||
if(nud->cb_disconnect_ref != LUA_NOREF)
|
||||
luaL_unref(L, LUA_REGISTRYINDEX, nud->cb_disconnect_ref);
|
||||
nud->cb_disconnect_ref = luaL_ref(L, LUA_REGISTRYINDEX);
|
||||
}else if((!isserver || nud->pesp_conn->type == ESPCONN_UDP) && sl == 7 && c_strcmp(method, "receive") == 0){
|
||||
}else if((!isserver || nud->pesp_conn->type == ESPCONN_UDP) && sl == 7 && strcmp(method, "receive") == 0){
|
||||
if(nud->cb_receive_ref != LUA_NOREF)
|
||||
luaL_unref(L, LUA_REGISTRYINDEX, nud->cb_receive_ref);
|
||||
nud->cb_receive_ref = luaL_ref(L, LUA_REGISTRYINDEX);
|
||||
}else if((!isserver || nud->pesp_conn->type == ESPCONN_UDP) && sl == 4 && c_strcmp(method, "sent") == 0){
|
||||
}else if((!isserver || nud->pesp_conn->type == ESPCONN_UDP) && sl == 4 && strcmp(method, "sent") == 0){
|
||||
if(nud->cb_send_ref != LUA_NOREF)
|
||||
luaL_unref(L, LUA_REGISTRYINDEX, nud->cb_send_ref);
|
||||
nud->cb_send_ref = luaL_ref(L, LUA_REGISTRYINDEX);
|
||||
}else if(!isserver && nud->pesp_conn->type == ESPCONN_TCP && sl == 3 && c_strcmp(method, "dns") == 0){
|
||||
}else if(!isserver && nud->pesp_conn->type == ESPCONN_TCP && sl == 3 && strcmp(method, "dns") == 0){
|
||||
if(nud->cb_dns_found_ref != LUA_NOREF)
|
||||
luaL_unref(L, LUA_REGISTRYINDEX, nud->cb_dns_found_ref);
|
||||
nud->cb_dns_found_ref = luaL_ref(L, LUA_REGISTRYINDEX);
|
||||
|
@ -1044,9 +1044,9 @@ static int net_send( lua_State* L, const char* mt )
|
|||
}
|
||||
pesp_conn = nud->pesp_conn;
|
||||
|
||||
if (mt!=NULL && c_strcmp(mt, "net.server")==0)
|
||||
if (mt!=NULL && strcmp(mt, "net.server")==0)
|
||||
isserver = true;
|
||||
else if (mt!=NULL && c_strcmp(mt, "net.socket")==0)
|
||||
else if (mt!=NULL && strcmp(mt, "net.socket")==0)
|
||||
isserver = false;
|
||||
else
|
||||
{
|
||||
|
@ -1060,7 +1060,7 @@ static int net_send( lua_State* L, const char* mt )
|
|||
|
||||
#if 0
|
||||
char temp[20] = {0};
|
||||
c_sprintf(temp, IPSTR, IP2STR( &(pesp_conn->proto.tcp->remote_ip) ) );
|
||||
sprintf(temp, IPSTR, IP2STR( &(pesp_conn->proto.tcp->remote_ip) ) );
|
||||
NODE_DBG("remote ");
|
||||
NODE_DBG(temp);
|
||||
NODE_DBG(":");
|
||||
|
@ -1085,8 +1085,8 @@ static int net_send( lua_State* L, const char* mt )
|
|||
if (espconn_get_connection_info (pesp_conn, &pr, 0) != ESPCONN_OK)
|
||||
return luaL_error (L, "remote ip/port unavailable");
|
||||
pesp_conn->proto.udp->remote_port = pr->remote_port;
|
||||
os_memmove (pesp_conn->proto.udp->remote_ip, pr->remote_ip, 4);
|
||||
// The remot_info apparently should *not* be os_free()d, fyi
|
||||
memmove (pesp_conn->proto.udp->remote_ip, pr->remote_ip, 4);
|
||||
// The remot_info apparently should *not* be free()d, fyi
|
||||
}
|
||||
#ifdef CLIENT_SSL_ENABLE
|
||||
if(nud->secure)
|
||||
|
@ -1114,9 +1114,9 @@ static int net_dns( lua_State* L, const char* mt )
|
|||
return 0;
|
||||
}
|
||||
|
||||
if (mt!=NULL && c_strcmp(mt, "net.server")==0)
|
||||
if (mt!=NULL && strcmp(mt, "net.server")==0)
|
||||
isserver = true;
|
||||
else if (mt!=NULL && c_strcmp(mt, "net.socket")==0)
|
||||
else if (mt!=NULL && strcmp(mt, "net.socket")==0)
|
||||
isserver = false;
|
||||
else
|
||||
{
|
||||
|
@ -1365,7 +1365,7 @@ static int net_socket_getpeer( lua_State* L )
|
|||
|
||||
if(nud!=NULL && nud->pesp_conn!=NULL ){
|
||||
char temp[20] = {0};
|
||||
c_sprintf(temp, IPSTR, IP2STR( &(nud->pesp_conn->proto.tcp->remote_ip) ) );
|
||||
sprintf(temp, IPSTR, IP2STR( &(nud->pesp_conn->proto.tcp->remote_ip) ) );
|
||||
if ( nud->pesp_conn->proto.tcp->remote_port != 0 ) {
|
||||
lua_pushstring( L, temp );
|
||||
lua_pushinteger( L, nud->pesp_conn->proto.tcp->remote_port );
|
||||
|
@ -1532,7 +1532,7 @@ static const char *fill_page_with_pem(lua_State *L, const unsigned char *flash_m
|
|||
memset(buffer, 0xff, buffer_limit - buffer);
|
||||
|
||||
// Lets see if it matches what is already there....
|
||||
if (c_memcmp(buffer_base, flash_memory, INTERNAL_FLASH_SECTOR_SIZE) != 0) {
|
||||
if (memcmp(buffer_base, flash_memory, INTERNAL_FLASH_SECTOR_SIZE) != 0) {
|
||||
// Starts being dangerous
|
||||
if (platform_flash_erase_sector(flash_offset / INTERNAL_FLASH_SECTOR_SIZE) != PLATFORM_OK) {
|
||||
luaM_free(L, buffer_base);
|
||||
|
@ -1672,7 +1672,7 @@ static int net_getdnsserver( lua_State* L )
|
|||
lua_pushnil( L );
|
||||
} else {
|
||||
char temp[20] = {0};
|
||||
c_sprintf(temp, IPSTR, IP2STR( &ipaddr.addr ) );
|
||||
sprintf(temp, IPSTR, IP2STR( &ipaddr.addr ) );
|
||||
lua_pushstring( L, temp );
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
#include "lrodefs.h"
|
||||
|
||||
#include "c_types.h"
|
||||
#include "c_string.h"
|
||||
#include <string.h>
|
||||
#include "driver/uart.h"
|
||||
#include "user_interface.h"
|
||||
#include "flash_api.h"
|
||||
|
@ -276,9 +276,9 @@ static int node_key( lua_State* L )
|
|||
if (str == NULL)
|
||||
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;
|
||||
} else if (sl == 4 && c_strcmp(str, "long") == 0) {
|
||||
} else if (sl == 4 && strcmp(str, "long") == 0) {
|
||||
ref = &long_key_ref;
|
||||
} else {
|
||||
ref = &short_key_ref;
|
||||
|
@ -311,9 +311,9 @@ static int node_input( lua_State* L )
|
|||
{
|
||||
lua_Load *load = &gLoad;
|
||||
if (load->line_position == 0) {
|
||||
c_memcpy(load->line, s, l);
|
||||
memcpy(load->line, s, l);
|
||||
load->line[l + 1] = '\0';
|
||||
load->line_position = c_strlen(load->line) + 1;
|
||||
load->line_position = strlen(load->line) + 1;
|
||||
load->done = 1;
|
||||
NODE_DBG("Get command:\n");
|
||||
NODE_DBG(load->line); // buggy here
|
||||
|
@ -328,7 +328,7 @@ static int output_redir_ref = LUA_NOREF;
|
|||
static int serial_debug = 1;
|
||||
void output_redirect(const char *str) {
|
||||
lua_State *L = lua_getstate();
|
||||
// if(c_strlen(str)>=TX_BUFF_SIZE){
|
||||
// if(strlen(str)>=TX_BUFF_SIZE){
|
||||
// NODE_ERR("output too long.\n");
|
||||
// return;
|
||||
// }
|
||||
|
@ -402,13 +402,13 @@ static int node_compile( lua_State* L )
|
|||
return luaL_error(L, "filename too long");
|
||||
|
||||
char output[FS_NAME_MAX_LENGTH];
|
||||
c_strcpy(output, fname);
|
||||
strcpy(output, fname);
|
||||
// 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");
|
||||
|
||||
output[c_strlen(output) - 2] = 'c';
|
||||
output[c_strlen(output) - 1] = '\0';
|
||||
output[strlen(output) - 2] = 'c';
|
||||
output[strlen(output) - 1] = '\0';
|
||||
NODE_DBG(output);
|
||||
NODE_DBG("\n");
|
||||
if (luaL_loadfsfile(L, fname) != 0) {
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
#include "ets_sys.h"
|
||||
#include "os_type.h"
|
||||
#include "osapi.h"
|
||||
#include "c_stdlib.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "module.h"
|
||||
#include "lauxlib.h"
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
#include "c_types.h"
|
||||
#include "user_interface.h"
|
||||
#include "driver/rotary.h"
|
||||
#include "../libc/c_stdlib.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
#define MASK(x) (1 << ROTARY_ ## x ## _INDEX)
|
||||
|
||||
|
@ -143,7 +143,7 @@ static int lrotary_setup( lua_State* L )
|
|||
callback_free(L, id, ROTARY_ALL);
|
||||
|
||||
if (!data[id]) {
|
||||
data[id] = (DATA *) os_zalloc(sizeof(DATA));
|
||||
data[id] = (DATA *) zalloc(sizeof(DATA));
|
||||
if (!data[id]) {
|
||||
return -1;
|
||||
}
|
||||
|
@ -202,7 +202,7 @@ static int lrotary_close( lua_State* L )
|
|||
DATA *d = data[id];
|
||||
if (d) {
|
||||
data[id] = NULL;
|
||||
os_free(d);
|
||||
free(d);
|
||||
}
|
||||
|
||||
if (rotary_close( id )) {
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include "rtc/rtctime.h"
|
||||
#define RTCTIME_SLEEP_ALIGNED rtctime_deep_sleep_until_aligned_us
|
||||
#include "rtc/rtcfifo.h"
|
||||
#include <string.h>
|
||||
|
||||
// rtcfifo.prepare ([{sensor_count=n, interval_us=m, storage_begin=x, storage_end=y}])
|
||||
static int rtcfifo_prepare (lua_State *L)
|
||||
|
|
|
@ -38,7 +38,7 @@
|
|||
#include "os_type.h"
|
||||
#include "osapi.h"
|
||||
#include "lwip/udp.h"
|
||||
#include "c_stdlib.h"
|
||||
#include <stdlib.h>
|
||||
#include "user_modules.h"
|
||||
#include "lwip/dns.h"
|
||||
#include "user_interface.h"
|
||||
|
@ -53,7 +53,7 @@
|
|||
#define MAX_ATTEMPTS 5
|
||||
|
||||
#if 0
|
||||
# define sntp_dbg(...) c_printf(__VA_ARGS__)
|
||||
# define sntp_dbg(...) printf(__VA_ARGS__)
|
||||
#else
|
||||
# define sntp_dbg(...)
|
||||
#endif
|
||||
|
@ -110,7 +110,7 @@ static void cleanup (lua_State *L)
|
|||
udp_remove (state->pcb);
|
||||
luaL_unref (L, LUA_REGISTRYINDEX, state->sync_cb_ref);
|
||||
luaL_unref (L, LUA_REGISTRYINDEX, state->err_cb_ref);
|
||||
os_free (state);
|
||||
free (state);
|
||||
state = 0;
|
||||
}
|
||||
|
||||
|
@ -328,7 +328,7 @@ static int sntp_sync (lua_State *L)
|
|||
if (state)
|
||||
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)
|
||||
sync_err ("out of memory");
|
||||
|
||||
|
@ -386,7 +386,7 @@ error:
|
|||
{
|
||||
if (state->pcb)
|
||||
udp_remove (state->pcb);
|
||||
c_free (state);
|
||||
free (state);
|
||||
state = 0;
|
||||
}
|
||||
return luaL_error (L, errmsg);
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue