diff --git a/app/Makefile b/app/Makefile index 52c57da5..897b3f8b 100644 --- a/app/Makefile +++ b/app/Makefile @@ -90,31 +90,33 @@ COMPONENTS_eagle.app.v6 = \ # only those) modules are pulled in. SELECTED_MODULE_SYMS=$(filter %_module_selected %module_selected1,$(shell $(NM) modules/.output/$(TARGET)/$(FLAVOR)/lib/libmodules.a)) -LINKFLAGS_eagle.app.v6 = \ - -Wl,--gc-sections \ - -Wl,-Map=mapfile \ +LINKFLAGS_eagle.app.v6 = \ + -Wl,--gc-sections \ + -Wl,-Map=mapfile \ -nostdlib \ - -T$(LD_FILE) \ - -Wl,@../ld/defsym.rom \ - -Wl,--no-check-sections \ - -Wl,-static \ + -T$(LD_FILE) \ + -Wl,@../ld/defsym.rom \ + -Wl,--no-check-sections \ + -Wl,-static \ $(addprefix -u , $(SELECTED_MODULE_SYMS)) \ - -Wl,--start-group \ + -Wl,--start-group \ -lmain \ - -lc \ + $(DEP_LIBS_eagle.app.v6)\ + -Wl,--end-group \ + -Wl,--start-group \ -lgcc \ -lhal \ -lphy \ -lpp \ -lnet80211 \ + -lsmartconfig \ -lwpa \ -lwpa2 \ - -lsmartconfig \ -lcrypto \ -lwps \ - $(DEP_LIBS_eagle.app.v6) \ - -Wl,--end-group \ - -lm + -lc \ + -lm \ + -Wl,--end-group # -Wl,--cref # -Wl,--wrap=_xtos_set_exception_handler diff --git a/app/coap/coap.c b/app/coap/coap.c index f207a953..e487c3ab 100644 --- a/app/coap/coap.c +++ b/app/coap/coap.c @@ -1,6 +1,6 @@ #include "user_config.h" -#include "c_stdio.h" -#include "c_string.h" +#include +#include #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;ihdr); 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;ipath->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) 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; } diff --git a/app/coap/coap.h b/app/coap/coap.h index a931cbd9..97c35cb4 100644 --- a/app/coap/coap.h +++ b/app/coap/coap.h @@ -5,8 +5,8 @@ extern "C" { #endif -#include "c_stdint.h" -#include "c_stddef.h" +#include +#include #include "lualib.h" #include "lauxlib.h" diff --git a/app/coap/coap_io.c b/app/coap/coap_io.c index 7d19fd87..21feade4 100644 --- a/app/coap/coap_io.c +++ b/app/coap/coap_io.c @@ -1,4 +1,4 @@ -#include "c_string.h" +#include #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); diff --git a/app/coap/coap_server.c b/app/coap/coap_server.c index cbec01f9..55c171f9 100644 --- a/app/coap/coap_server.c +++ b/app/coap/coap_server.c @@ -1,6 +1,6 @@ #include "user_config.h" #include "c_types.h" -#include "c_stdlib.h" +#include #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; } diff --git a/app/coap/coap_timer.c b/app/coap/coap_timer.c index 384ecab2..c8434193 100644 --- a/app/coap/coap_timer.c +++ b/app/coap/coap_timer.c @@ -1,6 +1,7 @@ #include "node.h" #include "coap_timer.h" #include "os_type.h" +#include "osapi.h" #include "pm/swtimer.h" static os_timer_t coap_timer; diff --git a/app/coap/endpoints.c b/app/coap/endpoints.c index 4d09f73b..1ec88287 100644 --- a/app/coap/endpoints.c +++ b/app/coap/endpoints.c @@ -1,6 +1,6 @@ -#include "c_stdio.h" -#include "c_string.h" -#include "c_stdlib.h" +#include +#include +#include #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 *)calloc(1,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"}}; @@ -49,17 +49,17 @@ 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(c_strlen(h->name)) + if(strlen(h->name)) { n = lua_gettop(L); lua_getglobal(L, h->name); @@ -70,7 +70,7 @@ static int handle_get_variable(const coap_endpoint_t *ep, coap_rw_buffer_t *scra } else { const char *res = lua_tostring(L,-1); lua_settop(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,18 +105,18 @@ 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); NODE_DBG(" match.\n"); - if(c_strlen(h->name)) + if(strlen(h->name)) { n = lua_gettop(L); lua_getglobal(L, h->name); @@ -173,7 +173,7 @@ static int handle_post_command(const coap_endpoint_t *ep, coap_rw_buffer_t *scra { char line[LUA_MAXINPUT]; if (!coap_buffer_to_string(line, LUA_MAXINPUT, &inpkt->payload) && - lua_put_line(line, c_strlen(line))) { + lua_put_line(line, strlen(line))) { NODE_DBG("\nResult(if any):\n"); system_os_post (LUA_TASK_PRIO, LUA_PROCESS_LINE_SIG, 0); } @@ -211,7 +211,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 @@ -222,57 +222,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; } diff --git a/app/coap/hash.c b/app/coap/hash.c index 0638ffa9..99f4db89 100644 --- a/app/coap/hash.c +++ b/app/coap/hash.c @@ -1,5 +1,5 @@ #include "hash.h" -#include "c_string.h" +#include /* 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); diff --git a/app/coap/node.c b/app/coap/node.c index 7e335449..52186ecb 100644 --- a/app/coap/node.c +++ b/app/coap/node.c @@ -1,14 +1,14 @@ -#include "c_string.h" -#include "c_stdlib.h" +#include +#include #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 *)calloc(1,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; } diff --git a/app/coap/pdu.c b/app/coap/pdu.c index be287d95..892bee6c 100644 --- a/app/coap/pdu.c +++ b/app/coap/pdu.c @@ -1,38 +1,38 @@ -#include "c_stdlib.h" +#include #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 *)calloc(1,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 *)calloc(1,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 *)calloc(1,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 *)calloc(1,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; } diff --git a/app/coap/str.c b/app/coap/str.c index c31a021f..1c882eed 100644 --- a/app/coap/str.c +++ b/app/coap/str.c @@ -6,23 +6,23 @@ * README for terms of use. */ -#include "c_stdlib.h" +#include #include "c_types.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); } diff --git a/app/coap/str.h b/app/coap/str.h index efcd9a3d..0289cf44 100644 --- a/app/coap/str.h +++ b/app/coap/str.h @@ -9,7 +9,7 @@ #ifndef _COAP_STR_H_ #define _COAP_STR_H_ -#include "c_string.h" +#include typedef struct { size_t length; /* length of string */ diff --git a/app/coap/uri.c b/app/coap/uri.c index a87dcb2f..c57de10a 100644 --- a/app/coap/uri.c +++ b/app/coap/uri.c @@ -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 +#include +#include +#include #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; diff --git a/app/crypto/digests.c b/app/crypto/digests.c index 409b3e90..05536581 100644 --- a/app/crypto/digests.c +++ b/app/crypto/digests.c @@ -34,7 +34,8 @@ #include "osapi.h" #include "mem.h" #include -#include +#include +#include #ifdef MD2_ENABLE #include "ssl/ssl_crypto.h" diff --git a/app/crypto/mech.c b/app/crypto/mech.c index 4fa5adec..d0938358 100644 --- a/app/crypto/mech.c +++ b/app/crypto/mech.c @@ -33,7 +33,8 @@ #include "mech.h" #include "sdk-aes.h" -#include "c_string.h" +#include +#include /* ----- AES ---------------------------------------------------------- */ @@ -58,7 +59,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 +69,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) { diff --git a/app/dht/dht.c b/app/dht/dht.c index 932725e3..cc412e52 100644 --- a/app/dht/dht.c +++ b/app/dht/dht.c @@ -29,7 +29,7 @@ #include "user_interface.h" #include "platform.h" -#include "c_stdio.h" +#include #include "dht.h" #ifndef LOW diff --git a/app/driver/i2c_master.c b/app/driver/i2c_master.c index b3ec4869..618d0898 100644 --- a/app/driver/i2c_master.c +++ b/app/driver/i2c_master.c @@ -24,7 +24,7 @@ * Rework of original driver: Natalia Sorokina , 2018 */ -#include "../libc/c_stdlib.h" +#include #include "ets_sys.h" #include "osapi.h" #include "gpio.h" diff --git a/app/driver/rotary.c b/app/driver/rotary.c index eedeb5e1..6e01506e 100644 --- a/app/driver/rotary.c +++ b/app/driver/rotary.c @@ -12,8 +12,8 @@ #include "platform.h" #include "c_types.h" -#include "../libc/c_stdlib.h" -#include "../libc/c_stdio.h" +#include +#include #include "driver/rotary.h" #include "user_interface.h" #include "task/task.h" @@ -87,7 +87,7 @@ int rotary_close(uint32_t channel) rotary_clear_pin(d->phase_b_pin); rotary_clear_pin(d->press_pin); - c_free(d); + free(d); set_gpio_bits(); @@ -207,7 +207,7 @@ int rotary_setup(uint32_t channel, int phase_a, int phase_b, int press, task_han } } - DATA *d = (DATA *) c_zalloc(sizeof(DATA)); + DATA *d = (DATA *) calloc(1, sizeof(DATA)); if (!d) { return -1; } diff --git a/app/driver/switec.c b/app/driver/switec.c index 1dbfe20f..23c1a5f1 100644 --- a/app/driver/switec.c +++ b/app/driver/switec.c @@ -15,8 +15,8 @@ #include "platform.h" #include "c_types.h" -#include "../libc/c_stdlib.h" -#include "../libc/c_stdio.h" +#include +#include #include "driver/switec.h" #include "ets_sys.h" #include "os_type.h" @@ -101,7 +101,7 @@ int switec_close(uint32_t channel) gpio_output_set(0, 0, 0, d->mask); data[channel] = NULL; - c_free(d); + free(d); // See if there are any other channels active for (channel = 0; channel < sizeof(data)/sizeof(data[0]); channel++) { @@ -259,7 +259,7 @@ int switec_setup(uint32_t channel, int *pin, int max_deg_per_sec, task_handle_t } } - DATA *d = (DATA *) c_zalloc(sizeof(DATA)); + DATA *d = (DATA *) calloc(1, sizeof(DATA)); if (!d) { return -1; } @@ -269,7 +269,7 @@ int switec_setup(uint32_t channel, int *pin, int max_deg_per_sec, task_handle_t // no autoreload if (!platform_hw_timer_init(TIMER_OWNER, FRC1_SOURCE, FALSE)) { // Failed to get the timer - c_free(d); + free(d); return -1; } } @@ -299,12 +299,12 @@ int switec_setup(uint32_t channel, int *pin, int max_deg_per_sec, task_handle_t #ifdef SWITEC_DEBUG for (i = 0; i < 4; i++) { - c_printf("pin[%d]=%d\n", i, pin[i]); + printf("pin[%d]=%d\n", i, pin[i]); } - c_printf("Mask=0x%x\n", d->mask); + printf("Mask=0x%x\n", d->mask); for (i = 0; i < N_STATES; i++) { - c_printf("pinstate[%d]=0x%x\n", i, d->pinstate[i]); + printf("pinstate[%d]=0x%x\n", i, d->pinstate[i]); } #endif diff --git a/app/fatfs/myfatfs.c b/app/fatfs/myfatfs.c index be079f31..c7a9c0a1 100644 --- a/app/fatfs/myfatfs.c +++ b/app/fatfs/myfatfs.c @@ -1,5 +1,6 @@ -#include -#include +#include +#include +#include #include "vfs_int.h" @@ -12,37 +13,37 @@ static FRESULT last_result = FR_OK; static const char* const volstr[FF_VOLUMES] = {FF_VOLUME_STRS}; -static int is_current_drive = FALSE; +static int is_current_drive = false; // forward declarations -static sint32_t myfatfs_close( const struct vfs_file *fd ); -static sint32_t myfatfs_read( const struct vfs_file *fd, void *ptr, size_t len ); -static sint32_t myfatfs_write( const struct vfs_file *fd, const void *ptr, size_t len ); -static sint32_t myfatfs_lseek( const struct vfs_file *fd, sint32_t off, int whence ); -static sint32_t myfatfs_eof( const struct vfs_file *fd ); -static sint32_t myfatfs_tell( const struct vfs_file *fd ); -static sint32_t myfatfs_flush( const struct vfs_file *fd ); +static int32_t myfatfs_close( const struct vfs_file *fd ); +static int32_t myfatfs_read( const struct vfs_file *fd, void *ptr, size_t len ); +static int32_t myfatfs_write( const struct vfs_file *fd, const void *ptr, size_t len ); +static int32_t myfatfs_lseek( const struct vfs_file *fd, int32_t off, int whence ); +static int32_t myfatfs_eof( const struct vfs_file *fd ); +static int32_t myfatfs_tell( const struct vfs_file *fd ); +static int32_t myfatfs_flush( const struct vfs_file *fd ); static uint32_t myfatfs_fsize( const struct vfs_file *fd ); -static sint32_t myfatfs_ferrno( const struct vfs_file *fd ); +static int32_t myfatfs_ferrno( const struct vfs_file *fd ); -static sint32_t myfatfs_closedir( const struct vfs_dir *dd ); -static sint32_t myfatfs_readdir( const struct vfs_dir *dd, struct vfs_stat *buf ); +static int32_t myfatfs_closedir( const struct vfs_dir *dd ); +static int32_t myfatfs_readdir( const struct vfs_dir *dd, struct vfs_stat *buf ); static vfs_vol *myfatfs_mount( const char *name, int num ); static vfs_file *myfatfs_open( const char *name, const char *mode ); static vfs_dir *myfatfs_opendir( const char *name ); -static sint32_t myfatfs_stat( const char *name, struct vfs_stat *buf ); -static sint32_t myfatfs_remove( const char *name ); -static sint32_t myfatfs_rename( const char *oldname, const char *newname ); -static sint32_t myfatfs_mkdir( const char *name ); -static sint32_t myfatfs_fsinfo( uint32_t *total, uint32_t *used ); -static sint32_t myfatfs_chdrive( const char *name ); -static sint32_t myfatfs_chdir( const char *name ); -static sint32_t myfatfs_errno( void ); +static int32_t myfatfs_stat( const char *name, struct vfs_stat *buf ); +static int32_t myfatfs_remove( const char *name ); +static int32_t myfatfs_rename( const char *oldname, const char *newname ); +static int32_t myfatfs_mkdir( const char *name ); +static int32_t myfatfs_fsinfo( uint32_t *total, uint32_t *used ); +static int32_t myfatfs_chdrive( const char *name ); +static int32_t myfatfs_chdir( const char *name ); +static int32_t myfatfs_errno( void ); static void myfatfs_clearerr( void ); -static sint32_t myfatfs_umount( const struct vfs_vol *vol ); +static int32_t myfatfs_umount( const struct vfs_vol *vol ); // --------------------------------------------------------------------------- @@ -112,12 +113,12 @@ struct myvfs_dir { // void *ff_memalloc( UINT size ) { - return c_malloc( size ); + return malloc( size ); } void ff_memfree( void *mblock ) { - c_free( mblock ); + free( mblock ); } // TODO @@ -153,14 +154,14 @@ DWORD get_fattime( void ) const struct myvfs_vol *myvol = (const struct myvfs_vol *)descr; \ FATFS *fs = (FATFS *)&(myvol->fs); -static sint32_t myfatfs_umount( const struct vfs_vol *vol ) +static int32_t myfatfs_umount( const struct vfs_vol *vol ) { GET_FATFS_FS(vol); last_result = f_mount( NULL, myvol->ldrname, 0 ); - c_free( myvol->ldrname ); - c_free( (void *)vol ); + free( myvol->ldrname ); + free( (void *)vol ); return last_result == FR_OK ? VFS_RES_OK : VFS_RES_ERR; } @@ -173,19 +174,19 @@ static sint32_t myfatfs_umount( const struct vfs_vol *vol ) const struct myvfs_file *myfd = (const struct myvfs_file *)descr; \ FIL *fp = (FIL *)&(myfd->fp); -static sint32_t myfatfs_close( const struct vfs_file *fd ) +static int32_t myfatfs_close( const struct vfs_file *fd ) { GET_FIL_FP(fd) last_result = f_close( fp ); // free descriptor memory - c_free( (void *)fd ); + free( (void *)fd ); return last_result == FR_OK ? VFS_RES_OK : VFS_RES_ERR; } -static sint32_t myfatfs_read( const struct vfs_file *fd, void *ptr, size_t len ) +static int32_t myfatfs_read( const struct vfs_file *fd, void *ptr, size_t len ) { GET_FIL_FP(fd); UINT act_read; @@ -195,7 +196,7 @@ static sint32_t myfatfs_read( const struct vfs_file *fd, void *ptr, size_t len ) return last_result == FR_OK ? act_read : VFS_RES_ERR; } -static sint32_t myfatfs_write( const struct vfs_file *fd, const void *ptr, size_t len ) +static int32_t myfatfs_write( const struct vfs_file *fd, const void *ptr, size_t len ) { GET_FIL_FP(fd); UINT act_written; @@ -205,7 +206,7 @@ static sint32_t myfatfs_write( const struct vfs_file *fd, const void *ptr, size_ return last_result == FR_OK ? act_written : VFS_RES_ERR; } -static sint32_t myfatfs_lseek( const struct vfs_file *fd, sint32_t off, int whence ) +static int32_t myfatfs_lseek( const struct vfs_file *fd, int32_t off, int whence ) { GET_FIL_FP(fd); FSIZE_t new_pos; @@ -231,7 +232,7 @@ static sint32_t myfatfs_lseek( const struct vfs_file *fd, sint32_t off, int when return last_result == FR_OK ? new_pos : VFS_RES_ERR; } -static sint32_t myfatfs_eof( const struct vfs_file *fd ) +static int32_t myfatfs_eof( const struct vfs_file *fd ) { GET_FIL_FP(fd); @@ -240,7 +241,7 @@ static sint32_t myfatfs_eof( const struct vfs_file *fd ) return f_eof( fp ); } -static sint32_t myfatfs_tell( const struct vfs_file *fd ) +static int32_t myfatfs_tell( const struct vfs_file *fd ) { GET_FIL_FP(fd); @@ -249,7 +250,7 @@ static sint32_t myfatfs_tell( const struct vfs_file *fd ) return f_tell( fp ); } -static sint32_t myfatfs_flush( const struct vfs_file *fd ) +static int32_t myfatfs_flush( const struct vfs_file *fd ) { GET_FIL_FP(fd); @@ -267,7 +268,7 @@ static uint32_t myfatfs_fsize( const struct vfs_file *fd ) return f_size( fp ); } -static sint32_t myfatfs_ferrno( const struct vfs_file *fd ) +static int32_t myfatfs_ferrno( const struct vfs_file *fd ) { return -last_result; } @@ -280,24 +281,24 @@ static sint32_t myfatfs_ferrno( const struct vfs_file *fd ) const struct myvfs_dir *mydd = (const struct myvfs_dir *)descr; \ DIR *dp = (DIR *)&(mydd->dp); -static sint32_t myfatfs_closedir( const struct vfs_dir *dd ) +static int32_t myfatfs_closedir( const struct vfs_dir *dd ) { GET_DIR_DP(dd); last_result = f_closedir( dp ); // free descriptor memory - c_free( (void *)dd ); + free( (void *)dd ); return last_result == FR_OK ? VFS_RES_OK : VFS_RES_ERR; } static void myfatfs_fill_stat( const FILINFO *fno, struct vfs_stat *buf ) { - c_memset( buf, 0, sizeof( struct vfs_stat ) ); + memset( buf, 0, sizeof( struct vfs_stat ) ); // fill in supported stat entries - c_strncpy( buf->name, fno->fname, FS_OBJ_NAME_LEN+1 ); + strncpy( buf->name, fno->fname, FS_OBJ_NAME_LEN+1 ); buf->name[FS_OBJ_NAME_LEN] = '\0'; buf->size = fno->fsize; buf->is_dir = fno->fattrib & AM_DIR ? 1 : 0; @@ -316,7 +317,7 @@ static void myfatfs_fill_stat( const FILINFO *fno, struct vfs_stat *buf ) buf->tm_valid = 1; } -static sint32_t myfatfs_readdir( const struct vfs_dir *dd, struct vfs_stat *buf ) +static int32_t myfatfs_readdir( const struct vfs_dir *dd, struct vfs_stat *buf ) { GET_DIR_DP(dd); FILINFO fno; @@ -340,19 +341,19 @@ static sint32_t myfatfs_readdir( const struct vfs_dir *dd, struct vfs_stat *buf static vfs_vol *myfatfs_mount( const char *name, int num ) { struct myvfs_vol *vol; - const size_t len = c_strlen( name ); + const size_t len = strlen( name ); // num argument specifies the physical driver = SS/CS pin number for this sd card if (num >= 0) { for (int i = 0; i < NUM_LOGICAL_DRIVES; i++) { - if (0 == c_strncmp( name, volstr[i], c_strlen( volstr[i] ) )) { + if (0 == strncmp( name, volstr[i], strlen( volstr[i] ) )) { VolToPart[i].pd = num; } } } - if (vol = c_malloc( sizeof( struct myvfs_vol ) )) { - if (vol->ldrname = c_strdup( name )) { + if (vol = malloc( sizeof( struct myvfs_vol ) )) { + if (vol->ldrname = strdup( name )) { if (FR_OK == (last_result = f_mount( &(vol->fs), name, 1 ))) { vol->vfs_vol.fs_type = VFS_FS_FATFS; vol->vfs_vol.fns = &myfatfs_vol_fns; @@ -362,29 +363,29 @@ static vfs_vol *myfatfs_mount( const char *name, int num ) } if (vol) { - if (vol->ldrname) c_free( vol->ldrname ); - c_free( vol ); + if (vol->ldrname) free( vol->ldrname ); + free( vol ); } return NULL; } static BYTE myfatfs_mode2flag( const char *mode ) { - if (c_strlen( mode ) == 1) { - if(c_strcmp( mode, "w" ) == 0) + if (strlen( mode ) == 1) { + if(strcmp( mode, "w" ) == 0) return FA_WRITE | FA_CREATE_ALWAYS; - else if (c_strcmp( mode, "r" ) == 0) + else if (strcmp( mode, "r" ) == 0) return FA_READ | FA_OPEN_EXISTING; - else if (c_strcmp( mode, "a" ) == 0) + else if (strcmp( mode, "a" ) == 0) return FA_WRITE | FA_OPEN_ALWAYS; else return FA_READ | FA_OPEN_EXISTING; - } else if (c_strlen( mode ) == 2) { - if (c_strcmp( mode, "r+" ) == 0) + } else if (strlen( mode ) == 2) { + if (strcmp( mode, "r+" ) == 0) return FA_READ | FA_WRITE | FA_OPEN_EXISTING; - else if (c_strcmp( mode, "w+" ) == 0) + else if (strcmp( mode, "w+" ) == 0) return FA_READ | FA_WRITE | FA_CREATE_ALWAYS; - else if (c_strcmp( mode, "a+" ) ==0 ) + else if (strcmp( mode, "a+" ) ==0 ) return FA_READ | FA_WRITE | FA_OPEN_ALWAYS; else return FA_READ | FA_OPEN_EXISTING; @@ -398,7 +399,7 @@ static vfs_file *myfatfs_open( const char *name, const char *mode ) struct myvfs_file *fd; const BYTE flags = myfatfs_mode2flag( mode ); - if (fd = c_malloc( sizeof( struct myvfs_file ) )) { + if (fd = malloc( sizeof( struct myvfs_file ) )) { if (FR_OK == (last_result = f_open( &(fd->fp), name, flags ))) { // skip to end of file for append mode if (flags & FA_OPEN_ALWAYS) @@ -408,7 +409,7 @@ static vfs_file *myfatfs_open( const char *name, const char *mode ) fd->vfs_file.fns = &myfatfs_file_fns; return (vfs_file *)fd; } else { - c_free( fd ); + free( fd ); } } @@ -419,20 +420,20 @@ static vfs_dir *myfatfs_opendir( const char *name ) { struct myvfs_dir *dd; - if (dd = c_malloc( sizeof( struct myvfs_dir ) )) { + if (dd = malloc( sizeof( struct myvfs_dir ) )) { if (FR_OK == (last_result = f_opendir( &(dd->dp), name ))) { dd->vfs_dir.fs_type = VFS_FS_FATFS; dd->vfs_dir.fns = &myfatfs_dir_fns; return (vfs_dir *)dd; } else { - c_free( dd ); + free( dd ); } } return NULL; } -static sint32_t myfatfs_stat( const char *name, struct vfs_stat *buf ) +static int32_t myfatfs_stat( const char *name, struct vfs_stat *buf ) { FILINFO fno; @@ -445,28 +446,28 @@ static sint32_t myfatfs_stat( const char *name, struct vfs_stat *buf ) } } -static sint32_t myfatfs_remove( const char *name ) +static int32_t myfatfs_remove( const char *name ) { last_result = f_unlink( name ); return last_result == FR_OK ? VFS_RES_OK : VFS_RES_ERR; } -static sint32_t myfatfs_rename( const char *oldname, const char *newname ) +static int32_t myfatfs_rename( const char *oldname, const char *newname ) { last_result = f_rename( oldname, newname ); return last_result == FR_OK ? VFS_RES_OK : VFS_RES_ERR; } -static sint32_t myfatfs_mkdir( const char *name ) +static int32_t myfatfs_mkdir( const char *name ) { last_result = f_mkdir( name ); return last_result == FR_OK ? VFS_RES_OK : VFS_RES_ERR; } -static sint32_t myfatfs_fsinfo( uint32_t *total, uint32_t *used ) +static int32_t myfatfs_fsinfo( uint32_t *total, uint32_t *used ) { DWORD free_clusters; FATFS *fatfs; @@ -480,21 +481,21 @@ static sint32_t myfatfs_fsinfo( uint32_t *total, uint32_t *used ) return last_result == FR_OK ? VFS_RES_OK : VFS_RES_ERR; } -static sint32_t myfatfs_chdrive( const char *name ) +static int32_t myfatfs_chdrive( const char *name ) { last_result = f_chdrive( name ); return last_result == FR_OK ? VFS_RES_OK : VFS_RES_ERR; } -static sint32_t myfatfs_chdir( const char *name ) +static int32_t myfatfs_chdir( const char *name ) { last_result = f_chdir( name ); return last_result == FR_OK ? VFS_RES_OK : VFS_RES_ERR; } -static sint32_t myfatfs_errno( void ) +static int32_t myfatfs_errno( void ) { return -last_result; } @@ -515,10 +516,10 @@ vfs_fs_fns *myfatfs_realm( const char *inname, char **outname, int set_current_d // logical drive is specified, check if it's one of ours for (int i = 0; i < FF_VOLUMES; i++) { - size_t volstr_len = c_strlen( volstr[i] ); - if (0 == c_strncmp( &(inname[1]), volstr[i], volstr_len )) { - oname = c_strdup( inname ); - c_strcpy( oname, volstr[i] ); + size_t volstr_len = strlen( volstr[i] ); + if (0 == strncmp( &(inname[1]), volstr[i], volstr_len )) { + oname = strdup( inname ); + strcpy( oname, volstr[i] ); oname[volstr_len] = ':'; *outname = oname; @@ -529,11 +530,11 @@ vfs_fs_fns *myfatfs_realm( const char *inname, char **outname, int set_current_d } else { // no logical drive in patchspec, are we current drive? if (is_current_drive) { - *outname = c_strdup( inname ); + *outname = strdup( inname ); return &myfatfs_fs_fns; } } - if (set_current_drive) is_current_drive = FALSE; + if (set_current_drive) is_current_drive = false; return NULL; } diff --git a/app/http/httpclient.c b/app/http/httpclient.c index 51c209d8..1419d597 100644 --- a/app/http/httpclient.c +++ b/app/http/httpclient.c @@ -13,7 +13,7 @@ */ #include "osapi.h" -#include "../libc/c_stdio.h" +#include #include "user_interface.h" #include "espconn.h" #include "mem.h" diff --git a/app/include/pm/pmSleep.h b/app/include/pm/pmSleep.h index eca8590a..093c7dc5 100644 --- a/app/include/pm/pmSleep.h +++ b/app/include/pm/pmSleep.h @@ -6,7 +6,7 @@ #include "gpio.h" #include "platform.h" #include "task/task.h" -#include "c_string.h" +#include #if defined(DEVELOP_VERSION) #define PMSLEEP_DEBUG diff --git a/app/include/user_config.h b/app/include/user_config.h index e87adbc7..4866e6a9 100644 --- a/app/include/user_config.h +++ b/app/include/user_config.h @@ -255,6 +255,11 @@ extern void luaL_dbgbreak(void); #define COAP_DEBUG #endif /* DEVELOP_VERSION */ + +#if !defined(LUA_CROSS_COMPILER) && !defined(dbg_printf) +extern void dbg_printf(const char *fmt, ...); +#endif + #ifdef NODE_DEBUG #define NODE_DBG dbg_printf #else diff --git a/app/include/user_mbedtls.h b/app/include/user_mbedtls.h index f6614f4c..cb3b7923 100644 --- a/app/include/user_mbedtls.h +++ b/app/include/user_mbedtls.h @@ -274,8 +274,10 @@ //#define MBEDTLS_MEMORY_ALIGN_MULTIPLE 4 /**< Align on multiples of this value */ //#define MBEDTLS_PLATFORM_STD_MEM_HDR /**< Header to include if MBEDTLS_PLATFORM_NO_STD_FUNCTIONS is defined. Don't define if no header is needed. */ -#define MBEDTLS_PLATFORM_STD_CALLOC pvPortCalloc /**< Default allocator to use, can be undefined */ -#define MBEDTLS_PLATFORM_STD_FREE vPortFree /**< Default free to use, can be undefined */ +extern void *mbedtls_calloc_wrap(size_t n, size_t sz); +#define MBEDTLS_PLATFORM_STD_CALLOC mbedtls_calloc_wrap /**< Default allocator to use, can be undefined */ +extern void mbedtls_free_wrap(void *p); +#define MBEDTLS_PLATFORM_STD_FREE mbedtls_free_wrap /**< Default free to use, can be undefined */ //#define MBEDTLS_PLATFORM_STD_EXIT exit /**< Default exit to use, can be undefined */ //#define MBEDTLS_PLATFORM_STD_TIME time /**< Default time to use, can be undefined. MBEDTLS_HAVE_TIME must be enabled */ //#define MBEDTLS_PLATFORM_STD_FPRINTF fprintf /**< Default fprintf to use, can be undefined */ diff --git a/app/libc/c_ctype.c b/app/libc/c_ctype.c deleted file mode 100644 index 90f8d709..00000000 --- a/app/libc/c_ctype.c +++ /dev/null @@ -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){} diff --git a/app/libc/c_ctype.h b/app/libc/c_ctype.h deleted file mode 100644 index c7d443f2..00000000 --- a/app/libc/c_ctype.h +++ /dev/null @@ -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_ */ diff --git a/app/libc/c_errno.h b/app/libc/c_errno.h deleted file mode 100644 index b0d79e44..00000000 --- a/app/libc/c_errno.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef __c_errno_h -#define __c_errno_h - -#include -// #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 */ - diff --git a/app/libc/c_fcntl.h b/app/libc/c_fcntl.h deleted file mode 100644 index 84bba18e..00000000 --- a/app/libc/c_fcntl.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef __c_fcntl_h -#define __c_fcntl_h - -#include - -#endif - -/* end of c_fcntl.h */ - diff --git a/app/libc/c_limits.h b/app/libc/c_limits.h deleted file mode 100644 index 226a5bbc..00000000 --- a/app/libc/c_limits.h +++ /dev/null @@ -1,58 +0,0 @@ -#ifndef __c_limits_h -#define __c_limits_h - -#include -#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 */ - diff --git a/app/libc/c_locale.h b/app/libc/c_locale.h deleted file mode 100644 index 2b5f5b64..00000000 --- a/app/libc/c_locale.h +++ /dev/null @@ -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 - -#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_ */ diff --git a/app/libc/c_math.h b/app/libc/c_math.h deleted file mode 100644 index ef18ee79..00000000 --- a/app/libc/c_math.h +++ /dev/null @@ -1,62 +0,0 @@ -#ifndef _C_MATH_H_ -#define _C_MATH_H_ -#include - -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_ */ diff --git a/app/libc/c_signal.h b/app/libc/c_signal.h deleted file mode 100644 index dab308f4..00000000 --- a/app/libc/c_signal.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef _C_SIGNAL_H_ -#define _C_SIGNAL_H_ - -#include - -#endif /* _C_SIGNAL_H_ */ diff --git a/app/libc/c_stdarg.h b/app/libc/c_stdarg.h deleted file mode 100644 index 1fa745d3..00000000 --- a/app/libc/c_stdarg.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef __c_stdarg_h -#define __c_stdarg_h - -#if defined(__GNUC__) - -#include - -#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 */ diff --git a/app/libc/c_stddef.h b/app/libc/c_stddef.h deleted file mode 100644 index f87717c4..00000000 --- a/app/libc/c_stddef.h +++ /dev/null @@ -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. ) also define */ - /* the unsigned integral type of the result of the sizeof operator. */ -#endif - -#undef NULL /* others (e.g. ) also define */ -#define NULL 0 - /* null pointer constant. */ - -#endif - -/* end of c_stddef.h */ - diff --git a/app/libc/c_stdint.h b/app/libc/c_stdint.h deleted file mode 100644 index 734c5f67..00000000 --- a/app/libc/c_stdint.h +++ /dev/null @@ -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 */ - - - diff --git a/app/libc/c_stdio.h b/app/libc/c_stdio.h deleted file mode 100644 index 4c9a9bf3..00000000 --- a/app/libc/c_stdio.h +++ /dev/null @@ -1,105 +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 - -extern void dbg_printf(const char *fmt, ...) __attribute__ ((format (printf, 1, 2))); - -#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_ */ diff --git a/app/libc/c_stdlib.h b/app/libc/c_stdlib.h deleted file mode 100644 index 171c7fbb..00000000 --- a/app/libc/c_stdlib.h +++ /dev/null @@ -1,64 +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 - -#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); - -//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_ */ diff --git a/app/libc/c_string.c b/app/libc/c_string.c deleted file mode 100644 index 011a1899..00000000 --- a/app/libc/c_string.c +++ /dev/null @@ -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 - * - * 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 - * - * 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 */ -} - diff --git a/app/libc/c_string.h b/app/libc/c_string.h deleted file mode 100644 index cced15ba..00000000 --- a/app/libc/c_string.h +++ /dev/null @@ -1,50 +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_memmove os_memmove -#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_ */ diff --git a/app/libc/c_math.c b/app/libc/math.c similarity index 72% rename from app/libc/c_math.c rename to app/libc/math.c index 2eb44687..3c469209 100644 --- a/app/libc/c_math.c +++ b/app/libc/math.c @@ -1,6 +1,5 @@ -#include "c_math.h" -#include "c_types.h" -#include "user_config.h" +#include +#include double floor(double x) { @@ -135,103 +134,3 @@ double pow(double x, double y) double res = ldexp(z, m); return flipsignal ? -res : res; } - -#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 diff --git a/app/libc/c_stdio.c b/app/libc/stdio.c similarity index 95% rename from app/libc/c_stdio.c rename to app/libc/stdio.c index 3b634613..0b03ef8f 100644 --- a/app/libc/c_stdio.c +++ b/app/libc/stdio.c @@ -1,61 +1,28 @@ -#include "c_stdio.h" -// #include "driver/uart.h" +#include int c_stdin = 999; int c_stdout = 1000; int c_stderr = 1001; -// FILE *c_fopen(const char *_name, const char *_type){ -// } -// FILE *c_freopen(const char *_name, const char *_type, FILE *_f){ -// } -// FILE *c_tmpfile(void){ -// } - -// int c_putchar(int c){ -// } - -// int c_printf(const char *c, ...){ -// } - -// int c_sprintf(char *c, const char *s, ...){ -// } - -// int c_fprintf(FILE *f, const char *s, ...){ -// } -// int c_fscanf(FILE *f, const char *s, ...){ -// } -// int c_fclose(FILE *f){ -// } -// int c_fflush(FILE *f){ -// } -// int c_setvbuf(FILE *f, char *c, int d, size_t t){ -// } -// void c_clearerr(FILE *f){ -// } -// int c_fseek(FILE *f, long l, int d){ -// } -// long c_ftell( FILE *f){ -// } -// int c_fputs(const char *c, FILE *f){ -// } -// char *c_fgets(char *c, int d, FILE *f){ -// } -// int c_ungetc(int d, FILE *f){ -// } -// size_t c_fread(void *p, size_t _size, size_t _n, FILE *f){ -// } -// size_t c_fwrite(const void *p, size_t _size, size_t _n, FILE *f){ -// } -// int c_feof(FILE *f){ -// } -// int c_ferror(FILE *f){ -// } -// int c_getc(FILE *f){ -// } - #if defined( LUA_NUMBER_INTEGRAL ) +#include + +int sprintf(char *s, const char *fmt, ...) +{ + int n; + va_list arg; + va_start(arg, fmt); + n = ets_vsprintf(s, fmt, arg); + va_end(arg); + return n; +} + +int vsprintf (char *d, const char *s, va_list ap) +{ + return ets_vsprintf(d, s, ap); +} + #else #define FLOATINGPT 1 @@ -97,8 +64,7 @@ int c_stderr = 1001; * SUCH DAMAGE. * */ -//#include -#include "c_string.h" +#include char * strichr(char *p, int c) @@ -147,8 +113,7 @@ strichr(char *p, int c) * SUCH DAMAGE. * */ -//#include -#include "c_string.h" +#include #define FMT_RJUST 0 #define FMT_LJUST 1 @@ -221,10 +186,8 @@ str_fmt(char *p, int size, int fmt) * SUCH DAMAGE. * */ -//#include -//#include -#include "c_string.h" -#include "c_ctype.h" +#include +#include void strtoupper(char *p) @@ -269,10 +232,9 @@ strtoupper(char *p) */ //#include -//#include +#include +#include //#include -#include "c_string.h" -typedef unsigned int u_int32_t; typedef unsigned int u_int; typedef unsigned long u_long; typedef int32_t register_t; @@ -371,7 +333,7 @@ _atob (u_quad_t *vp, char *p, int base) * converts p to binary result in vp, rtn 1 on success */ int -atob(u_int32_t *vp, char *p, int base) +atob(uint32_t *vp, char *p, int base) { u_quad_t v; @@ -554,13 +516,10 @@ gethex(int32_t *vp, char *p, int n) * */ //#include -//#include -//#include -//#include //#include -#include "c_stdarg.h" -#include "c_string.h" -#include "c_ctype.h" +#include +#include +#include /* * int vsprintf(d,s,ap) @@ -1091,10 +1050,9 @@ exponent(char *p, int exp, int fmtch) } return (p); } -#endif /* FLOATINGPT */ -int c_sprintf(char *s, const char *fmt, ...) +int sprintf(char *s, const char *fmt, ...) { int n; va_list arg; @@ -1104,4 +1062,6 @@ int c_sprintf(char *s, const char *fmt, ...) return n; } +#endif /* FLOATINGPT */ + #endif diff --git a/app/libc/c_stdlib.c b/app/libc/stdlib.c similarity index 92% rename from app/libc/c_stdlib.c rename to app/libc/stdlib.c index 4f39cc86..6299eceb 100644 --- a/app/libc/c_stdlib.c +++ b/app/libc/stdlib.c @@ -1,23 +1,13 @@ -//#include "user_interface.h" #include "user_config.h" -#ifdef LUA_CROSS_COMPILER - #include #include #include + +#ifdef LUA_CROSS_COMPILER #define ICACHE_RODATA_ATTR #define TRUE 1 #define FALSE 0 - -#else - -#include "c_stdlib.h" -#include "c_types.h" -#include "c_string.h" -#include <_ansi.h> -//#include -//#include "mprec.h" #endif double powersOf10[] ICACHE_STORE_ATTR ICACHE_RODATA_ATTR = /* Table giving binary powers of 10. Entry */ { @@ -32,7 +22,7 @@ double powersOf10[] ICACHE_STORE_ATTR ICACHE_RODATA_ATTR = /* Table giving bin 1.0e256 }; -double c_strtod(const char *string, char **endPtr) +double strtod(const char *string, char **endPtr) { int maxExponent = 511; /* Largest possible base 10 exponent. Any * exponent larger than this will already @@ -256,10 +246,3 @@ done: } return fraction; } - -// 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){ -// } diff --git a/app/lua/lapi.c b/app/lua/lapi.c index 29df306b..6139e2f2 100644 --- a/app/lua/lapi.c +++ b/app/lua/lapi.c @@ -10,9 +10,8 @@ #include "lua.h" -//#include C_HEADER_ASSERT -#include C_HEADER_MATH -#include C_HEADER_STRING +#include +#include #include "lapi.h" #include "ldebug.h" #include "ldo.h" @@ -463,7 +462,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)); } diff --git a/app/lua/lauxlib.c b/app/lua/lauxlib.c index de2ae489..773d01a3 100644 --- a/app/lua/lauxlib.c +++ b/app/lua/lauxlib.c @@ -7,18 +7,19 @@ #define LUAC_CROSS_FILE #include "lua.h" -#include C_HEADER_CTYPE +#include #ifdef __MINGW__ #include #else #ifdef _MSC_VER //msvc #defines errno, which interferes with our #include macro #undef errno #endif -#include C_HEADER_ERRNO +#include #endif -#include C_HEADER_STDIO -#include C_HEADER_STDLIB -#include C_HEADER_STRING +#include +#include +#include +#include #ifndef LUA_CROSS_COMPILER #include "vfs.h" #include "user_interface.h" @@ -100,7 +101,7 @@ static void scanBlocks (void) { for (i=0; p ;i++) { s = memcmp(p->mark, marker, MARKSIZE) ? '<' : ' '; e = memcmp(cast(char *, p+1) + p->size, marker, MARKSIZE) ? '>' : ' '; - c_printf("%4u %p %8lu %c %c\n", i, p, p->size, s, e); + printf("%4u %p %8lu %c %c\n", i, p, p->size, s, e); ASSERT(p->next); p = p->next; } @@ -136,7 +137,7 @@ static void freeblock (MemHeader *block) { p->next = next; } fillmem(block, sizeof(MemHeader) + size + MARKSIZE); /* erase block */ - c_free(block); /* actually free block */ + free(block); /* actually free block */ mc.numblocks--; /* update counts */ mc.total -= size; } @@ -163,7 +164,7 @@ void *debug_realloc (void *b, size_t oldsize, size_t size) { MemHeader *newblock; size_t commonsize = (oldsize < size) ? oldsize : size; size_t realsize = sizeof(MemHeader) + size + MARKSIZE; - newblock = cast(MemHeader *, c_malloc(realsize)); /* alloc a new block */ + newblock = cast(MemHeader *, malloc(realsize)); /* alloc a new block */ if (newblock == NULL) return NULL; /* really out of memory? */ if (block) { @@ -190,7 +191,7 @@ void *debug_realloc (void *b, size_t oldsize, size_t size) { /* }====================================================================== */ #else -#define this_realloc(p,os,s) c_realloc(p,s) +#define this_realloc(p,os,s) realloc(p,s) #endif /* DEBUG_ALLOCATOR */ /* @@ -205,7 +206,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)", @@ -262,7 +263,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)); @@ -352,7 +353,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); @@ -533,10 +534,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' */ @@ -552,8 +553,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); @@ -634,7 +635,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)); } @@ -650,7 +651,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 */ } @@ -730,14 +731,14 @@ static const char *getF (lua_State *L, void *ud, size_t *size) { *size = 1; return "\n"; } - if (c_feof(lf->f)) return NULL; - *size = c_fread(lf->buff, 1, sizeof(lf->buff), lf->f); + if (feof(lf->f)) return NULL; + *size = fread(lf->buff, 1, sizeof(lf->buff), lf->f); return (*size > 0) ? lf->buff : NULL; } static int errfile (lua_State *L, const char *what, int fnameindex) { - const char *serr = c_strerror(errno); + const char *serr = strerror(errno); const char *filename = lua_tostring(L, fnameindex) + 1; lua_pushfstring(L, "cannot %s %s: %s", what, filename, serr); lua_remove(L, fnameindex); @@ -757,27 +758,27 @@ LUALIB_API int luaL_loadfile (lua_State *L, const char *filename) { } else { lua_pushfstring(L, "@%s", filename); - lf.f = c_fopen(filename, "r"); + lf.f = fopen(filename, "r"); if (lf.f == NULL) return errfile(L, "open", fnameindex); } - c = c_getc(lf.f); + c = getc(lf.f); if (c == '#') { /* Unix exec. file? */ lf.extraline = 1; - while ((c = c_getc(lf.f)) != EOF && c != '\n') ; /* skip first line */ - if (c == '\n') c = c_getc(lf.f); + while ((c = getc(lf.f)) != EOF && c != '\n') ; /* skip first line */ + if (c == '\n') c = getc(lf.f); } if (c == LUA_SIGNATURE[0] && filename) { /* binary file? */ - lf.f = c_freopen(filename, "rb", lf.f); /* reopen in binary mode */ + lf.f = freopen(filename, "rb", lf.f); /* reopen in binary mode */ if (lf.f == NULL) return errfile(L, "reopen", fnameindex); /* skip eventual `#!...' */ - while ((c = c_getc(lf.f)) != EOF && c != LUA_SIGNATURE[0]) {} + while ((c = getc(lf.f)) != EOF && c != LUA_SIGNATURE[0]) {} lf.extraline = 0; } - c_ungetc(c, lf.f); + ungetc(c, lf.f); status = lua_load(L, getF, &lf, lua_tostring(L, -1)); - readstatus = c_ferror(lf.f); - if (filename) c_fclose(lf.f); /* close file (even in case of errors) */ + readstatus = ferror(lf.f); + if (filename) fclose(lf.f); /* close file (even in case of errors) */ if (readstatus) { lua_settop(L, fnameindex); /* ignore results from `lua_load' */ return errfile(L, "read", fnameindex); @@ -788,8 +789,6 @@ LUALIB_API int luaL_loadfile (lua_State *L, const char *filename) { #else -#include C_HEADER_FCNTL - typedef struct LoadFSF { int extraline; int f; @@ -893,7 +892,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); } @@ -928,7 +927,7 @@ static void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize) { #ifdef DEBUG_ALLOCATOR return (void *)this_realloc(ptr, osize, nsize); #else - c_free(ptr); + free(ptr); return NULL; #endif } @@ -988,7 +987,7 @@ LUALIB_API void luaL_dbgbreak(void) { static int panic (lua_State *L) { (void)L; /* to avoid warnings */ #if defined(LUA_USE_STDIO) - c_fprintf(c_stderr, "PANIC: unprotected error in call to Lua API (%s)\n", + fprintf(c_stderr, "PANIC: unprotected error in call to Lua API (%s)\n", lua_tostring(L, -1)); #else luai_writestringerror("PANIC: unprotected error in call to Lua API (%s)\n", diff --git a/app/lua/lauxlib.h b/app/lua/lauxlib.h index 333fa4e2..09dbd2c0 100644 --- a/app/lua/lauxlib.h +++ b/app/lua/lauxlib.h @@ -8,15 +8,9 @@ #ifndef lauxlib_h #define lauxlib_h - #include "lua.h" -#ifdef LUA_CROSS_COMPILER #include -#else -#include "c_stdio.h" -#endif - #if defined(LUA_COMPAT_GETN) LUALIB_API int (luaL_getn) (lua_State *L, int t); diff --git a/app/lua/lbaselib.c b/app/lua/lbaselib.c index 16ee1cf9..02b69bc8 100644 --- a/app/lua/lbaselib.c +++ b/app/lua/lbaselib.c @@ -11,9 +11,9 @@ #define LUAC_CROSS_FILE #include "lua.h" -#include C_HEADER_STDIO -#include C_HEADER_STRING -#include C_HEADER_STDLIB +#include +#include +#include #include "lauxlib.h" #include "lualib.h" #include "lrotable.h" @@ -41,16 +41,16 @@ static int luaB_print (lua_State *L) { return luaL_error(L, LUA_QL("tostring") " must return a string to " LUA_QL("print")); #if defined(LUA_USE_STDIO) - if (i>1) c_fputs("\t", c_stdout); - c_fputs(s, c_stdout); + if (i>1) fputs("\t", c_stdout); + 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 */ } #if defined(LUA_USE_STDIO) - c_fputs("\n", c_stdout); + fputs("\n", c_stdout); #else luai_writeline(); #endif @@ -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? */ diff --git a/app/lua/lcode.c b/app/lua/lcode.c index ed53def7..5fa535ce 100644 --- a/app/lua/lcode.c +++ b/app/lua/lcode.c @@ -10,7 +10,7 @@ #define LUAC_CROSS_FILE #include "lua.h" -#include C_HEADER_STDLIB +#include #include "lcode.h" #include "ldebug.h" @@ -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); } diff --git a/app/lua/ldblib.c b/app/lua/ldblib.c index d41721bd..d3926e9d 100644 --- a/app/lua/ldblib.c +++ b/app/lua/ldblib.c @@ -10,9 +10,9 @@ #define LUAC_CROSS_FILE #include "lua.h" -#include C_HEADER_STDIO -#include C_HEADER_STDLIB -#include C_HEADER_STRING +#include +#include +#include #include "lauxlib.h" #include "lualib.h" @@ -33,7 +33,7 @@ static int db_getstrings (lua_State *L) { GCObject *o; #ifndef LUA_CROSS_COMPILER const char *opt = lua_tolstring (L, 1, &n); - if (n==3 && c_memcmp(opt, "ROM", 4) == 0) { + if (n==3 && memcmp(opt, "ROM", 4) == 0) { if (G(L)->ROstrt.hash == NULL) return 0; tb = &G(L)->ROstrt; @@ -155,24 +155,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 */ } @@ -261,9 +261,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; } @@ -340,19 +340,19 @@ static int db_debug (lua_State *L) { for (;;) { char buffer[LUA_MAXINPUT]; #if defined(LUA_USE_STDIO) - c_fputs("lua_debug> ", c_stderr); - if (c_fgets(buffer, sizeof(buffer), c_stdin) == 0 || + fputs("lua_debug> ", c_stderr); + if (fgets(buffer, sizeof(buffer), c_stdin) == 0 || #else // 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); - c_fputs("\n", c_stderr); + fputs(lua_tostring(L, -1), c_stderr); + fputs("\n", c_stderr); #else luai_writestringerror("%s\n", lua_tostring(L, -1)); #endif diff --git a/app/lua/ldebug.c b/app/lua/ldebug.c index 1441e69d..eab0ef62 100644 --- a/app/lua/ldebug.c +++ b/app/lua/ldebug.c @@ -10,7 +10,7 @@ #define LUAC_CROSS_FILE #include "lua.h" -#include C_HEADER_STRING +#include #include "lapi.h" #include "lcode.h" @@ -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; diff --git a/app/lua/ldo.c b/app/lua/ldo.c index 6414a61b..86126f0a 100644 --- a/app/lua/ldo.c +++ b/app/lua/ldo.c @@ -11,7 +11,7 @@ #define LUAC_CROSS_FILE #include "lua.h" -#include C_HEADER_STRING +#include #include "ldebug.h" #include "ldo.h" diff --git a/app/lua/ldump.c b/app/lua/ldump.c index 7681fed6..db2a0362 100644 --- a/app/lua/ldump.c +++ b/app/lua/ldump.c @@ -9,7 +9,7 @@ #define LUAC_CROSS_FILE #include "lua.h" -#include C_HEADER_STRING +#include #include "lobject.h" #include "lstate.h" @@ -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; isizecode; 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; diff --git a/app/lua/lflash.c b/app/lua/lflash.c index 17218fe1..ba1c46d3 100644 --- a/app/lua/lflash.c +++ b/app/lua/lflash.c @@ -17,10 +17,10 @@ #include "vfs.h" #include "uzlib.h" -#include "c_fcntl.h" -#include "c_stdio.h" -#include "c_stdlib.h" -#include "c_string.h" +#include +#include +#include +#include /* * Flash memory is a fixed memory addressable block that is serially allocated by the @@ -388,13 +388,13 @@ static void put_byte (uint8_t value) { } -static uint8_t recall_byte (uint offset) { +static uint8_t recall_byte (unsigned offset) { if(offset > DICTIONARY_WINDOW || offset >= out->ndx) flash_error("invalid dictionary offset on inflate"); /* ndx starts at 1. Need relative to 0 */ - uint n = out->ndx - offset; - uint pos = n % WRITE_BLOCKSIZE; - uint blockNo = out->ndx / WRITE_BLOCKSIZE - n / WRITE_BLOCKSIZE; + unsigned n = out->ndx - offset; + unsigned pos = n % WRITE_BLOCKSIZE; + unsigned blockNo = out->ndx / WRITE_BLOCKSIZE - n / WRITE_BLOCKSIZE; return out->block[blockNo]->byte[pos]; } @@ -429,7 +429,7 @@ int procFirstPass (void) { fh->flash_size > flashSize || out->flagsLen != 1 + (out->flashLen/WORDSIZE - 1) / BITS_PER_WORD) flash_error("LFS length mismatch"); - out->flags = luaM_newvector(out->L, out->flagsLen, uint); + out->flags = luaM_newvector(out->L, out->flagsLen, unsigned); } /* update running CRC */ @@ -512,7 +512,7 @@ static int loadLFS (lua_State *L) { in->len = vfs_size(in->fd); if (in->len <= 200 || /* size of an empty luac output */ vfs_lseek(in->fd, in->len-4, VFS_SEEK_SET) != in->len-4 || - vfs_read(in->fd, &out->len, sizeof(uint)) != sizeof(uint)) + vfs_read(in->fd, &out->len, sizeof(unsigned)) != sizeof(unsigned)) flash_error("read error on LFS image file"); vfs_lseek(in->fd, 0, VFS_SEEK_SET); diff --git a/app/lua/lfunc.c b/app/lua/lfunc.c index fe502f6b..a9c6e2d9 100644 --- a/app/lua/lfunc.c +++ b/app/lua/lfunc.c @@ -9,7 +9,7 @@ #define LUAC_CROSS_FILE #include "lua.h" -#include C_HEADER_STRING +#include #include "lfunc.h" #include "lgc.h" @@ -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); diff --git a/app/lua/lgc.c b/app/lua/lgc.c index 645703d6..5f1c28fa 100644 --- a/app/lua/lgc.c +++ b/app/lua/lgc.c @@ -9,7 +9,7 @@ #define LUAC_CROSS_FILE #include "lua.h" -#include C_HEADER_STRING +#include #include "ldebug.h" #include "ldo.h" @@ -173,8 +173,8 @@ static int traversetable (global_State *g, Table *h) { } 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) | @@ -333,7 +333,7 @@ static l_mem propagatemark (global_State *g) { (proto_isreadonly(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); diff --git a/app/lua/llex.c b/app/lua/llex.c index d38c993b..4a8edbc3 100644 --- a/app/lua/llex.c +++ b/app/lua/llex.c @@ -10,9 +10,9 @@ #define LUAC_CROSS_FILE #include "lua.h" -#include C_HEADER_CTYPE -#include C_HEADER_LOCALE -#include C_HEADER_STRING +#include +#include +#include #include "ldo.h" #include "llex.h" @@ -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); diff --git a/app/lua/llimits.h b/app/lua/llimits.h index fec09c2e..21db9d3d 100644 --- a/app/lua/llimits.h +++ b/app/lua/llimits.h @@ -8,8 +8,6 @@ #define llimits_h -//#include "c_limits.h" - #include "lua.h" typedef LUAI_UINT32 lu_int32; diff --git a/app/lua/lmathlib.c b/app/lua/lmathlib.c index 2a10b6e9..26967652 100644 --- a/app/lua/lmathlib.c +++ b/app/lua/lmathlib.c @@ -10,8 +10,8 @@ #define LUAC_CROSS_FILE #include "lua.h" -#include C_HEADER_STDLIB -#include C_HEADER_MATH +#include +#include #include "lauxlib.h" #include "lualib.h" diff --git a/app/lua/lmem.h b/app/lua/lmem.h index 4766454f..4ef11997 100644 --- a/app/lua/lmem.h +++ b/app/lua/lmem.h @@ -8,12 +8,6 @@ #define lmem_h -//#ifdef LUA_CROSS_COMPILER -//#include -//#else -//#include "c_stddef.h" -//#endif - #include "llimits.h" #include "lua.h" diff --git a/app/lua/loadlib.c b/app/lua/loadlib.c index b8cc6911..a4ab42c9 100644 --- a/app/lua/loadlib.c +++ b/app/lua/loadlib.c @@ -14,9 +14,9 @@ #define LUAC_CROSS_FILE #include "lua.h" -#include C_HEADER_STDLIB -#include C_HEADER_STRING -#include C_HEADER_FCNTL +#include +#include +#include #ifndef LUA_CROSS_COMPILER #include "vfs.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'; @@ -333,9 +333,9 @@ static int ll_loadlib (lua_State *L) { */ #ifdef LUA_CROSS_COMPILER static int readable (const char *filename) { - FILE *f = c_fopen(filename, "r"); /* try to open file */ + FILE *f = fopen(filename, "r"); /* try to open file */ if (f == NULL) return 0; /* open failed */ - c_fclose(f); + fclose(f); return 1; } #else @@ -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; } @@ -406,7 +406,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); @@ -431,7 +431,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); @@ -559,7 +559,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) */ diff --git a/app/lua/lobject.c b/app/lua/lobject.c index 9f733970..214a3658 100644 --- a/app/lua/lobject.c +++ b/app/lua/lobject.c @@ -10,9 +10,9 @@ #define LUAC_CROSS_FILE #include "lua.h" -#include C_HEADER_STDIO -#include C_HEADER_STRING -#include C_HEADER_STDLIB +#include +#include +#include #include "ldo.h" #include "lmem.h" @@ -116,7 +116,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++; @@ -137,7 +137,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); @@ -167,7 +167,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; } @@ -206,7 +206,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" */ @@ -214,26 +214,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, "\"]"); } } } diff --git a/app/lua/lobject.h b/app/lua/lobject.h index e2173831..7741ddbf 100644 --- a/app/lua/lobject.h +++ b/app/lua/lobject.h @@ -8,11 +8,7 @@ #ifndef lobject_h #define lobject_h -#ifdef LUA_CROSS_COMPILER #include -#else -#include "c_stdarg.h" -#endif #include "llimits.h" #include "lua.h" diff --git a/app/lua/lparser.c b/app/lua/lparser.c index ae955359..097d1a84 100644 --- a/app/lua/lparser.c +++ b/app/lua/lparser.c @@ -10,7 +10,7 @@ #define LUAC_CROSS_FILE #include "lua.h" -#include C_HEADER_STRING +#include #include "lcode.h" #include "ldebug.h" diff --git a/app/lua/lrotable.c b/app/lua/lrotable.c index 5a73ef75..a2b809af 100644 --- a/app/lua/lrotable.c +++ b/app/lua/lrotable.c @@ -2,7 +2,7 @@ #define LUAC_CROSS_FILE #include "lua.h" -#include C_HEADER_STRING +#include #include "lrotable.h" #include "lauxlib.h" #include "lstring.h" @@ -100,7 +100,7 @@ const TValue* luaR_findentry(ROTable *rotable, TString *key, unsigned *ppos) { unsigned l = key ? key->tsv.len : sizeof("__metatable")-1; if (pentry) { - if (j >= 0 && !c_strcmp(pentry[j].key, strkey)) { + if (j >= 0 && !strcmp(pentry[j].key, strkey)) { if (ppos) *ppos = j; //dbg_printf("%3d hit %p %s\n", (hash>>2) & (LA_LINES-1), rotable, strkey); @@ -112,11 +112,11 @@ const TValue* luaR_findentry(ROTable *rotable, TString *key, unsigned *ppos) { * is included so a "on\0" has a mask of 0xFFFFFF and "a\0" has 0xFFFF. */ unsigned name4, mask4 = l > 2 ? (~0u) : (~0u)>>((3-l)*8); - c_memcpy(&name4, strkey, sizeof(name4)); + memcpy(&name4, strkey, sizeof(name4)); for(;pentry->key != NULL; i++, pentry++) { if (((*(unsigned *)pentry->key ^ name4) & mask4) == 0 && - !c_strcmp(pentry->key, strkey)) { + !strcmp(pentry->key, strkey)) { //dbg_printf("%p %s hit after %d probes \n", rotable, strkey, (int)(rotable-pentry)); if (ppos) *ppos = i; diff --git a/app/lua/lstring.c b/app/lua/lstring.c index be459187..5803b059 100644 --- a/app/lua/lstring.c +++ b/app/lua/lstring.c @@ -11,7 +11,7 @@ #define LUAC_CROSS_FILE #include "lua.h" -#include C_HEADER_STRING +#include #include "lmem.h" #include "lobject.h" @@ -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; @@ -106,7 +106,7 @@ LUAI_FUNC TString *luaS_newlstr (lua_State *L, const char *str, size_t l) { 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; @@ -131,7 +131,7 @@ LUAI_FUNC TString *luaS_newlstr (lua_State *L, const char *str, size_t l) { /* New additions to the RAM strt are tagged as readonly if the string address * is in the CTEXT segment (target only, not luac.cross) */ int readonly = (lua_is_ptr_in_ro_area(str) && l+1 > sizeof(char**) && - l == c_strlen(str) ? LUAS_READONLY_STRING : LUAS_REGULAR_STRING); + l == strlen(str) ? LUAS_READONLY_STRING : LUAS_REGULAR_STRING); return newlstr(L, str, l, h, readonly); /* not found */ } diff --git a/app/lua/lstring.h b/app/lua/lstring.h index 227489c2..366f92b3 100644 --- a/app/lua/lstring.h +++ b/app/lua/lstring.h @@ -17,7 +17,7 @@ #define sizeudata(u) (sizeof(union Udata)+(u)->len) -#define luaS_new(L, s) (luaS_newlstr(L, s, c_strlen(s))) +#define luaS_new(L, s) (luaS_newlstr(L, s, strlen(s))) #define luaS_newliteral(L, s) (luaS_newlstr(L, "" s, \ (sizeof(s)/sizeof(char))-1)) diff --git a/app/lua/lstrlib.c b/app/lua/lstrlib.c index 2bcd5e84..72b503da 100644 --- a/app/lua/lstrlib.c +++ b/app/lua/lstrlib.c @@ -10,8 +10,8 @@ #define LUAC_CROSS_FILE #include "lua.h" -#include C_HEADER_STDIO -#include C_HEADER_STRING +#include +#include #include "lauxlib.h" #include "lualib.h" @@ -352,7 +352,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; } @@ -447,7 +447,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; @@ -496,7 +496,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) { @@ -723,7 +723,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 */ @@ -736,7 +736,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; @@ -744,9 +744,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'; } @@ -773,23 +773,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 @@ -800,7 +800,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); @@ -808,7 +808,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; } } @@ -817,7 +817,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); diff --git a/app/lua/ltable.c b/app/lua/ltable.c index 8417fc14..93fb1db1 100644 --- a/app/lua/ltable.c +++ b/app/lua/ltable.c @@ -23,8 +23,8 @@ #define LUAC_CROSS_FILE #include "lua.h" -#include C_HEADER_MATH -#include C_HEADER_STRING +#include +#include #include "ldebug.h" #include "ldo.h" @@ -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]); } diff --git a/app/lua/ltm.c b/app/lua/ltm.c index b1d9b667..6f5962db 100644 --- a/app/lua/ltm.c +++ b/app/lua/ltm.c @@ -10,7 +10,7 @@ #define LUAC_CROSS_FILE #include "lua.h" -#include C_HEADER_STRING +#include #include "lobject.h" #include "lstate.h" diff --git a/app/lua/lua.c b/app/lua/lua.c index cb226b51..81b04751 100644 --- a/app/lua/lua.c +++ b/app/lua/lua.c @@ -5,10 +5,9 @@ */ -// #include "c_signal.h" -#include "c_stdio.h" -#include "c_stdlib.h" -#include "c_string.h" +#include +#include +#include #include "user_interface.h" #include "user_version.h" #include "driver/readline.h" @@ -32,9 +31,9 @@ static const char *progname = LUA_PROGNAME; static void l_message (const char *pname, const char *msg) { #if defined(LUA_USE_STDIO) - if (pname) c_fprintf(c_stderr, "%s: ", pname); - c_fprintf(c_stderr, "%s\n", msg); - c_fflush(c_stderr); + if (pname) fprintf(c_stderr, "%s: ", pname); + fprintf(c_stderr, "%s\n", msg); + fflush(c_stderr); #else if (pname) luai_writestringerror("%s: ", pname); luai_writestringerror("%s\n", msg); @@ -122,7 +121,7 @@ static int dofsfile (lua_State *L, const char *name) { 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); } @@ -148,7 +147,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("")) - 1); - if (c_strstr(msg, LUA_QL("")) == tp) { + if (strstr(msg, LUA_QL("")) == tp) { lua_pop(L, 1); return 1; } @@ -214,7 +213,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; } @@ -307,7 +306,7 @@ int lua_main (int argc, char **argv) { gLoad.L = L; gLoad.firstline = 1; gLoad.done = 0; - gLoad.line = c_malloc(LUA_MAXINPUT); + gLoad.line = malloc(LUA_MAXINPUT); gLoad.len = LUA_MAXINPUT; gLoad.line_position = 0; gLoad.prmt = get_prompt(L, 1); @@ -324,7 +323,7 @@ int lua_main (int argc, char **argv) { int lua_put_line(const char *s, size_t l) { if (s == NULL || ++l > LUA_MAXINPUT || gLoad.line_position > 0) return 0; - c_memcpy(gLoad.line, s, l); + memcpy(gLoad.line, s, l); gLoad.line[l] = '\0'; gLoad.line_position = l; gLoad.done = 1; @@ -336,7 +335,7 @@ void lua_handle_input (bool force) { while (gLoad.L && (force || readline (&gLoad))) { NODE_DBG("Handle Input: first=%u, pos=%u, len=%u, actual=%u, line=%s\n", gLoad.firstline, - gLoad.line_position, gLoad.len, c_strlen(gLoad.line), gLoad.line); + gLoad.line_position, gLoad.len, strlen(gLoad.line), gLoad.line); dojob (&gLoad); force = false; } @@ -357,7 +356,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 `=' ? */ @@ -401,8 +400,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 @@ -468,7 +467,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); continue; } else { load->done = 1; diff --git a/app/lua/lua.h b/app/lua/lua.h index b6f6c413..a4b5c4e2 100644 --- a/app/lua/lua.h +++ b/app/lua/lua.h @@ -11,16 +11,10 @@ #ifdef LUAC_CROSS_FILE #include "luac_cross.h" #endif -#ifdef LUA_CROSS_COMPILER -#include -#include -#include -#else -#include "c_stdarg.h" -#include "c_stddef.h" -#include "c_types.h" -#include -#endif +#include +#include "stdarg.h" +#include "stddef.h" +#include "ctype.h" #include "luaconf.h" diff --git a/app/lua/luac_cross/Makefile b/app/lua/luac_cross/Makefile index da133ec5..984d2b65 100644 --- a/app/lua/luac_cross/Makefile +++ b/app/lua/luac_cross/Makefile @@ -8,7 +8,7 @@ summary ?= @true -CCFLAGS:= -I.. -I../../include -I../../libc -I../../uzlib +CCFLAGS:= -I.. -I../../include -I../../uzlib LDFLAGS:= -L$(SDK_DIR)/lib -L$(SDK_DIR)/ld -lm -ldl -Wl,-Map=mapfile CCFLAGS += -Wall @@ -33,13 +33,12 @@ LUASRC := lapi.c lauxlib.c lbaselib.c lcode.c ldblib.c ldebug.c lmathlib.c lmem.c loadlib.c lobject.c lopcodes.c lparser.c \ lrotable.c lstate.c lstring.c lstrlib.c ltable.c ltablib.c \ ltm.c lundump.c lvm.c lzio.c -LIBCSRC := c_stdlib.c UZSRC := uzlib_deflate.c crc32.c # # This relies on the files being unique on the vpath # -SRC := $(LUACSRC) $(LUASRC) $(LIBCSRC) $(UZSRC) +SRC := $(LUACSRC) $(LUASRC) $(UZSRC) vpath %.c .:..:../../libc:../../uzlib ODIR := .output/$(TARGET)/$(FLAVOR)/obj diff --git a/app/lua/luac_cross/mingw32-Makefile.mak b/app/lua/luac_cross/mingw32-Makefile.mak index b3b6b7f6..ebfa4a5b 100644 --- a/app/lua/luac_cross/mingw32-Makefile.mak +++ b/app/lua/luac_cross/mingw32-Makefile.mak @@ -38,12 +38,11 @@ LUASRC := lapi.c lauxlib.c lbaselib.c lcode.c ldblib.c ldebug.c lmathlib.c lmem.c loadlib.c lobject.c lopcodes.c lparser.c \ lrotable.c lstate.c lstring.c lstrlib.c ltable.c ltablib.c \ ltm.c lundump.c lvm.c lzio.c -LIBCSRC := c_stdlib.c UZSRC := uzlib_deflate.c crc32.c # # This relies on the files being unique on the vpath # -SRC := $(LUACSRC) $(LUASRC) $(LIBCSRC) $(UZSRC) +SRC := $(LUACSRC) $(LUASRC) $(UZSRC) vpath %.c .:..:../../libc:../../uzlib diff --git a/app/lua/luaconf.h b/app/lua/luaconf.h index ddea8a76..3170b0dd 100644 --- a/app/lua/luaconf.h +++ b/app/lua/luaconf.h @@ -8,13 +8,9 @@ #ifndef lconfig_h #define lconfig_h -#ifdef LUA_CROSS_COMPILER #include #include -#else -#include "c_limits.h" -#include "c_stddef.h" -#endif +#include #include "user_config.h" /* @@ -262,11 +258,7 @@ #define lua_stdin_is_tty() isatty(0) #elif defined(LUA_WIN) #include -#ifdef LUA_CROSS_COMPILER #include -#else -#include "c_stdio.h" -#endif #define lua_stdin_is_tty() _isatty(_fileno(stdin)) #else @@ -317,11 +309,11 @@ #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, c_stdout), fflush(c_stdout), /* show prompt */ \ + fgets(b, LUA_MAXINPUT, c_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) @@ -342,8 +334,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) /* @@ -622,31 +614,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 -#ifdef _MSC_VER //what's wrong with stdlib strtod? #define lua_str2number(s,p) strtod((s), (p)) -#else -#define lua_str2number(s,p) c_strtod((s), (p)) -#endif #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 -#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)) @@ -801,7 +785,7 @@ union luai_Cast { double l_d; long l_l; }; #include #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); } @@ -821,7 +805,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) diff --git a/app/lua/lundump.c b/app/lua/lundump.c index 0baedf29..4ccb4677 100644 --- a/app/lua/lundump.c +++ b/app/lua/lundump.c @@ -9,7 +9,7 @@ #define LUAC_CROSS_FILE #include "lua.h" -#include C_HEADER_STRING +#include #include "ldebug.h" #include "ldo.h" @@ -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; diff --git a/app/lua/lundump.h b/app/lua/lundump.h index 219b980d..eaa58597 100644 --- a/app/lua/lundump.h +++ b/app/lua/lundump.h @@ -7,11 +7,7 @@ #ifndef lundump_h #define lundump_h -#ifdef LUA_CROSS_COMPILER #include -#else -#include "c_stdint.h" -#endif #include "lobject.h" #include "lzio.h" diff --git a/app/lua/lvm.c b/app/lua/lvm.c index a0243d6c..11cc6ce1 100644 --- a/app/lua/lvm.c +++ b/app/lua/lvm.c @@ -10,9 +10,9 @@ #define LUAC_CROSS_FILE #include "lua.h" -#include C_HEADER_STDIO -#include C_HEADER_STRING -#include C_HEADER_MATH +#include +#include +#include #include "ldebug.h" #include "ldo.h" @@ -252,10 +252,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? */ @@ -363,7 +363,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)); diff --git a/app/lua/lzio.c b/app/lua/lzio.c index 84d811c3..16108489 100644 --- a/app/lua/lzio.c +++ b/app/lua/lzio.c @@ -10,7 +10,7 @@ #define LUAC_CROSS_FILE #include "lua.h" -#include C_HEADER_STRING +#include #include "llimits.h" #include "lmem.h" @@ -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; diff --git a/app/mbedtls/library/platform.c b/app/mbedtls/library/platform.c index dd3dde99..aa88fc1a 100644 --- a/app/mbedtls/library/platform.c +++ b/app/mbedtls/library/platform.c @@ -25,15 +25,6 @@ #include MBEDTLS_CONFIG_FILE #endif -// XXX Espressif are hacks sometimes. This is BS, but is taken from -// the mbedtls platform.c from their SDK. Really, this should go -// somewhere else. Note that the prototype here for vPortFree differs (!) -// from the one in sdk-overrides.h. That's above my pay grade. -// --nwf; 2018 Feb 18 -extern void *pvPortCalloc(unsigned int count, unsigned int size); -extern void vPortFree( void *pv ); - - #if defined(MBEDTLS_PLATFORM_C) #include "mbedtls/platform.h" diff --git a/app/mbedtls/platform/mbedtls_mem.c b/app/mbedtls/platform/mbedtls_mem.c new file mode 100644 index 00000000..9281362f --- /dev/null +++ b/app/mbedtls/platform/mbedtls_mem.c @@ -0,0 +1,4 @@ +#include + +void *mbedtls_calloc(size_t n, size_t sz) { return calloc(n, sz); } +void mbedtls_free(void *p) { free(p); } diff --git a/app/mbedtls/platform/memcompat.c b/app/mbedtls/platform/memcompat.c new file mode 100644 index 00000000..ff765d7c --- /dev/null +++ b/app/mbedtls/platform/memcompat.c @@ -0,0 +1,3 @@ +#include +void *mbedtls_calloc_wrap(size_t n, size_t sz) { return calloc(n, sz); } +void mbedtls_free_wrap(void *p) { free(p); } diff --git a/app/modules/ads1115.c b/app/modules/ads1115.c index 72181ba4..950f1a1d 100644 --- a/app/modules/ads1115.c +++ b/app/modules/ads1115.c @@ -8,7 +8,7 @@ #include "lauxlib.h" #include "platform.h" #include "osapi.h" -#include "c_stdlib.h" +#include //*************************************************************************** diff --git a/app/modules/adxl345.c b/app/modules/adxl345.c index 2628bdc9..f18a1122 100644 --- a/app/modules/adxl345.c +++ b/app/modules/adxl345.c @@ -6,8 +6,8 @@ #include "module.h" #include "lauxlib.h" #include "platform.h" -#include "c_stdlib.h" -#include "c_string.h" +#include +#include static const uint32_t adxl345_i2c_id = 0; static const uint8_t adxl345_i2c_addr = 0x53; diff --git a/app/modules/apa102.c b/app/modules/apa102.c index b4db4368..8179662b 100644 --- a/app/modules/apa102.c +++ b/app/modules/apa102.c @@ -1,5 +1,5 @@ -#include "c_stdlib.h" -#include "c_string.h" +#include +#include #include "lualib.h" #include "lauxlib.h" #include "lrotable.h" diff --git a/app/modules/bit.c b/app/modules/bit.c index 0c2b2e3b..70cbfef0 100644 --- a/app/modules/bit.c +++ b/app/modules/bit.c @@ -6,7 +6,7 @@ #include "module.h" -#include "c_limits.h" +#include #include "lauxlib.h" diff --git a/app/modules/bloom.c b/app/modules/bloom.c index 514c347e..922e3ed2 100644 --- a/app/modules/bloom.c +++ b/app/modules/bloom.c @@ -6,6 +6,7 @@ #include "module.h" #include "lauxlib.h" +#include #include "c_types.h" #include "../crypto/sha2.h" diff --git a/app/modules/bme280.c b/app/modules/bme280.c index b642e8b9..e8525921 100644 --- a/app/modules/bme280.c +++ b/app/modules/bme280.c @@ -11,7 +11,7 @@ #include "module.h" #include "lauxlib.h" #include "platform.h" -#include "c_math.h" +#include /****************************************************/ /**\name registers definition */ diff --git a/app/modules/bme680.c b/app/modules/bme680.c index dfc1c0e9..85efbe20 100644 --- a/app/modules/bme680.c +++ b/app/modules/bme680.c @@ -9,7 +9,7 @@ #include "module.h" #include "lauxlib.h" #include "platform.h" -#include "c_math.h" +#include #include "bme680_defs.h" diff --git a/app/modules/bmp085.c b/app/modules/bmp085.c index 4ccc9e85..97eeadfb 100644 --- a/app/modules/bmp085.c +++ b/app/modules/bmp085.c @@ -1,8 +1,8 @@ #include "module.h" #include "lauxlib.h" #include "platform.h" -#include "c_stdlib.h" -#include "c_string.h" +#include +#include static const uint32_t bmp085_i2c_id = 0; static const uint8_t bmp085_i2c_addr = 0x77; diff --git a/app/modules/coap.c b/app/modules/coap.c index 2b18b6b2..f810154e 100644 --- a/app/modules/coap.c +++ b/app/modules/coap.c @@ -4,8 +4,8 @@ #include "lauxlib.h" #include "platform.h" -#include "c_string.h" -#include "c_stdlib.h" +#include +#include #include "c_types.h" #include "mem.h" @@ -36,13 +36,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); @@ -52,11 +52,11 @@ static void coap_received(void *arg, char *pdata, unsigned short len) 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 + // 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) @@ -83,7 +83,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 *)calloc(1,sizeof(struct espconn)); if(!pesp_conn) return luaL_error(L, "not enough memory"); @@ -93,9 +93,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 *)calloc(1,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"); } @@ -131,9 +131,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; } @@ -170,7 +170,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"); @@ -235,7 +235,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 ) @@ -243,7 +243,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); @@ -271,7 +271,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); @@ -303,7 +303,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] ) @@ -354,7 +354,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); @@ -362,7 +362,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"); @@ -371,7 +371,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"); } @@ -422,7 +422,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; @@ -447,13 +447,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 *)calloc(1,sizeof(coap_luser_entry)); h = h->next; if(h == NULL) return luaL_error(L, "not enough memory"); diff --git a/app/modules/color_utils.c b/app/modules/color_utils.c index 6c37cd8c..78a5a58f 100644 --- a/app/modules/color_utils.c +++ b/app/modules/color_utils.c @@ -2,9 +2,9 @@ #include "lauxlib.h" #include "lmem.h" #include "platform.h" -#include "c_stdlib.h" -#include "c_math.h" -#include "c_string.h" +#include +#include +#include #include "user_interface.h" #include "osapi.h" diff --git a/app/modules/color_utils.h b/app/modules/color_utils.h index c937cd7f..42a911b1 100644 --- a/app/modules/color_utils.h +++ b/app/modules/color_utils.h @@ -5,9 +5,9 @@ #include "lauxlib.h" #include "lmem.h" #include "platform.h" -#include "c_stdlib.h" -#include "c_math.h" -#include "c_string.h" +#include +#include +#include #include "user_interface.h" #include "osapi.h" diff --git a/app/modules/cron.c b/app/modules/cron.c index 60175d2f..5196c003 100644 --- a/app/modules/cron.c +++ b/app/modules/cron.c @@ -5,7 +5,7 @@ #include "lmem.h" #include "user_interface.h" #include "c_types.h" -#include "c_string.h" +#include #include "ets_sys.h" #include "time.h" #include "rtc/rtctime.h" @@ -176,7 +176,7 @@ static int lcron_reset(lua_State *L) { luaL_unref(L, LUA_REGISTRYINDEX, cronent_list[i]); } cronent_count = 0; - os_free(cronent_list); + free(cronent_list); cronent_list = 0; return 0; } diff --git a/app/modules/crypto.c b/app/modules/crypto.c index e648c82e..f55b7f2e 100644 --- a/app/modules/crypto.c +++ b/app/modules/crypto.c @@ -1,11 +1,11 @@ // Module for cryptography -#include +#include #include "module.h" #include "lauxlib.h" #include "platform.h" #include "c_types.h" -#include "c_stdlib.h" +#include #include "vfs.h" #include "../crypto/digests.h" #include "../crypto/mech.h" diff --git a/app/modules/encoder.c b/app/modules/encoder.c index b3c17985..53c08b74 100644 --- a/app/modules/encoder.c +++ b/app/modules/encoder.c @@ -3,7 +3,7 @@ #include "module.h" #include "lauxlib.h" #include "lmem.h" -#include "c_string.h" +#include #define BASE64_INVALID '\xff' #define BASE64_PADDING '=' #define ISBASE64(c) (unbytes64[c] != BASE64_INVALID) @@ -19,7 +19,7 @@ static uint8 *toBase64 ( lua_State* L, const uint8 *msg, size_t *len){ int buf_size = (n + 2) / 3 * 4; // estimated encoded size uint8 * q, *out = (uint8 *)luaM_malloc(L, buf_size); 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]; @@ -46,7 +46,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) { diff --git a/app/modules/enduser_setup.c b/app/modules/enduser_setup.c index addef5f4..caf676d4 100644 --- a/app/modules/enduser_setup.c +++ b/app/modules/enduser_setup.c @@ -38,9 +38,9 @@ #include "lauxlib.h" #include "lmem.h" #include "platform.h" -#include "c_stdlib.h" -#include "c_stdio.h" -#include "c_string.h" +#include +#include +#include #include "ctype.h" #include "user_interface.h" #include "espconn.h" @@ -248,7 +248,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); @@ -266,7 +266,7 @@ static void enduser_setup_check_station(void *p) /* No IP Address yet, so check the reported status */ uint8_t curr_status = wifi_station_get_connect_status(); char buf[20]; - c_sprintf(buf, "status=%d,chan=%d", curr_status, currChan); + sprintf(buf, "status=%d,chan=%d", curr_status, currChan); ENDUSER_SETUP_DEBUG(buf); if (curr_status == 2 || curr_status == 3 || curr_status == 4) @@ -290,7 +290,7 @@ static void enduser_setup_check_station(void *p) return; } - c_sprintf (ipaddr, "%d.%d.%d.%d", IP2STR(&ip.ip.addr)); + sprintf (ipaddr, "%d.%d.%d.%d", IP2STR(&ip.ip.addr)); state->success = 1; state->lastStationStatus = 5; /* We have an IP Address, so the status is 5 (as of SDK 1.5.1) */ @@ -298,7 +298,7 @@ static void enduser_setup_check_station(void *p) #if ENDUSER_SETUP_DEBUG_ENABLE char debuginfo[100]; - c_sprintf(debuginfo, "AP_CHAN: %d, STA_CHAN: %d", state->softAPchannel, currChan); + sprintf(debuginfo, "AP_CHAN: %d, STA_CHAN: %d", state->softAPchannel, currChan); ENDUSER_SETUP_DEBUG(debuginfo); #endif @@ -462,27 +462,27 @@ static int enduser_setup_http_load_payload(void) char cl_hdr[30]; size_t ce_len = 0; - c_sprintf(cl_hdr, http_header_content_len_fmt, file_len); - size_t cl_len = c_strlen(cl_hdr); + sprintf(cl_hdr, http_header_content_len_fmt, file_len); + size_t cl_len = strlen(cl_hdr); if (!f || err == VFS_RES_ERR || err2 == VFS_RES_ERR) { ENDUSER_SETUP_DEBUG("Unable to load file enduser_setup.html, loading default HTML..."); - c_sprintf(cl_hdr, http_header_content_len_fmt, sizeof(enduser_setup_html_default)); - cl_len = c_strlen(cl_hdr); + sprintf(cl_hdr, http_header_content_len_fmt, sizeof(enduser_setup_html_default)); + cl_len = strlen(cl_hdr); int html_len = LITLEN(enduser_setup_html_default); if (enduser_setup_html_default[0] == 0x1f && enduser_setup_html_default[1] == 0x8b) { - ce_len = c_strlen(http_html_gzip_contentencoding); + ce_len = strlen(http_html_gzip_contentencoding); html_len = enduser_setup_html_default_len; /* Defined in enduser_setup/enduser_setup.html.gz.def.h by xxd -i */ ENDUSER_SETUP_DEBUG("Content is gzipped"); } int payload_len = LITLEN(http_header_200) + cl_len + ce_len + html_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) { @@ -490,17 +490,17 @@ static int enduser_setup_http_load_payload(void) } 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); if (ce_len > 0) { - offset += c_sprintf(state->http_payload_data + offset, http_html_gzip_contentencoding, ce_len); + offset += sprintf(state->http_payload_data + offset, http_html_gzip_contentencoding, ce_len); } - c_memcpy(&(state->http_payload_data[offset]), &(cl_hdr), cl_len); + memcpy(&(state->http_payload_data[offset]), &(cl_hdr), cl_len); offset += cl_len; - c_memcpy(&(state->http_payload_data[offset]), &(enduser_setup_html_default), sizeof(enduser_setup_html_default)); + memcpy(&(state->http_payload_data[offset]), &(enduser_setup_html_default), sizeof(enduser_setup_html_default)); return 1; } @@ -510,13 +510,13 @@ static int enduser_setup_http_load_payload(void) if (magic[0] == 0x1f && magic[1] == 0x8b) { - ce_len = c_strlen(http_html_gzip_contentencoding); + ce_len = strlen(http_html_gzip_contentencoding); ENDUSER_SETUP_DEBUG("Content is gzipped"); } int payload_len = LITLEN(http_header_200) + cl_len + ce_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) { @@ -527,15 +527,15 @@ static int enduser_setup_http_load_payload(void) 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); if (ce_len > 0) { - offset += c_sprintf(state->http_payload_data + offset, http_html_gzip_contentencoding, ce_len); + offset += sprintf(state->http_payload_data + offset, http_html_gzip_contentencoding, ce_len); } - c_memcpy(&(state->http_payload_data[offset]), &(cl_hdr), cl_len); + memcpy(&(state->http_payload_data[offset]), &(cl_hdr), cl_len); offset += cl_len; vfs_read(f, &(state->http_payload_data[offset]), file_len); vfs_close(f); @@ -658,18 +658,18 @@ static void enduser_setup_free_keypairs(struct keypairs_t *kp) { if (kp->keypairs != NULL) { for (int i = 0; i < kp->keypairs_nb * 2; i++) { - os_free(kp->keypairs[i]); + free(kp->keypairs[i]); } } - os_free(kp->keypairs); - os_free(kp); + free(kp->keypairs); + free(kp); } static struct keypairs_t * enduser_setup_alloc_keypairs(int kp_number ){ - struct keypairs_t *kp = os_malloc(sizeof(struct keypairs_t)); + struct keypairs_t *kp = malloc(sizeof(struct keypairs_t)); os_memset(kp, 0, sizeof(struct keypairs_t)); - kp->keypairs = os_malloc(kp_number * 2 * sizeof(char *)); + kp->keypairs = malloc(kp_number * 2 * sizeof(char *)); kp->keypairs_nb = kp_number; return kp; } @@ -691,7 +691,7 @@ static struct keypairs_t *enduser_setup_get_keypairs_from_form(char *form_body, int current_idx = 0; int err; - char *body_copy = os_malloc(form_length+1); + char *body_copy = malloc(form_length+1); os_bzero(body_copy, form_length+1); os_memcpy(body_copy, form_body, form_length); char *tok = strtok(body_copy, "="); @@ -699,12 +699,12 @@ static struct keypairs_t *enduser_setup_get_keypairs_from_form(char *form_body, char last_tok = '='; while (tok) { size_t len = strlen(tok); - kp->keypairs[current_idx] = os_malloc(len + 1); + kp->keypairs[current_idx] = malloc(len + 1); err = enduser_setup_http_urldecode(kp->keypairs[current_idx], tok, len, len + 1); if (err) { ENDUSER_SETUP_DEBUG("Unable to decode parameter"); enduser_setup_free_keypairs(kp); - os_free(body_copy); + free(body_copy); return NULL; } @@ -712,7 +712,7 @@ static struct keypairs_t *enduser_setup_get_keypairs_from_form(char *form_body, if (current_idx > keypair_nb*2) { ENDUSER_SETUP_DEBUG("Too many keypairs!"); enduser_setup_free_keypairs(kp); - os_free(body_copy); + free(body_copy); return NULL; } @@ -724,7 +724,7 @@ static struct keypairs_t *enduser_setup_get_keypairs_from_form(char *form_body, last_tok='='; } } - os_free(body_copy); + free(body_copy); return kp; } @@ -765,7 +765,7 @@ static int enduser_setup_write_file_with_extra_configuration_data(char *form_bod int idx = 0; for( idx = 0; idx < kp->keypairs_nb*2; idx=idx+2){ char* to_write = kp->keypairs[idx]; - size_t length = c_strlen(to_write); + size_t length = strlen(to_write); vfs_write(p_file, "p.", 2); @@ -774,7 +774,7 @@ static int enduser_setup_write_file_with_extra_configuration_data(char *form_bod vfs_write(p_file, "=\"", 2); to_write = kp->keypairs[idx+1]; - length = c_strlen(to_write); + length = strlen(to_write); vfs_write(p_file, to_write, length); vfs_write(p_file, "\"\n", 2); @@ -824,14 +824,14 @@ 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)); cnf->threshold.rssi = -127; cnf->threshold.authmode = AUTH_OPEN; int err; err = enduser_setup_http_urldecode(cnf->ssid, name_str_start, name_str_len, sizeof(cnf->ssid)); err |= enduser_setup_http_urldecode(cnf->password, pwd_str_start, pwd_str_len, sizeof(cnf->password)); - if (err != 0 || c_strlen(cnf->ssid) == 0) + if (err != 0 || strlen(cnf->ssid) == 0) { ENDUSER_SETUP_DEBUG("Unable to decode HTTP parameter to valid password or SSID"); return 1; @@ -990,21 +990,21 @@ static void enduser_setup_serve_status(struct tcp_pcb *conn) ip_addr[0] = '\0'; if (curr_state == STATION_GOT_IP) { - c_sprintf (ip_addr, "%d.%d.%d.%d", IP2STR(&ip_info.ip.addr)); + sprintf (ip_addr, "%d.%d.%d.%d", IP2STR(&ip_info.ip.addr)); } - int state_len = c_strlen(s); - int ip_len = c_strlen(ip_addr); - int ssid_len = c_strlen(config.ssid); + int state_len = strlen(s); + int ip_len = strlen(ip_addr); + int ssid_len = strlen(config.ssid); int status_len = state_len + ssid_len + ip_len + 1; char status_buf[status_len]; memset(status_buf, 0, status_len); - status_len = c_sprintf(status_buf, s, config.ssid, ip_addr); + status_len = sprintf(status_buf, s, config.ssid, ip_addr); 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); } @@ -1014,11 +1014,11 @@ static void enduser_setup_serve_status(struct tcp_pcb *conn) default: { const char *s = states[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); } @@ -1048,13 +1048,13 @@ static void enduser_setup_serve_status_as_json (struct tcp_pcb *http_client) /* If IP address not yet available, get now */ if (strlen(ipaddr) == 0) { - c_sprintf(ipaddr, "%d.%d.%d.%d", IP2STR(&ip_info.ip.addr)); + sprintf(ipaddr, "%d.%d.%d.%d", IP2STR(&ip_info.ip.addr)); } - c_sprintf(json_payload, "{\"deviceid\":\"%s\", \"status\":%d}", ipaddr, curr_status); + sprintf(json_payload, "{\"deviceid\":\"%s\", \"status\":%d}", ipaddr, curr_status); } else { - c_sprintf(json_payload, "{\"deviceid\":\"%06X\", \"status\":%d}", system_get_chip_id(), curr_status); + sprintf(json_payload, "{\"deviceid\":\"%06X\", \"status\":%d}", system_get_chip_id(), curr_status); } const char fmt[] = @@ -1067,9 +1067,9 @@ static void enduser_setup_serve_status_as_json (struct tcp_pcb *http_client) "\r\n" "%s"; - int len = c_strlen(json_payload); - char buf[c_strlen(fmt) + NUMLEN(len) + len - 4]; - len = c_sprintf (buf, fmt, len, json_payload); + int len = strlen(json_payload); + char buf[strlen(fmt) + NUMLEN(len) + len - 4]; + len = sprintf (buf, fmt, len, json_payload); enduser_setup_http_serve_header (http_client, buf, len); } @@ -1098,15 +1098,15 @@ static void enduser_setup_handle_OPTIONS (struct tcp_pcb *http_client, char *dat int type = 0; - if (c_strncmp(data, "GET ", 4) == 0) + if (strncmp(data, "GET ", 4) == 0) { - if (c_strncmp(data + 4, "/aplist", 7) == 0 || c_strncmp(data + 4, "/setwifi?", 9) == 0 || c_strncmp(data + 4, "/status.json", 12) == 0) + if (strncmp(data + 4, "/aplist", 7) == 0 || strncmp(data + 4, "/setwifi?", 9) == 0 || strncmp(data + 4, "/status.json", 12) == 0) { - enduser_setup_http_serve_header (http_client, json, c_strlen(json)); + enduser_setup_http_serve_header (http_client, json, strlen(json)); return; } } - enduser_setup_http_serve_header (http_client, others, c_strlen(others)); + enduser_setup_http_serve_header (http_client, others, strlen(others)); return; } @@ -1114,7 +1114,7 @@ static void enduser_setup_handle_OPTIONS (struct tcp_pcb *http_client, char *dat static err_t enduser_setup_handle_POST(struct tcp_pcb *http_client, char* data, size_t data_len) { ENDUSER_SETUP_DEBUG("Handling POST"); - if (c_strncmp(data + 5, "/setwifi ", 9) == 0) // User clicked the submit button + if (strncmp(data + 5, "/setwifi ", 9) == 0) // User clicked the submit button { switch (enduser_setup_http_handle_credentials(data, data_len)) { @@ -1123,7 +1123,7 @@ static err_t enduser_setup_handle_POST(struct tcp_pcb *http_client, char* data, char* body=strstr(data, "\r\n\r\n"); char *content_length_str = strstr(data, "Content-Length: "); if( body != NULL && content_length_str != NULL){ - int bodylength = c_atoi(content_length_str + 16); + int bodylength = atoi(content_length_str + 16); body += 4; // length of the double CRLF found above enduser_setup_write_file_with_extra_configuration_data(body, bodylength); } @@ -1157,7 +1157,7 @@ static void free_scan_listeners (void) while (l) { next = l->next; - c_free (l); + free (l); l = next; } state->scan_listeners = 0; @@ -1177,7 +1177,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 @@ -1256,7 +1256,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 = 27 + 2*32 + 6; /* {"ssid":"","rssi":,"chan":} */ const size_t alloc_sz = hdr_sz + num_nets * max_entry_sz + 3; - char *http = os_zalloc (alloc_sz); + char *http = calloc (1, alloc_sz); if (!http) { goto serve_500; @@ -1282,26 +1282,26 @@ 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); const char entry_chan[] = ",\"chan\":"; strcpy (p, entry_chan); p += sizeof (entry_chan) -1; - p += c_sprintf (p, "%d", wn->channel); + p += sprintf (p, "%d", wn->channel); *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); ENDUSER_SETUP_DEBUG(http + hdr_sz); - c_free (http); + free (http); return; } @@ -1334,7 +1334,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 = calloc (1, p->tot_len + 1); if (!data) return ERR_MEM; @@ -1348,9 +1348,9 @@ static err_t enduser_setup_http_recvcb(void *arg, struct tcp_pcb *http_client, s ENDUSER_SETUP_DEBUG(data); #endif - if (c_strncmp(data, "GET ", 4) == 0) + if (strncmp(data, "GET ", 4) == 0) { - if (c_strncmp(data + 4, "/ ", 2) == 0 || c_strncmp(data + 4, "/?", 2) == 0) + if (strncmp(data + 4, "/ ", 2) == 0 || strncmp(data + 4, "/?", 2) == 0) { if (enduser_setup_http_serve_html(http_client) != 0) { @@ -1361,12 +1361,12 @@ 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", 7) == 0) + else if (strncmp(data + 4, "/aplist", 7) == 0) { /* Don't do an AP Scan while station is trying to connect to Wi-Fi */ if (state->connecting == 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); @@ -1398,16 +1398,16 @@ static err_t enduser_setup_http_recvcb(void *arg, struct tcp_pcb *http_client, s enduser_setup_http_serve_header(http_client, http_header_204, LITLEN(http_header_204)); } } - else if (c_strncmp(data + 4, "/status.json", 12) == 0) + else if (strncmp(data + 4, "/status.json", 12) == 0) { enduser_setup_serve_status_as_json(http_client); } - else if (c_strncmp(data + 4, "/status", 7) == 0) + else if (strncmp(data + 4, "/status", 7) == 0) { enduser_setup_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)) { @@ -1422,7 +1422,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", 13) == 0) + else if (strncmp(data + 4, "/generate_204", 13) == 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)); @@ -1433,11 +1433,11 @@ static err_t enduser_setup_http_recvcb(void *arg, struct tcp_pcb *http_client, s enduser_setup_http_serve_header(http_client, http_header_404, LITLEN(http_header_404)); } } - else if (c_strncmp(data, "OPTIONS ", 8) == 0) + else if (strncmp(data, "OPTIONS ", 8) == 0) { enduser_setup_handle_OPTIONS(http_client, data, data_len); } - else if (c_strncmp(data, "POST ", 5) == 0) + else if (strncmp(data, "POST ", 5) == 0) { enduser_setup_handle_POST(http_client, data, data_len); } @@ -1449,7 +1449,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; } @@ -1542,20 +1542,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 = state == NULL? 1 : state->softAPchannel; cnf.authmode = AUTH_OPEN; @@ -1567,7 +1567,7 @@ static void enduser_setup_ap_start(void) #if ENDUSER_SETUP_DEBUG_ENABLE char debuginfo[100]; - c_sprintf(debuginfo, "SSID: %s, CHAN: %d", cnf.ssid, cnf.channel); + sprintf(debuginfo, "SSID: %s, CHAN: %d", cnf.ssid, cnf.channel); ENDUSER_SETUP_DEBUG(debuginfo); #endif } @@ -1614,15 +1614,15 @@ 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; #if ENDUSER_SETUP_DEBUG_ENABLE - char *qname = c_malloc(qname_len + 12); + char *qname = malloc(qname_len + 12); if (qname != NULL) { - c_sprintf(qname, "DNS QUERY = %s", &(recv_data[12])); + sprintf(qname, "DNS QUERY = %s", &(recv_data[12])); uint32_t p; int i, j; @@ -1639,7 +1639,7 @@ static void enduser_setup_dns_recv_callback(void *arg, char *recv_data, unsigned } qname[i-1]='\0'; ENDUSER_SETUP_DEBUG(qname); - c_free(qname); + free(qname); } #endif @@ -1656,22 +1656,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; @@ -1684,7 +1684,7 @@ static void enduser_setup_dns_recv_callback(void *arg, char *recv_data, unsigned 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); @@ -1725,16 +1725,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; } @@ -1747,20 +1747,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_ALREADY_INITIALIZED, 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; @@ -1816,7 +1816,7 @@ static int enduser_setup_init(lua_State *L) } else { - state = (enduser_setup_state_t *) os_zalloc(sizeof(enduser_setup_state_t)); + state = (enduser_setup_state_t *) calloc(1, sizeof(enduser_setup_state_t)); if (state == NULL) { @@ -1824,7 +1824,7 @@ static int enduser_setup_init(lua_State *L) } else { - 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; diff --git a/app/modules/file.c b/app/modules/file.c index be5cdf44..03763b74 100644 --- a/app/modules/file.c +++ b/app/modules/file.c @@ -7,7 +7,7 @@ #include "c_types.h" #include "vfs.h" -#include "c_string.h" +#include #include @@ -190,7 +190,7 @@ static int file_open( lua_State* L ) const char *fname = luaL_checklstring( L, 1, &len ); const char *basename = vfs_basename( fname ); - luaL_argcheck(L, c_strlen(basename) <= FS_OBJ_NAME_LEN && c_strlen(fname) == len, 1, "filename invalid"); + luaL_argcheck(L, strlen(basename) <= FS_OBJ_NAME_LEN && strlen(fname) == len, 1, "filename invalid"); const char *mode = luaL_optstring(L, 2, "r"); @@ -303,7 +303,7 @@ static int file_exists( lua_State* L ) size_t len; const char *fname = luaL_checklstring( L, 1, &len ); const char *basename = vfs_basename( fname ); - luaL_argcheck(L, c_strlen(basename) <= FS_OBJ_NAME_LEN && c_strlen(fname) == len, 1, "filename invalid"); + luaL_argcheck(L, strlen(basename) <= FS_OBJ_NAME_LEN && strlen(fname) == len, 1, "filename invalid"); struct vfs_stat stat; lua_pushboolean(L, vfs_stat((char *)fname, &stat) == VFS_RES_OK ? 1 : 0); @@ -317,7 +317,7 @@ static int file_remove( lua_State* L ) size_t len; const char *fname = luaL_checklstring( L, 1, &len ); const char *basename = vfs_basename( fname ); - luaL_argcheck(L, c_strlen(basename) <= FS_OBJ_NAME_LEN && c_strlen(fname) == len, 1, "filename invalid"); + luaL_argcheck(L, strlen(basename) <= FS_OBJ_NAME_LEN && strlen(fname) == len, 1, "filename invalid"); vfs_remove((char *)fname); return 0; } @@ -343,11 +343,11 @@ static int file_rename( lua_State* L ) const char *oldname = luaL_checklstring( L, 1, &len ); const char *basename = vfs_basename( oldname ); - luaL_argcheck(L, c_strlen(basename) <= FS_OBJ_NAME_LEN && c_strlen(oldname) == len, 1, "filename invalid"); + luaL_argcheck(L, strlen(basename) <= FS_OBJ_NAME_LEN && strlen(oldname) == len, 1, "filename invalid"); const char *newname = luaL_checklstring( L, 2, &len ); basename = vfs_basename( newname ); - luaL_argcheck(L, c_strlen(basename) <= FS_OBJ_NAME_LEN && c_strlen(newname) == len, 2, "filename invalid"); + luaL_argcheck(L, strlen(basename) <= FS_OBJ_NAME_LEN && strlen(newname) == len, 2, "filename invalid"); if(0 <= vfs_rename( oldname, newname )){ lua_pushboolean(L, 1); @@ -362,7 +362,7 @@ static int file_stat( lua_State* L ) { size_t len; const char *fname = luaL_checklstring( L, 1, &len ); - luaL_argcheck( L, c_strlen(fname) <= FS_OBJ_NAME_LEN && c_strlen(fname) == len, 1, "filename invalid" ); + luaL_argcheck( L, strlen(fname) <= FS_OBJ_NAME_LEN && strlen(fname) == len, 1, "filename invalid" ); struct vfs_stat stat; if (vfs_stat( (char *)fname, &stat ) != VFS_RES_OK) { diff --git a/app/modules/gpio.c b/app/modules/gpio.c index 16b79365..43104413 100644 --- a/app/modules/gpio.c +++ b/app/modules/gpio.c @@ -7,7 +7,7 @@ #include "platform.h" #include "user_interface.h" #include "c_types.h" -#include "c_string.h" +#include #include "gpio.h" #include "hw_timer.h" diff --git a/app/modules/gpio_pulse.c b/app/modules/gpio_pulse.c index bc119744..35945862 100644 --- a/app/modules/gpio_pulse.c +++ b/app/modules/gpio_pulse.c @@ -4,7 +4,7 @@ #include "platform.h" #include "user_interface.h" #include "c_types.h" -#include "c_string.h" +#include #include "gpio.h" #include "hw_timer.h" #include "pin_map.h" diff --git a/app/modules/hdc1080.c b/app/modules/hdc1080.c index 095c3701..bc3f995f 100644 --- a/app/modules/hdc1080.c +++ b/app/modules/hdc1080.c @@ -7,9 +7,9 @@ #include "module.h" #include "lauxlib.h" #include "platform.h" -#include "c_stdlib.h" -#include "c_string.h" -#include "c_math.h" +#include +#include +#include static const uint32_t hdc1080_i2c_id = 0; static const uint8_t hdc1080_i2c_addr = 0x40; diff --git a/app/modules/hmc5883l.c b/app/modules/hmc5883l.c index 7c0108a0..5dd13535 100644 --- a/app/modules/hmc5883l.c +++ b/app/modules/hmc5883l.c @@ -6,8 +6,8 @@ #include "module.h" #include "lauxlib.h" #include "platform.h" -#include "c_stdlib.h" -#include "c_string.h" +#include +#include static const uint32_t hmc5883_i2c_id = 0; static const uint8_t hmc5883_i2c_addr = 0x1E; diff --git a/app/modules/http.c b/app/modules/http.c index 87f077ac..0b37d577 100644 --- a/app/modules/http.c +++ b/app/modules/http.c @@ -3,7 +3,7 @@ * vowstar@gmail.com * 2015-12-29 *******************************************************************************/ -#include +#include #include "module.h" #include "lauxlib.h" #include "platform.h" @@ -92,7 +92,7 @@ static void http_callback( char * response, int http_status, char ** full_respon } if (full_response_p && *full_response_p) { - c_free(*full_response_p); + free(*full_response_p); *full_response_p = NULL; } diff --git a/app/modules/hx711.c b/app/modules/hx711.c index 8f89ca7f..61198e33 100644 --- a/app/modules/hx711.c +++ b/app/modules/hx711.c @@ -4,8 +4,8 @@ #include "module.h" #include "lauxlib.h" #include "platform.h" -#include "c_stdlib.h" -#include "c_string.h" +#include +#include #include "user_interface.h" static uint8_t data_pin; static uint8_t clk_pin; diff --git a/app/modules/l3g4200d.c b/app/modules/l3g4200d.c index a6f2fd76..eef6d6d7 100644 --- a/app/modules/l3g4200d.c +++ b/app/modules/l3g4200d.c @@ -6,8 +6,8 @@ #include "module.h" #include "lauxlib.h" #include "platform.h" -#include "c_stdlib.h" -#include "c_string.h" +#include +#include static const uint32_t i2c_id = 0; static const uint8_t i2c_addr = 0x69; diff --git a/app/modules/mdns.c b/app/modules/mdns.c index 5afeb30e..8694c045 100644 --- a/app/modules/mdns.c +++ b/app/modules/mdns.c @@ -3,11 +3,11 @@ #include "module.h" #include "lauxlib.h" -#include "c_string.h" -#include "c_stdlib.h" +#include +#include +#include #include "c_types.h" -#include "mem.h" #include "lwip/ip_addr.h" #include "nodemcu_mdns.h" #include "user_interface.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); diff --git a/app/modules/mqtt.c b/app/modules/mqtt.c index 2a411e9f..49ae3e5b 100644 --- a/app/modules/mqtt.c +++ b/app/modules/mqtt.c @@ -4,8 +4,8 @@ #include "lauxlib.h" #include "platform.h" -#include "c_string.h" -#include "c_stdlib.h" +#include +#include #include "c_types.h" #include "mem.h" @@ -133,7 +133,7 @@ static void mqtt_socket_disconnected(void *arg) // tcp only } if(mud->mqtt_state.recv_buffer) { - c_free(mud->mqtt_state.recv_buffer); + free(mud->mqtt_state.recv_buffer); mud->mqtt_state.recv_buffer = NULL; } mud->mqtt_state.recv_buffer_size = 0; @@ -142,9 +142,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; } @@ -303,7 +303,7 @@ static void mqtt_socket_received(void *arg, char *pdata, unsigned short len) // Last buffer had so few byte that we could not determine message length. // Store in a local heap buffer and operate on this, as if was the regular pdata buffer. // Avoids having to repeat message size/overflow logic. - temp_pdata = c_zalloc(mud->mqtt_state.recv_buffer_size + len); + temp_pdata = calloc(1,mud->mqtt_state.recv_buffer_size + len); if(temp_pdata == NULL) { NODE_DBG("MQTT[buffering-short]: Failed to allocate %u bytes, disconnecting...\n", mud->mqtt_state.recv_buffer_size + len); #ifdef CLIENT_SSL_ENABLE @@ -320,7 +320,7 @@ static void mqtt_socket_received(void *arg, char *pdata, unsigned short len) NODE_DBG("MQTT[buffering-short]: Continuing with %u + %u bytes\n", mud->mqtt_state.recv_buffer_size, len); memcpy(temp_pdata, mud->mqtt_state.recv_buffer, mud->mqtt_state.recv_buffer_size); memcpy(temp_pdata + mud->mqtt_state.recv_buffer_size, pdata, len); - c_free(mud->mqtt_state.recv_buffer); + free(mud->mqtt_state.recv_buffer); mud->mqtt_state.recv_buffer = NULL; mud->mqtt_state.recv_buffer_state = MQTT_RECV_NORMAL; @@ -533,7 +533,7 @@ READPACKET: // max_message_length is 16bit. uint16_t alloc_size = message_length > 0 ? (uint16_t)message_length : in_buffer_length; - mud->mqtt_state.recv_buffer = c_zalloc(alloc_size); + mud->mqtt_state.recv_buffer = calloc(1,alloc_size); if (mud->mqtt_state.recv_buffer == NULL) { NODE_DBG("MQTT: Failed to allocate %u bytes, disconnecting...\n", alloc_size); #ifdef CLIENT_SSL_ENABLE @@ -674,7 +674,7 @@ RX_MESSAGE_PROCESSED: if(continuation_buffer != NULL) { NODE_DBG("MQTT[buffering]: buffered message finished. Continuing with rest of rx buffer (%u)\n", len); - c_free(mud->mqtt_state.recv_buffer); + free(mud->mqtt_state.recv_buffer); mud->mqtt_state.recv_buffer = NULL; in_buffer = continuation_buffer; @@ -698,7 +698,7 @@ RX_MESSAGE_PROCESSED: RX_PACKET_FINISHED: if(temp_pdata != NULL) { - c_free(temp_pdata); + free(temp_pdata); } mqtt_send_if_possible(pesp_conn); @@ -902,12 +902,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; @@ -917,7 +917,7 @@ static int mqtt_socket_client( lua_State* L ) // create a object mud = (lmqtt_userdata *)lua_newuserdata(L, sizeof(lmqtt_userdata)); - c_memset(mud, 0, sizeof(*mud)); + memset(mud, 0, sizeof(*mud)); // pre-initialize it, in case of errors mud->self_ref = LUA_NOREF; mud->cb_connect_ref = LUA_NOREF; @@ -989,30 +989,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 *)calloc(1,idl+1); + mud->connect_info.username = (uint8_t *)calloc(1,unl + 1); + mud->connect_info.password = (uint8_t *)calloc(1,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); @@ -1055,9 +1055,9 @@ 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 } while(mud->mqtt_state.pending_msg_q) { @@ -1066,34 +1066,34 @@ static int mqtt_delete( lua_State* L ) // ---- 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_received() if(mud->mqtt_state.recv_buffer) { - c_free(mud->mqtt_state.recv_buffer); + free(mud->mqtt_state.recv_buffer); mud->mqtt_state.recv_buffer = 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; } // ------- @@ -1203,7 +1203,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"); @@ -1241,7 +1241,7 @@ static int mqtt_socket_connect( lua_State* L ) struct espconn *pesp_conn = mud->pesp_conn; if(!pesp_conn) { - pesp_conn = mud->pesp_conn = (struct espconn *)c_zalloc(sizeof(struct espconn)); + pesp_conn = mud->pesp_conn = (struct espconn *)calloc(1,sizeof(struct espconn)); } else { espconn_delete(pesp_conn); } @@ -1249,9 +1249,9 @@ static int mqtt_socket_connect( lua_State* L ) if(!pesp_conn) return luaL_error(L, "not enough memory"); if (!pesp_conn->proto.tcp) - pesp_conn->proto.tcp = (esp_tcp *)c_zalloc(sizeof(esp_tcp)); + pesp_conn->proto.tcp = (esp_tcp *)calloc(1,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"); } @@ -1271,7 +1271,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"); @@ -1340,7 +1340,7 @@ static int mqtt_socket_connect( lua_State* L ) //My guess: If in doubt, resume the timer // 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; @@ -1434,25 +1434,25 @@ 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 if( sl == 8 && c_strcmp(method, "overflow") == 0){ + }else if( sl == 8 && strcmp(method, "overflow") == 0){ luaL_unref(L, LUA_REGISTRYINDEX, mud->cb_overflow_ref); mud->cb_overflow_ref = luaL_ref(L, LUA_REGISTRYINDEX); - }else if( sl == 6 && c_strcmp(method, "puback") == 0){ + }else if( sl == 6 && strcmp(method, "puback") == 0){ luaL_unref(L, LUA_REGISTRYINDEX, mud->cb_puback_ref); mud->cb_puback_ref = luaL_ref(L, LUA_REGISTRYINDEX); - }else if( sl == 6 && c_strcmp(method, "suback") == 0){ + }else if( sl == 6 && strcmp(method, "suback") == 0){ luaL_unref(L, LUA_REGISTRYINDEX, mud->cb_suback_ref); mud->cb_suback_ref = luaL_ref(L, LUA_REGISTRYINDEX); - }else if( sl == 8 && c_strcmp(method, "unsuback") == 0){ + }else if( sl == 8 && strcmp(method, "unsuback") == 0){ luaL_unref(L, LUA_REGISTRYINDEX, mud->cb_unsuback_ref); mud->cb_unsuback_ref = luaL_ref(L, LUA_REGISTRYINDEX); }else{ @@ -1795,30 +1795,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*) calloc(1, topicSize + 1 ); + mud->connect_info.will_message = (uint8_t*) calloc(1, 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) ) diff --git a/app/modules/net.c b/app/modules/net.c index 1336089d..d0b705d7 100644 --- a/app/modules/net.c +++ b/app/modules/net.c @@ -5,8 +5,9 @@ #include "platform.h" #include "lmem.h" -#include "c_string.h" -#include "c_stdlib.h" +#include +#include +#include #include "c_types.h" #include "mem.h" @@ -875,14 +876,14 @@ static void net_dns_static_cb(const char *name, ip_addr_t *ipaddr, void *callbac addr = *ipaddr; else addr.addr = 0xFFFFFFFF; int cb_ref = ((int*)callback_arg)[0]; - c_free(callback_arg); + free(callback_arg); lua_State *L = lua_getstate(); lua_rawgeti(L, LUA_REGISTRYINDEX, cb_ref); lua_pushnil(L); if (addr.addr != 0xFFFFFFFF) { char iptmp[20]; - size_t ipl = c_sprintf(iptmp, IPSTR, IP2STR(&addr.addr)); + size_t ipl = sprintf(iptmp, IPSTR, IP2STR(&addr.addr)); lua_pushlstring(L, iptmp, ipl); } else { lua_pushnil(L); @@ -906,7 +907,7 @@ static int net_dns_static( lua_State* L ) { if (cbref == LUA_NOREF) { return luaL_error(L, "wrong callback"); } - int *cbref_ptr = c_zalloc(sizeof(int)); + int *cbref_ptr = calloc(1, sizeof(int)); cbref_ptr[0] = cbref; ip_addr_t addr; err_t err = dns_gethostbyname(domain, &addr, net_dns_static_cb, cbref_ptr); @@ -917,7 +918,7 @@ static int net_dns_static( lua_State* L ) { return 0; } else { int e = lwip_lua_checkerr(L, err); - c_free(cbref_ptr); + free(cbref_ptr); return e; } return 0; @@ -958,7 +959,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 ); } diff --git a/app/modules/node.c b/app/modules/node.c index 7a01bac1..cc834c31 100644 --- a/app/modules/node.c +++ b/app/modules/node.c @@ -17,7 +17,7 @@ #include "platform.h" #include "lflash.h" #include "c_types.h" -#include "c_string.h" +#include #include "driver/uart.h" #include "user_interface.h" #include "flash_api.h" @@ -189,7 +189,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; // } @@ -260,18 +260,18 @@ static int node_compile( lua_State* L ) size_t len; const char *fname = luaL_checklstring( L, 1, &len ); const char *basename = vfs_basename( fname ); - luaL_argcheck(L, c_strlen(basename) <= FS_OBJ_NAME_LEN && c_strlen(fname) == len, 1, "filename invalid"); + luaL_argcheck(L, strlen(basename) <= FS_OBJ_NAME_LEN && strlen(fname) == len, 1, "filename invalid"); char *output = luaM_malloc( L, len+1 ); - 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) ) { luaM_free( L, output ); 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) { @@ -622,7 +622,7 @@ static int node_getpartitiontable (lua_State *L) { static void insert_partition(partition_item_t *p, int n, uint32_t type, uint32_t addr) { if (n>0) - c_memmove(p+1, p, n*sizeof(partition_item_t)); /* overlapped so must be move not cpy */ + memmove(p+1, p, n*sizeof(partition_item_t)); /* overlapped so must be move not cpy */ p->type = type; p->addr = addr; p->size = 0; @@ -630,7 +630,7 @@ static void insert_partition(partition_item_t *p, int n, uint32_t type, uint32_t static void delete_partition(partition_item_t *p, int n) { if (n>0) - c_memmove(p, p+1, n*sizeof(partition_item_t)); /* overlapped so must be move not cpy */ + memmove(p, p+1, n*sizeof(partition_item_t)); /* overlapped so must be move not cpy */ } #define SKIP (~0) @@ -668,7 +668,7 @@ static int node_setpartitiontable (lua_State *L) { */ lua_newuserdata(L, (n+2)*sizeof(partition_item_t)); pt = lua_touserdata (L, -1); - c_memcpy(pt, rcr_pt, n*sizeof(partition_item_t)); + memcpy(pt, rcr_pt, n*sizeof(partition_item_t)); pt[n].type = 0; pt[n+1].type = 0; for (i = 0; i < n; i ++) { diff --git a/app/modules/pcm.c b/app/modules/pcm.c index 5193ec63..f9056bcd 100644 --- a/app/modules/pcm.c +++ b/app/modules/pcm.c @@ -3,8 +3,8 @@ #include "module.h" #include "lauxlib.h" #include "task/task.h" -#include "c_string.h" -#include "c_stdlib.h" +#include +#include #include "pcm.h" #include "pcm_drv.h" @@ -43,11 +43,11 @@ static int pcm_drv_free( lua_State *L ) UNREF_CB( cfg->self_ref ); if (cfg->bufs[0].data) { - c_free( cfg->bufs[0].data ); + free( cfg->bufs[0].data ); cfg->bufs[0].data = NULL; } if (cfg->bufs[1].data) { - c_free( cfg->bufs[1].data ); + free( cfg->bufs[1].data ); cfg->bufs[1].data = NULL; } @@ -152,19 +152,19 @@ static int pcm_drv_on( lua_State *L ) is_func = TRUE; } - if ((len == 4) && (c_strcmp( event, "data" ) == 0)) { + if ((len == 4) && (strcmp( event, "data" ) == 0)) { luaL_unref( L, LUA_REGISTRYINDEX, cfg->cb_data_ref); cfg->cb_data_ref = COND_REF( is_func ); - } else if ((len == 7) && (c_strcmp( event, "drained" ) == 0)) { + } else if ((len == 7) && (strcmp( event, "drained" ) == 0)) { luaL_unref( L, LUA_REGISTRYINDEX, cfg->cb_drained_ref); cfg->cb_drained_ref = COND_REF( is_func ); - } else if ((len == 6) && (c_strcmp( event, "paused" ) == 0)) { + } else if ((len == 6) && (strcmp( event, "paused" ) == 0)) { luaL_unref( L, LUA_REGISTRYINDEX, cfg->cb_paused_ref); cfg->cb_paused_ref = COND_REF( is_func ); - } else if ((len == 7) && (c_strcmp( event, "stopped" ) == 0)) { + } else if ((len == 7) && (strcmp( event, "stopped" ) == 0)) { luaL_unref( L, LUA_REGISTRYINDEX, cfg->cb_stopped_ref); cfg->cb_stopped_ref = COND_REF( is_func ); - } else if ((len == 2) && (c_strcmp( event, "vu" ) == 0)) { + } else if ((len == 2) && (strcmp( event, "vu" ) == 0)) { luaL_unref( L, LUA_REGISTRYINDEX, cfg->cb_vu_ref); cfg->cb_vu_ref = COND_REF( is_func ); diff --git a/app/modules/perf.c b/app/modules/perf.c index fc5f712e..96196d84 100644 --- a/app/modules/perf.c +++ b/app/modules/perf.c @@ -9,7 +9,7 @@ #include "ets_sys.h" #include "os_type.h" #include "osapi.h" -#include "c_stdlib.h" +#include #include "module.h" #include "lauxlib.h" diff --git a/app/modules/rotary.c b/app/modules/rotary.c index 5436b56f..27df5440 100644 --- a/app/modules/rotary.c +++ b/app/modules/rotary.c @@ -12,7 +12,7 @@ #include "c_types.h" #include "user_interface.h" #include "driver/rotary.h" -#include "../libc/c_stdlib.h" +#include #define MASK(x) (1 << ROTARY_ ## x ## _INDEX) @@ -145,7 +145,7 @@ static int lrotary_setup( lua_State* L ) callback_free(L, id, ROTARY_ALL); if (!data[id]) { - data[id] = (DATA *) c_zalloc(sizeof(DATA)); + data[id] = (DATA *) calloc(1, sizeof(DATA)); if (!data[id]) { return -1; } @@ -211,7 +211,7 @@ static int lrotary_close( lua_State* L ) DATA *d = data[id]; if (d) { data[id] = NULL; - c_free(d); + free(d); } if (rotary_close( id )) { diff --git a/app/modules/rtcfifo.c b/app/modules/rtcfifo.c index dfea7777..9ae5e2e2 100644 --- a/app/modules/rtcfifo.c +++ b/app/modules/rtcfifo.c @@ -6,6 +6,7 @@ #include "rtc/rtctime.h" #define RTCTIME_SLEEP_ALIGNED rtctime_deep_sleep_until_aligned_us #include "rtc/rtcfifo.h" +#include // rtcfifo.prepare ([{sensor_count=n, interval_us=m, storage_begin=x, storage_end=y}]) static int rtcfifo_prepare (lua_State *L) diff --git a/app/modules/sjson.c b/app/modules/sjson.c index 7be6bb1b..530dfb25 100644 --- a/app/modules/sjson.c +++ b/app/modules/sjson.c @@ -6,9 +6,9 @@ #ifndef LOCAL_LUA #include "module.h" -#include "c_string.h" -#include "c_math.h" -#include "c_limits.h" +#include +#include +#include #endif #include "json_config.h" diff --git a/app/modules/sntp.c b/app/modules/sntp.c index 7d1b9872..9af8bda9 100644 --- a/app/modules/sntp.c +++ b/app/modules/sntp.c @@ -38,7 +38,7 @@ #include "os_type.h" #include "osapi.h" #include "lwip/udp.h" -#include "c_stdlib.h" +#include #include "user_modules.h" #include "lwip/dns.h" #include "task/task.h" @@ -180,18 +180,18 @@ static void cleanup (lua_State *L) luaL_unref (L, LUA_REGISTRYINDEX, state->sync_cb_ref); luaL_unref (L, LUA_REGISTRYINDEX, state->err_cb_ref); luaL_unref (L, LUA_REGISTRYINDEX, state->list_ref); - os_free (state); + free (state); state = 0; } static ip_addr_t* get_free_server() { - ip_addr_t* temp = (ip_addr_t *) c_malloc((server_count + 1) * sizeof(ip_addr_t)); + ip_addr_t* temp = (ip_addr_t *) malloc((server_count + 1) * sizeof(ip_addr_t)); if (server_count > 0) { memcpy(temp, serverp, server_count * sizeof(ip_addr_t)); } if (serverp) { - c_free(serverp); + free(serverp); } serverp = temp; @@ -671,7 +671,7 @@ static void sntp_dolookups (lua_State *L) { } static char *state_init(lua_State *L) { - state = (sntp_state_t *)c_malloc (sizeof (sntp_state_t)); + state = (sntp_state_t *)malloc (sizeof (sntp_state_t)); if (!state) return ("out of memory"); @@ -700,7 +700,7 @@ static char *set_repeat_mode(lua_State *L, bool enable) { if (enable) { set_repeat_mode(L, FALSE); - repeat = (sntp_repeat_t *) c_malloc(sizeof(sntp_repeat_t)); + repeat = (sntp_repeat_t *) malloc(sizeof(sntp_repeat_t)); if (!repeat) { return "no memory"; } @@ -722,7 +722,7 @@ static char *set_repeat_mode(lua_State *L, bool enable) luaL_unref (L, LUA_REGISTRYINDEX, repeat->sync_cb_ref); luaL_unref (L, LUA_REGISTRYINDEX, repeat->err_cb_ref); luaL_unref (L, LUA_REGISTRYINDEX, repeat->list_ref); - c_free(repeat); + free(repeat); repeat = NULL; } } @@ -811,7 +811,7 @@ static int sntp_sync (lua_State *L) for (i = 0; i < 4; i++) { lua_pushnumber(L, i + 1); char buf[64]; - c_sprintf(buf, "%d.nodemcu.pool.ntp.org", i); + sprintf(buf, "%d.nodemcu.pool.ntp.org", i); lua_pushstring(L, buf); lua_settable(L, -3); } @@ -835,7 +835,7 @@ error: { if (state->pcb) udp_remove (state->pcb); - c_free (state); + free (state); state = 0; } return luaL_error (L, errmsg); diff --git a/app/modules/sqlite3.c b/app/modules/sqlite3.c index 825da29f..a6b9cde6 100644 --- a/app/modules/sqlite3.c +++ b/app/modules/sqlite3.c @@ -31,7 +31,7 @@ #define SQLITE_OMIT_PROGRESS_CALLBACK 1 #include -#include +#include #include #define LUA_LIB @@ -273,7 +273,7 @@ static int dbvm_tostring(lua_State *L) { if (svm->vm == NULL) strcpy(buff, "closed"); else - c_sprintf(buff, "%p", svm); + sprintf(buff, "%p", svm); lua_pushfstring(L, "sqlite virtual machine (%s)", buff); return 1; } @@ -743,7 +743,7 @@ static int cleanupdb(lua_State *L, sdb *db) { luaL_unref(L, LUA_REGISTRYINDEX, func->fn_step); luaL_unref(L, LUA_REGISTRYINDEX, func->fn_finalize); luaL_unref(L, LUA_REGISTRYINDEX, func->udata); - c_free(func); + free(func); func = func_next; } db->func = NULL; @@ -800,7 +800,7 @@ static int lcontext_tostring(lua_State *L) { if (ctx->ctx == NULL) strcpy(buff, "closed"); else - c_sprintf(buff, "%p", ctx->ctx); + sprintf(buff, "%p", ctx->ctx); lua_pushfstring(L, "sqlite function context (%s)", buff); return 1; } @@ -1156,7 +1156,7 @@ static int db_register_function(lua_State *L, int aggregate) { if (aggregate) luaL_checktype(L, 5, LUA_TFUNCTION); /* maybe an alternative way to allocate memory should be used/avoided */ - func = (sdb_func*)c_malloc(sizeof(sdb_func)); + func = (sdb_func*)malloc(sizeof(sdb_func)); if (func == NULL) { luaL_error(L, "out of memory"); } @@ -1194,7 +1194,7 @@ static int db_register_function(lua_State *L, int aggregate) { } else { /* free allocated memory */ - c_free(func); + free(func); } lua_pushboolean(L, result == SQLITE_OK ? 1 : 0); @@ -1232,7 +1232,7 @@ static int collwrapper(scc *co,int l1,const void *p1, static void collfree(scc *co) { if (co) { luaL_unref(co->L,LUA_REGISTRYINDEX,co->ref); - c_free(co); + free(co); } } @@ -1246,7 +1246,7 @@ static int db_create_collation(lua_State *L) { else if (!lua_isnil(L,3)) luaL_error(L,"create_collation: function or nil expected"); if (collfunc != NULL) { - co=(scc *)c_malloc(sizeof(scc)); /* userdata is a no-no as it + co=(scc *)malloc(sizeof(scc)); /* userdata is a no-no as it will be garbage-collected */ if (co) { co->L=L; @@ -2037,7 +2037,7 @@ static int db_tostring(lua_State *L) { if (db->db == NULL) strcpy(buff, "closed"); else - c_sprintf(buff, "%p", lua_touserdata(L, 1)); + sprintf(buff, "%p", lua_touserdata(L, 1)); lua_pushfstring(L, "sqlite database (%s)", buff); return 1; } diff --git a/app/modules/tcs34725.c b/app/modules/tcs34725.c index a6733945..b5d59f28 100644 --- a/app/modules/tcs34725.c +++ b/app/modules/tcs34725.c @@ -22,7 +22,7 @@ #include "module.h" #include "lauxlib.h" #include "platform.h" -#include "c_math.h" +#include // #define TCS34725_ADDRESS (0x29<<1) #define TCS34725_ADDRESS (0x29) diff --git a/app/modules/tls.c b/app/modules/tls.c index d66c628e..d59af574 100644 --- a/app/modules/tls.c +++ b/app/modules/tls.c @@ -8,8 +8,8 @@ #include "platform.h" #include "lmem.h" -#include "c_string.h" -#include "c_stdlib.h" +#include +#include #include "c_types.h" #include "mem.h" @@ -77,10 +77,10 @@ static void tls_socket_cleanup(tls_socket_ud *ud) { if (ud->pesp_conn) { espconn_secure_disconnect(ud->pesp_conn); if (ud->pesp_conn->proto.tcp) { - c_free(ud->pesp_conn->proto.tcp); + free(ud->pesp_conn->proto.tcp); ud->pesp_conn->proto.tcp = NULL; } - c_free(ud->pesp_conn); + free(ud->pesp_conn); ud->pesp_conn = NULL; } lua_State *L = lua_getstate(); @@ -167,7 +167,7 @@ static void tls_socket_dns_cb( const char* domain, const ip_addr_t *ip_addr, tls lua_pushnil(L); } else { char tmp[20]; - c_sprintf(tmp, IPSTR, IP2STR(&addr.addr)); + sprintf(tmp, IPSTR, IP2STR(&addr.addr)); lua_pushstring(L, tmp); } lua_call(L, 2, 0); @@ -205,13 +205,13 @@ static int tls_socket_connect( lua_State *L ) { if (domain == NULL) return luaL_error(L, "invalid domain"); - ud->pesp_conn = (struct espconn*)c_zalloc(sizeof(struct espconn)); + ud->pesp_conn = (struct espconn*)calloc(1,sizeof(struct espconn)); if(!ud->pesp_conn) return luaL_error(L, "not enough memory"); ud->pesp_conn->proto.udp = NULL; - ud->pesp_conn->proto.tcp = (esp_tcp *)c_zalloc(sizeof(esp_tcp)); + ud->pesp_conn->proto.tcp = (esp_tcp *)calloc(1,sizeof(esp_tcp)); if(!ud->pesp_conn->proto.tcp){ - c_free(ud->pesp_conn); + free(ud->pesp_conn); ud->pesp_conn = NULL; return luaL_error(L, "not enough memory"); } @@ -349,7 +349,7 @@ static int tls_socket_getpeer( lua_State *L ) { if(ud->pesp_conn && ud->pesp_conn->proto.tcp->remote_port != 0){ char temp[20] = {0}; - c_sprintf(temp, IPSTR, IP2STR( &(ud->pesp_conn->proto.tcp->remote_ip) ) ); + sprintf(temp, IPSTR, IP2STR( &(ud->pesp_conn->proto.tcp->remote_ip) ) ); lua_pushstring( L, temp ); lua_pushinteger( L, ud->pesp_conn->proto.tcp->remote_port ); } else { @@ -382,10 +382,10 @@ static int tls_socket_delete( lua_State *L ) { if (ud->pesp_conn) { espconn_secure_disconnect(ud->pesp_conn); if (ud->pesp_conn->proto.tcp) { - c_free(ud->pesp_conn->proto.tcp); + free(ud->pesp_conn->proto.tcp); ud->pesp_conn->proto.tcp = NULL; } - c_free(ud->pesp_conn); + free(ud->pesp_conn); ud->pesp_conn = NULL; } @@ -507,7 +507,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); diff --git a/app/modules/tm1829.c b/app/modules/tm1829.c index 21f149da..c0da809c 100644 --- a/app/modules/tm1829.c +++ b/app/modules/tm1829.c @@ -1,8 +1,8 @@ #include "module.h" #include "lauxlib.h" #include "platform.h" -#include "c_stdlib.h" -#include "c_string.h" +#include +#include #include "user_interface.h" static inline uint32_t _getCycleCount(void) { @@ -68,7 +68,7 @@ static int ICACHE_FLASH_ATTR tm1829_write(lua_State* L) const char *rgb = luaL_checklstring(L, 2, &length); // dont modify lua-internal lstring - make a copy instead - char *buffer = (char *)c_malloc(length); + char *buffer = (char *)malloc(length); // Ignore incomplete Byte triples at the end of buffer length -= length % 3; @@ -95,7 +95,7 @@ static int ICACHE_FLASH_ATTR tm1829_write(lua_State* L) os_delay_us(500); // reset time - c_free(buffer); + free(buffer); return 0; } diff --git a/app/modules/tmr.c b/app/modules/tmr.c index 6625f973..14b7f528 100644 --- a/app/modules/tmr.c +++ b/app/modules/tmr.c @@ -78,7 +78,7 @@ typedef struct{ uint32_t interval; uint8_t mode; }timer_struct_t; -typedef timer_struct_t* timer_t; +typedef timer_struct_t* tmr_t; // The previous implementation extended the rtc counter to 64 bits, and then // applied rtc2sec with the current calibration value to that 64 bit value. @@ -97,7 +97,7 @@ static sint32_t soft_watchdog = -1; static os_timer_t rtc_timer; static void alarm_timer_common(void* arg){ - timer_t tmr = (timer_t)arg; + tmr_t tmr = (tmr_t)arg; lua_State* L = lua_getstate(); if(tmr->lua_ref == LUA_NOREF) return; @@ -142,16 +142,16 @@ static int tmr_now(lua_State* L){ return 1; } -static timer_t tmr_get( lua_State *L, int stack ) { - timer_t t = (timer_t)luaL_checkudata(L, stack, "tmr.timer"); +static tmr_t tmr_get( lua_State *L, int stack ) { + tmr_t t = (tmr_t)luaL_checkudata(L, stack, "tmr.timer"); if (t == NULL) - return (timer_t)luaL_error(L, "timer object expected"); + return (tmr_t)luaL_error(L, "timer object expected"); return t; } // Lua: tmr.register( ref, interval, mode, function ) static int tmr_register(lua_State* L){ - timer_t tmr = tmr_get(L, 1); + tmr_t tmr = tmr_get(L, 1); uint32_t interval = luaL_checkinteger(L, 2); uint8_t mode = luaL_checkinteger(L, 3); @@ -176,7 +176,7 @@ static int tmr_register(lua_State* L){ // Lua: tmr.start( id / ref ) static int tmr_start(lua_State* L){ - timer_t tmr = tmr_get(L, 1); + tmr_t tmr = tmr_get(L, 1); if (tmr->self_ref == LUA_NOREF) { lua_pushvalue(L, 1); @@ -202,7 +202,7 @@ static int tmr_alarm(lua_State* L){ // Lua: tmr.stop( id / ref ) static int tmr_stop(lua_State* L){ - timer_t tmr = tmr_get(L, 1); + tmr_t tmr = tmr_get(L, 1); if (tmr->self_ref != LUA_REFNIL) { luaL_unref(L, LUA_REGISTRYINDEX, tmr->self_ref); @@ -244,7 +244,7 @@ static int tmr_resume_all (lua_State *L){ // Lua: tmr.unregister( id / ref ) static int tmr_unregister(lua_State* L){ - timer_t tmr = tmr_get(L, 1); + tmr_t tmr = tmr_get(L, 1); if (tmr->self_ref != LUA_REFNIL) { luaL_unref(L, LUA_REGISTRYINDEX, tmr->self_ref); @@ -262,7 +262,7 @@ static int tmr_unregister(lua_State* L){ // Lua: tmr.interval( id / ref, interval ) static int tmr_interval(lua_State* L){ - timer_t tmr = tmr_get(L, 1); + tmr_t tmr = tmr_get(L, 1); uint32_t interval = luaL_checkinteger(L, 2); luaL_argcheck(L, (interval > 0 && interval <= MAX_TIMEOUT), 2, MAX_TIMEOUT_ERR_STR); @@ -278,7 +278,7 @@ static int tmr_interval(lua_State* L){ // Lua: tmr.state( id / ref ) static int tmr_state(lua_State* L){ - timer_t tmr = tmr_get(L, 1); + tmr_t tmr = tmr_get(L, 1); if(tmr->mode == TIMER_MODE_OFF){ lua_pushnil(L); @@ -355,7 +355,7 @@ static int tmr_softwd( lua_State* L ){ // Lua: tmr.create() static int tmr_create( lua_State *L ) { - timer_t ud = (timer_t)lua_newuserdata(L, sizeof(timer_struct_t)); + tmr_t ud = (tmr_t)lua_newuserdata(L, sizeof(timer_struct_t)); if (!ud) return luaL_error(L, "not enough memory"); luaL_getmetatable(L, "tmr.timer"); lua_setmetatable(L, -2); diff --git a/app/modules/uart.c b/app/modules/uart.c index a9b7efee..364873d7 100644 --- a/app/modules/uart.c +++ b/app/modules/uart.c @@ -5,7 +5,7 @@ #include "platform.h" #include "c_types.h" -#include "c_string.h" +#include #include "rom.h" static int uart_receive_rf = LUA_NOREF; @@ -67,7 +67,7 @@ static int l_uart_on( lua_State* L ) } else { lua_pushnil(L); } - if(sl == 4 && c_strcmp(method, "data") == 0){ + if(sl == 4 && strcmp(method, "data") == 0){ run_input = true; if(uart_receive_rf != LUA_NOREF){ luaL_unref(L, LUA_REGISTRYINDEX, uart_receive_rf); diff --git a/app/modules/websocket.c b/app/modules/websocket.c index 27e886af..77d83d08 100644 --- a/app/modules/websocket.c +++ b/app/modules/websocket.c @@ -14,8 +14,8 @@ #include "module.h" #include "c_types.h" -#include "c_string.h" -#include "c_stdlib.h" +#include +#include #include "websocketclient.h" @@ -191,14 +191,14 @@ static int websocketclient_connect(lua_State *L) { static header_t *realloc_headers(header_t *headers, int new_size) { if(headers) { for(header_t *header = headers; header->key; header++) { - c_free(header->value); - c_free(header->key); + free(header->value); + free(header->key); } - c_free(headers); + free(headers); } if(!new_size) return NULL; - return (header_t *)c_malloc(sizeof(header_t) * (new_size + 1)); + return (header_t *)malloc(sizeof(header_t) * (new_size + 1)); } static int websocketclient_config(lua_State *L) { @@ -225,8 +225,8 @@ static int websocketclient_config(lua_State *L) { lua_pushnil(L); while(lua_next(L, -2)) { - header->key = c_strdup(lua_tostring(L, -2)); - header->value = c_strdup(lua_tostring(L, -1)); + header->key = strdup(lua_tostring(L, -2)); + header->value = strdup(lua_tostring(L, -1)); header++; lua_pop(L, 1); } diff --git a/app/modules/wifi.c b/app/modules/wifi.c index 794fdef1..ddcc3096 100644 --- a/app/modules/wifi.c +++ b/app/modules/wifi.c @@ -6,8 +6,8 @@ #include "lauxlib.h" #include "platform.h" -#include "c_string.h" -#include "c_stdlib.h" +#include +#include #include "ctype.h" #include "c_types.h" @@ -95,18 +95,18 @@ static void wifi_scan_done(void *arg, STATUS status) while (bss_link != NULL) { - c_memset(ssid, 0, 33); - if (c_strlen(bss_link->ssid) <= 32) + memset(ssid, 0, 33); + if (strlen(bss_link->ssid) <= 32) { - c_memcpy(ssid, bss_link->ssid, c_strlen(bss_link->ssid)); + memcpy(ssid, bss_link->ssid, strlen(bss_link->ssid)); } else { - c_memcpy(ssid, bss_link->ssid, 32); + memcpy(ssid, bss_link->ssid, 32); } if(getap_output_format==1) //use new format(BSSID : SSID, RSSI, Authmode, Channel) { - c_sprintf(temp,MACSTR, MAC2STR(bss_link->bssid)); + sprintf(temp,MACSTR, MAC2STR(bss_link->bssid)); wifi_add_sprintf_field(L, temp, "%s,%d,%d,%d", ssid, bss_link->rssi, bss_link->authmode, bss_link->channel); NODE_DBG(MACSTR" : %s\n",MAC2STR(bss_link->bssid) , temp);//00 00 00 00 00 00 @@ -260,7 +260,7 @@ static int wifi_setcountry( lua_State* L ){ if( lua_isstring(L, -1) ){ const char *country_code = luaL_checklstring( L, -1, &len ); luaL_argcheck(L, (len==2 && isalpha(country_code[0]) && isalpha(country_code[1])), 1, "country: country code must be 2 chars"); - c_memcpy(cfg.cc, country_code, len); + memcpy(cfg.cc, country_code, len); if(cfg.cc[0] >= 0x61) cfg.cc[0]=cfg.cc[0]-32; //if lowercase change to uppercase if(cfg.cc[1] >= 0x61) cfg.cc[1]=cfg.cc[1]-32; //if lowercase change to uppercase } @@ -552,7 +552,7 @@ static int wifi_getmac( lua_State* L, uint8_t mode ) char temp[64]; uint8_t mac[6]; wifi_get_macaddr(mode, mac); - c_sprintf(temp, MACSTR, MAC2STR(mac)); + sprintf(temp, MACSTR, MAC2STR(mac)); lua_pushstring( L, temp ); return 1; } @@ -581,11 +581,11 @@ static int wifi_getip( lua_State* L, uint8_t mode ) } else { - c_sprintf(temp, "%d.%d.%d.%d", IP2STR(&pTempIp.ip) ); + sprintf(temp, "%d.%d.%d.%d", IP2STR(&pTempIp.ip) ); lua_pushstring( L, temp ); - c_sprintf(temp, "%d.%d.%d.%d", IP2STR(&pTempIp.netmask) ); + sprintf(temp, "%d.%d.%d.%d", IP2STR(&pTempIp.netmask) ); lua_pushstring( L, temp ); - c_sprintf(temp, "%d.%d.%d.%d", IP2STR(&pTempIp.gw) ); + sprintf(temp, "%d.%d.%d.%d", IP2STR(&pTempIp.gw) ); lua_pushstring( L, temp ); return 3; } @@ -609,7 +609,7 @@ static int wifi_getbroadcast( lua_State* L, uint8_t mode ) uint32 broadcast_address32 = ~pTempIp.netmask.addr | subnet_mask32; broadcast_address.addr = broadcast_address32; - c_sprintf(temp, "%d.%d.%d.%d", IP2STR(&broadcast_address) ); + sprintf(temp, "%d.%d.%d.%d", IP2STR(&broadcast_address) ); lua_pushstring( L, temp ); return 1; @@ -688,7 +688,7 @@ static int wifi_station_get_ap_info4lua( lua_State* L ) lua_pushstring(L, temp); lua_setfield(L, -2, "ssid"); #if defined(WIFI_DEBUG) - c_sprintf(debug_temp, " %-6d %-32s ", i, temp); + sprintf(debug_temp, " %-6d %-32s ", i, temp); #endif memset(temp, 0, sizeof(temp)); @@ -699,13 +699,13 @@ static int wifi_station_get_ap_info4lua( lua_State* L ) lua_setfield(L, -2, "pwd"); } #if defined(WIFI_DEBUG) - c_sprintf(debug_temp + strlen(debug_temp), "%-64s ", temp); + sprintf(debug_temp + strlen(debug_temp), "%-64s ", temp); #endif memset(temp, 0, sizeof(temp)); if (config[i].bssid_set) { - c_sprintf(temp, MACSTR, MAC2STR(config[i].bssid)); + sprintf(temp, MACSTR, MAC2STR(config[i].bssid)); lua_pushstring(L, temp); lua_setfield(L, -2, "bssid"); } @@ -812,7 +812,7 @@ static int wifi_station_getconfig( lua_State* L, bool get_flash_cfg) lua_setfield(L, -2, "bssid_set"); memset(temp, 0, sizeof(temp)); - c_sprintf(temp, MACSTR, MAC2STR(sta_conf.bssid)); + sprintf(temp, MACSTR, MAC2STR(sta_conf.bssid)); lua_pushstring( L, temp); lua_setfield(L, -2, "bssid"); @@ -827,7 +827,7 @@ static int wifi_station_getconfig( lua_State* L, bool get_flash_cfg) memcpy(temp, sta_conf.password, sizeof(sta_conf.password)); lua_pushstring(L, temp); lua_pushinteger( L, sta_conf.bssid_set); - c_sprintf(temp, MACSTR, MAC2STR(sta_conf.bssid)); + sprintf(temp, MACSTR, MAC2STR(sta_conf.bssid)); lua_pushstring( L, temp); return 4; } @@ -1180,8 +1180,8 @@ static int wifi_station_listap( lua_State* L ) const char *ssidstr = luaL_checklstring( L, -1, &len ); if(len>32) return luaL_error( L, "ssid:<32" ); - c_memset(ssid, 0, 32); - c_memcpy(ssid, ssidstr, len); + memset(ssid, 0, 32); + memcpy(ssid, ssidstr, len); scan_cfg.ssid=ssid; NODE_DBG(scan_cfg.ssid); NODE_DBG("\n"); @@ -1199,7 +1199,7 @@ static int wifi_station_listap( lua_State* L ) { const char *macaddr = luaL_checklstring( L, -1, &len ); luaL_argcheck(L, len==17, 1, INVALID_MAC_STR); - c_memset(bssid, 0, 6); + memset(bssid, 0, 6); ets_str2macaddr(bssid, macaddr); scan_cfg.bssid=bssid; NODE_DBG(MACSTR, MAC2STR(scan_cfg.bssid)); @@ -1401,7 +1401,7 @@ static int wifi_ap_deauth( lua_State* L ) } else { - c_memset(&mac, 0xFF, sizeof(mac)); + memset(&mac, 0xFF, sizeof(mac)); } lua_pushboolean(L,wifi_softap_deauth(mac)); return 1; @@ -1799,7 +1799,7 @@ static int wifi_ap_listclient( lua_State* L ) struct station_info * next_station; while (station != NULL) { - c_sprintf(temp, MACSTR, MAC2STR(station->bssid)); + sprintf(temp, MACSTR, MAC2STR(station->bssid)); wifi_add_sprintf_field(L, temp, IPSTR, IP2STR(&station->ip)); station = STAILQ_NEXT(station, next); } @@ -1833,9 +1833,9 @@ static int wifi_ap_dhcp_config( lua_State* L ) ip4_addr4(&lease.end_ip) += config.max_connection - 1; char temp[64]; - c_sprintf(temp, IPSTR, IP2STR(&lease.start_ip)); + sprintf(temp, IPSTR, IP2STR(&lease.start_ip)); lua_pushstring(L, temp); - c_sprintf(temp, IPSTR, IP2STR(&lease.end_ip)); + sprintf(temp, IPSTR, IP2STR(&lease.end_ip)); lua_pushstring(L, temp); // note: DHCP max range = 101 from start_ip to end_ip @@ -1983,20 +1983,20 @@ void wifi_change_default_host_name(void) wifi_get_macaddr(STATION_IF, mac); #ifndef WIFI_STA_HOSTNAME - c_sprintf(temp, "NODE-%X%X%X", (mac)[3], (mac)[4], (mac)[5]); + sprintf(temp, "NODE-%X%X%X", (mac)[3], (mac)[4], (mac)[5]); #elif defined(WIFI_STA_HOSTNAME) && !defined(WIFI_STA_HOSTNAME_APPEND_MAC) if(wifi_sta_checkhostname(WIFI_STA_HOSTNAME, strlen(WIFI_STA_HOSTNAME))){ - c_sprintf(temp, "%s", WIFI_STA_HOSTNAME); + sprintf(temp, "%s", WIFI_STA_HOSTNAME); } else{ - c_sprintf(temp, "NODE-%X%X%X", (mac)[3], (mac)[4], (mac)[5]); + sprintf(temp, "NODE-%X%X%X", (mac)[3], (mac)[4], (mac)[5]); } #elif defined(WIFI_STA_HOSTNAME) && defined(WIFI_STA_HOSTNAME_APPEND_MAC) if(strlen(WIFI_STA_HOSTNAME) <= 26 && wifi_sta_checkhostname(WIFI_STA_HOSTNAME, strlen(WIFI_STA_HOSTNAME))){ - c_sprintf(temp, "%s%X%X%X", WIFI_STA_HOSTNAME, (mac)[3], (mac)[4], (mac)[5]); + sprintf(temp, "%s%X%X%X", WIFI_STA_HOSTNAME, (mac)[3], (mac)[4], (mac)[5]); } else{ - c_sprintf(temp, "NODE-%X%X%X", (mac)[3], (mac)[4], (mac)[5]); + sprintf(temp, "NODE-%X%X%X", (mac)[3], (mac)[4], (mac)[5]); } #endif diff --git a/app/modules/wifi_common.c b/app/modules/wifi_common.c index cba000eb..b2afc5ea 100644 --- a/app/modules/wifi_common.c +++ b/app/modules/wifi_common.c @@ -10,7 +10,7 @@ void wifi_add_sprintf_field(lua_State* L, char* name, char* string, ...) char buffer[256]; va_list arglist; va_start( arglist, string ); - c_vsprintf( buffer, string, arglist ); + vsprintf( buffer, string, arglist ); va_end( arglist ); lua_pushstring(L, buffer); lua_setfield(L, -2, name); diff --git a/app/modules/wifi_common.h b/app/modules/wifi_common.h index c94a857d..3c14354e 100644 --- a/app/modules/wifi_common.h +++ b/app/modules/wifi_common.h @@ -5,12 +5,11 @@ #include "lauxlib.h" #include "platform.h" -#include "c_string.h" -#include "c_stdlib.h" -#include "c_types.h" +#include +#include +#include #include "user_interface.h" #include "user_config.h" -#include "c_stdio.h" #include "task/task.h" //#define WIFI_DEBUG @@ -37,16 +36,16 @@ static inline void unregister_lua_cb(lua_State* L, int* cb_ref){ void wifi_change_default_host_name(void); #if defined(WIFI_DEBUG) || defined(NODE_DEBUG) -#define WIFI_DBG(...) c_printf(__VA_ARGS__) +#define WIFI_DBG(...) printf(__VA_ARGS__) #else -#define WIFI_DBG(...) //c_printf(__VA_ARGS__) +#define WIFI_DBG(...) //printf(__VA_ARGS__) #endif #if defined(EVENT_DEBUG) || defined(NODE_DEBUG) -#define EVENT_DBG(fmt, ...) c_printf("\n EVENT_DBG(%s): "fmt"\n", __FUNCTION__, ##__VA_ARGS__) +#define EVENT_DBG(fmt, ...) printf("\n EVENT_DBG(%s): "fmt"\n", __FUNCTION__, ##__VA_ARGS__) #else -#define EVENT_DBG(...) //c_printf(__VA_ARGS__) +#define EVENT_DBG(...) //printf(__VA_ARGS__) #endif enum wifi_suspension_state{ diff --git a/app/modules/wifi_eventmon.c b/app/modules/wifi_eventmon.c index 89c2fb7d..5d016f91 100644 --- a/app/modules/wifi_eventmon.c +++ b/app/modules/wifi_eventmon.c @@ -4,8 +4,8 @@ #include "lauxlib.h" #include "platform.h" -#include "c_string.h" -#include "c_stdlib.h" +#include +#include #include "c_types.h" #include "user_interface.h" @@ -82,7 +82,7 @@ static void wifi_event_monitor_handle_event_cb(System_Event_t *evt) lua_rawgeti(L, LUA_REGISTRYINDEX, event_queue_ref); System_Event_t* evt_tmp = lua_newuserdata(L, sizeof(System_Event_t)); - c_memcpy(evt_tmp, evt, sizeof(System_Event_t)); //copy event data to new struct + memcpy(evt_tmp, evt, sizeof(System_Event_t)); //copy event data to new struct sint32_t evt_ud_ref = luaL_ref(L, LUA_REGISTRYINDEX); size_t queue_len = lua_objlen(L, -1); diff --git a/app/modules/wifi_monitor.c b/app/modules/wifi_monitor.c index 88067b8f..041bb03f 100644 --- a/app/modules/wifi_monitor.c +++ b/app/modules/wifi_monitor.c @@ -5,8 +5,8 @@ #include "lapi.h" #include "platform.h" -#include "c_string.h" -#include "c_stdlib.h" +#include +#include #include "ctype.h" #include "c_types.h" @@ -294,12 +294,12 @@ static void wifi_rx_cb(uint8 *buf, uint16 len) { return; } - packet_t *packet = (packet_t *) c_malloc(len + sizeof(packet_t)); + packet_t *packet = (packet_t *) malloc(len + sizeof(packet_t)); if (packet) { packet->len = len; memcpy(packet->buf, buf, len); if (!task_post_medium(tasknumber, (ETSParam) packet)) { - c_free(packet); + free(packet); } } } @@ -320,11 +320,11 @@ static void monitor_task(os_param_t param, uint8_t prio) luaL_getmetatable(L, "wifi.packet"); lua_setmetatable(L, -2); - c_free(input); + free(input); lua_call(L, 1, 0); } else { - c_free(input); + free(input); } } diff --git a/app/modules/ws2801.c b/app/modules/ws2801.c index b325898b..bbc34b49 100644 --- a/app/modules/ws2801.c +++ b/app/modules/ws2801.c @@ -1,8 +1,9 @@ #include "module.h" #include "lauxlib.h" #include "platform.h" -#include "c_stdlib.h" -#include "c_string.h" +#include +#include +#include "osapi.h" /** * Code is based on https://github.com/CHERTS/esp8266-devkit/blob/master/Espressif/examples/EspLightNode/user/ws2801.c diff --git a/app/modules/ws2812.c b/app/modules/ws2812.c index 3be67e89..fa892079 100644 --- a/app/modules/ws2812.c +++ b/app/modules/ws2812.c @@ -2,9 +2,9 @@ #include "lauxlib.h" #include "lmem.h" #include "platform.h" -#include "c_stdlib.h" -#include "c_math.h" -#include "c_string.h" +#include +#include +#include #include "user_interface.h" #include "driver/uart.h" #include "osapi.h" @@ -201,7 +201,7 @@ static int ws2812_new_buffer(lua_State *L) { ws2812_buffer * buffer = allocate_buffer(L, leds, colorsPerLed); - c_memset(buffer->values, 0, colorsPerLed * leds); + memset(buffer->values, 0, colorsPerLed * leds); return 1; } @@ -295,7 +295,7 @@ int ws2812_buffer_shift(ws2812_buffer * buffer, int shiftValue, unsigned shift_t return 0; } - uint8_t * tmp_pixels = c_malloc(buffer->colorsPerLed * sizeof(uint8_t) * shift); + uint8_t * tmp_pixels = malloc(buffer->colorsPerLed * sizeof(uint8_t) * shift); int i,j; size_t shift_len, remaining_len; // calculate length of shift section and remaining section @@ -305,37 +305,37 @@ int ws2812_buffer_shift(ws2812_buffer * buffer, int shiftValue, unsigned shift_t if (shiftValue > 0) { // Store the values which are moved out of the array (last n pixels) - c_memcpy(tmp_pixels, &buffer->values[offset + (size-shift)*buffer->colorsPerLed], shift_len); + memcpy(tmp_pixels, &buffer->values[offset + (size-shift)*buffer->colorsPerLed], shift_len); // Move pixels to end os_memmove(&buffer->values[offset + shift*buffer->colorsPerLed], &buffer->values[offset], remaining_len); // Fill beginning with temp data if (shift_type == SHIFT_LOGICAL) { - c_memset(&buffer->values[offset], 0, shift_len); + memset(&buffer->values[offset], 0, shift_len); } else { - c_memcpy(&buffer->values[offset], tmp_pixels, shift_len); + memcpy(&buffer->values[offset], tmp_pixels, shift_len); } } else { // Store the values which are moved out of the array (last n pixels) - c_memcpy(tmp_pixels, &buffer->values[offset], shift_len); + memcpy(tmp_pixels, &buffer->values[offset], shift_len); // Move pixels to end os_memmove(&buffer->values[offset], &buffer->values[offset + shift*buffer->colorsPerLed], remaining_len); // Fill beginning with temp data if (shift_type == SHIFT_LOGICAL) { - c_memset(&buffer->values[offset + (size-shift)*buffer->colorsPerLed], 0, shift_len); + memset(&buffer->values[offset + (size-shift)*buffer->colorsPerLed], 0, shift_len); } else { - c_memcpy(&buffer->values[offset + (size-shift)*buffer->colorsPerLed], tmp_pixels, shift_len); + memcpy(&buffer->values[offset + (size-shift)*buffer->colorsPerLed], tmp_pixels, shift_len); } } // Free memory - c_free(tmp_pixels); + free(tmp_pixels); return 0; } @@ -386,7 +386,7 @@ static int ws2812_buffer_replace(lua_State* L) { luaL_argcheck(L, srcLen + start - 1 <= buffer->size, 2, "Does not fit into destination"); - c_memcpy(buffer->values + (start - 1) * buffer->colorsPerLed, src, srcLen * buffer->colorsPerLed); + memcpy(buffer->values + (start - 1) * buffer->colorsPerLed, src, srcLen * buffer->colorsPerLed); return 0; } @@ -504,7 +504,7 @@ static int ws2812_buffer_set(lua_State* L) { return luaL_error(L, "string size will exceed strip length"); } - c_memcpy(&buffer->values[buffer->colorsPerLed*led], buf, len); + memcpy(&buffer->values[buffer->colorsPerLed*led], buf, len); } else { @@ -535,7 +535,7 @@ static int ws2812_buffer_sub(lua_State* L) { if (end > (ptrdiff_t)l) end = (ptrdiff_t)l; if (start <= end) { ws2812_buffer *result = allocate_buffer(L, end - start + 1, lhs->colorsPerLed); - c_memcpy(result->values, lhs->values + lhs->colorsPerLed * (start - 1), lhs->colorsPerLed * (end - start + 1)); + memcpy(result->values, lhs->values + lhs->colorsPerLed * (start - 1), lhs->colorsPerLed * (end - start + 1)); } else { ws2812_buffer *result = allocate_buffer(L, 0, lhs->colorsPerLed); } @@ -553,8 +553,8 @@ static int ws2812_buffer_concat(lua_State* L) { ws2812_buffer * buffer = allocate_buffer(L, leds, colorsPerLed); - c_memcpy(buffer->values, lhs->values, lhs->colorsPerLed * lhs->size); - c_memcpy(buffer->values + lhs->colorsPerLed * lhs->size, rhs->values, rhs->colorsPerLed * rhs->size); + memcpy(buffer->values, lhs->values, lhs->colorsPerLed * lhs->size); + memcpy(buffer->values + lhs->colorsPerLed * lhs->size, rhs->values, rhs->colorsPerLed * rhs->size); return 1; } @@ -579,7 +579,7 @@ static int ws2812_buffer_tostring(lua_State* L) { luaL_addchar(&result, ','); } char numbuf[5]; - c_sprintf(numbuf, "%d", buffer->values[p]); + sprintf(numbuf, "%d", buffer->values[p]); luaL_addstring(&result, numbuf); } luaL_addchar(&result, ')'); diff --git a/app/modules/ws2812.h b/app/modules/ws2812.h index 40c0fb26..9b31910f 100644 --- a/app/modules/ws2812.h +++ b/app/modules/ws2812.h @@ -5,9 +5,9 @@ #include "lauxlib.h" #include "lmem.h" #include "platform.h" -#include "c_stdlib.h" -#include "c_math.h" -#include "c_string.h" +#include +#include +#include #include "user_interface.h" #include "driver/uart.h" #include "osapi.h" diff --git a/app/modules/ws2812_effects.c b/app/modules/ws2812_effects.c index 6945c8b8..e53676be 100644 --- a/app/modules/ws2812_effects.c +++ b/app/modules/ws2812_effects.c @@ -2,9 +2,9 @@ #include "lauxlib.h" #include "lmem.h" #include "platform.h" -#include "c_stdlib.h" -#include "c_math.h" -#include "c_string.h" +#include +#include +#include #include "user_interface.h" #include "driver/uart.h" #include "osapi.h" @@ -18,8 +18,6 @@ #define DEFAULT_MODE 0 #define DEFAULT_COLOR 0xFF0000 -#define UINT32_MAX 4294967295U - #define SPEED_MIN 0 #define SPEED_MAX 255 #define SPEED_DEFAULT 150 @@ -161,11 +159,11 @@ static int ws2812_effects_init(lua_State *L) { // get rid of old state if (state != NULL) { luaL_unref(L, LUA_REGISTRYINDEX, state->buffer_ref); - os_free((void *) state); + free((void *) state); } // Allocate memory and set all to zero size_t size = sizeof(ws2812_effects) + buffer->colorsPerLed*sizeof(uint8_t); - state = (ws2812_effects *) os_zalloc(size); + state = (ws2812_effects *) calloc(1,size); // initialize state->speed = SPEED_DEFAULT; state->mode_delay = DELAY_DEFAULT; @@ -307,7 +305,7 @@ static int ws2812_effects_mode_blink() { else { // off ws2812_buffer * buffer = state->buffer; - c_memset(&buffer->values[0], 0, buffer->size * buffer->colorsPerLed); + memset(&buffer->values[0], 0, buffer->size * buffer->colorsPerLed); } return 0; } diff --git a/app/mqtt/mqtt_msg.c b/app/mqtt/mqtt_msg.c index 979cedf4..f3975695 100644 --- a/app/mqtt/mqtt_msg.c +++ b/app/mqtt/mqtt_msg.c @@ -29,7 +29,7 @@ * */ -#include "c_string.h" +#include #include "mqtt_msg.h" #define MQTT_MAX_FIXED_HEADER_SIZE 3 @@ -61,7 +61,7 @@ static int append_string(mqtt_connection_t* connection, const char* string, int connection->buffer[connection->message.length++] = len >> 8; connection->buffer[connection->message.length++] = len & 0xff; - c_memcpy(connection->buffer + connection->message.length, string, len); + memcpy(connection->buffer + connection->message.length, string, len); connection->message.length += len; return len + 2; @@ -121,7 +121,7 @@ static mqtt_message_t* fini_message(mqtt_connection_t* connection, int type, int void mqtt_msg_init(mqtt_connection_t* connection, uint8_t* buffer, uint16_t buffer_length) { - c_memset(connection, 0, sizeof(connection)); + memset(connection, 0, sizeof(connection)); connection->buffer = buffer; connection->buffer_length = buffer_length; } @@ -299,7 +299,7 @@ mqtt_message_t* mqtt_msg_connect(mqtt_connection_t* connection, mqtt_connect_inf variable_header->lengthMsb = 0; variable_header->lengthLsb = 4; - c_memcpy(variable_header->magic, "MQTT", 4); + memcpy(variable_header->magic, "MQTT", 4); variable_header->version = 4; variable_header->flags = 0; variable_header->keepaliveMsb = info->keepalive >> 8; @@ -310,7 +310,7 @@ mqtt_message_t* mqtt_msg_connect(mqtt_connection_t* connection, mqtt_connect_inf if(info->client_id != NULL && info->client_id[0] != '\0') { - if(append_string(connection, info->client_id, c_strlen(info->client_id)) < 0) + if(append_string(connection, info->client_id, strlen(info->client_id)) < 0) return fail_message(connection); } else @@ -318,10 +318,10 @@ mqtt_message_t* mqtt_msg_connect(mqtt_connection_t* connection, mqtt_connect_inf if(info->will_topic != NULL && info->will_topic[0] != '\0') { - if(append_string(connection, info->will_topic, c_strlen(info->will_topic)) < 0) + if(append_string(connection, info->will_topic, strlen(info->will_topic)) < 0) return fail_message(connection); - if(append_string(connection, info->will_message, c_strlen(info->will_message)) < 0) + if(append_string(connection, info->will_message, strlen(info->will_message)) < 0) return fail_message(connection); variable_header->flags |= MQTT_CONNECT_FLAG_WILL; @@ -332,7 +332,7 @@ mqtt_message_t* mqtt_msg_connect(mqtt_connection_t* connection, mqtt_connect_inf if(info->username != NULL && info->username[0] != '\0') { - if(append_string(connection, info->username, c_strlen(info->username)) < 0) + if(append_string(connection, info->username, strlen(info->username)) < 0) return fail_message(connection); variable_header->flags |= MQTT_CONNECT_FLAG_USERNAME; @@ -340,7 +340,7 @@ mqtt_message_t* mqtt_msg_connect(mqtt_connection_t* connection, mqtt_connect_inf if(info->password != NULL && info->password[0] != '\0') { - if(append_string(connection, info->password, c_strlen(info->password)) < 0) + if(append_string(connection, info->password, strlen(info->password)) < 0) return fail_message(connection); variable_header->flags |= MQTT_CONNECT_FLAG_PASSWORD; @@ -356,7 +356,7 @@ mqtt_message_t* mqtt_msg_publish(mqtt_connection_t* connection, const char* topi if(topic == NULL || topic[0] == '\0') return fail_message(connection); - if(append_string(connection, topic, c_strlen(topic)) < 0) + if(append_string(connection, topic, strlen(topic)) < 0) return fail_message(connection); if(qos > 0) @@ -369,7 +369,7 @@ mqtt_message_t* mqtt_msg_publish(mqtt_connection_t* connection, const char* topi if(connection->message.length + data_length > connection->buffer_length) return fail_message(connection); - c_memcpy(connection->buffer + connection->message.length, data, data_length); + memcpy(connection->buffer + connection->message.length, data, data_length); connection->message.length += data_length; return fini_message(connection, MQTT_MSG_TYPE_PUBLISH, 0, qos, retain); @@ -422,7 +422,7 @@ mqtt_message_t* mqtt_msg_subscribe_topic(mqtt_connection_t* connection, const ch if(topic == NULL || topic[0] == '\0') return fail_message(connection); - if(append_string(connection, topic, c_strlen(topic)) < 0) + if(append_string(connection, topic, strlen(topic)) < 0) return fail_message(connection); if(connection->message.length + 1 > connection->buffer_length) @@ -462,7 +462,7 @@ mqtt_message_t* mqtt_msg_unsubscribe_topic(mqtt_connection_t* connection, const if(topic == NULL || topic[0] == '\0') return fail_message(connection); - if(append_string(connection, topic, c_strlen(topic)) < 0) + if(append_string(connection, topic, strlen(topic)) < 0) return fail_message(connection); return &connection->message; diff --git a/app/mqtt/msg_queue.c b/app/mqtt/msg_queue.c index 392957ff..1b00d5e8 100644 --- a/app/mqtt/msg_queue.c +++ b/app/mqtt/msg_queue.c @@ -1,7 +1,8 @@ -#include "c_string.h" -#include "c_stdlib.h" -#include "c_stdio.h" +#include +#include +#include #include "msg_queue.h" +#include "user_config.h" msg_queue_t *msg_enqueue(msg_queue_t **head, mqtt_message_t *msg, uint16_t msg_id, int msg_type, int publish_qos){ if(!head){ @@ -11,19 +12,19 @@ msg_queue_t *msg_enqueue(msg_queue_t **head, mqtt_message_t *msg, uint16_t msg_i NODE_DBG("empty message\n"); return NULL; } - msg_queue_t *node = (msg_queue_t *)c_zalloc(sizeof(msg_queue_t)); + msg_queue_t *node = (msg_queue_t *)calloc(1,sizeof(msg_queue_t)); if(!node){ NODE_DBG("not enough memory\n"); return NULL; } - node->msg.data = (uint8_t *)c_zalloc(msg->length); + node->msg.data = (uint8_t *)calloc(1,msg->length); if(!node->msg.data){ NODE_DBG("not enough memory\n"); - c_free(node); + free(node); return NULL; } - c_memcpy(node->msg.data, msg->data, msg->length); + memcpy(node->msg.data, msg->data, msg->length); node->msg.length = msg->length; node->next = NULL; node->msg_id = msg_id; @@ -43,10 +44,10 @@ msg_queue_t *msg_enqueue(msg_queue_t **head, mqtt_message_t *msg, uint16_t msg_i void msg_destroy(msg_queue_t *node){ if(!node) return; if(node->msg.data){ - c_free(node->msg.data); + free(node->msg.data); node->msg.data = NULL; } - c_free(node); + free(node); } msg_queue_t * msg_dequeue(msg_queue_t **head){ diff --git a/app/net/nodemcu_mdns.c b/app/net/nodemcu_mdns.c index a5eb4182..5750a9b7 100644 --- a/app/net/nodemcu_mdns.c +++ b/app/net/nodemcu_mdns.c @@ -48,7 +48,7 @@ #include "osapi.h" #include "os_type.h" #include "user_interface.h" -#include "c_string.h" +#include #include "nodemcu_mdns.h" #if 0 @@ -484,7 +484,7 @@ mdns_send_service(struct nodemcu_mdns_info *info, u16_t id, struct ip_addr *dst_ hdr->numextrarr = htons(1); query = (char*) hdr + SIZEOF_DNS_HDR; query_end = (char *) p->payload + p->tot_len; - c_strlcpy(tmpBuf, service_name_with_suffix, sizeof(tmpBuf)); + strlcpy(tmpBuf, service_name_with_suffix, sizeof(tmpBuf)); pHostname = tmpBuf; --pHostname; @@ -618,9 +618,9 @@ mdns_send_service(struct nodemcu_mdns_info *info, u16_t id, struct ip_addr *dst_ ans.type = htons(DNS_RRTYPE_SRV); ans.class = htons(dns_class); ans.ttl = htonl(min(max_ttl, 300)); - c_strlcpy(tmpBuf,ms_info->host_name, sizeof(tmpBuf)); - c_strlcat(tmpBuf, ".", sizeof(tmpBuf)); - c_strlcat(tmpBuf, MDNS_LOCAL, sizeof(tmpBuf)); + strlcpy(tmpBuf,ms_info->host_name, sizeof(tmpBuf)); + strlcat(tmpBuf, ".", sizeof(tmpBuf)); + strlcat(tmpBuf, MDNS_LOCAL, sizeof(tmpBuf)); length = os_strlen(tmpBuf) + MDNS_LENGTH_ADD; ans.len = htons(SIZEOF_MDNS_SERVICE + length); length = 0; @@ -931,9 +931,9 @@ mdns_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, struct ip_addr *addr, actual_rr = DNS_RRTYPE_PTR; } } else { - c_strlcpy(tmpBuf,ms_info->host_name, sizeof(tmpBuf)); - c_strlcat(tmpBuf, ".", sizeof(tmpBuf)); - c_strlcat(tmpBuf, MDNS_LOCAL, sizeof(tmpBuf)); + strlcpy(tmpBuf,ms_info->host_name, sizeof(tmpBuf)); + strlcat(tmpBuf, ".", sizeof(tmpBuf)); + strlcat(tmpBuf, MDNS_LOCAL, sizeof(tmpBuf)); no_rr_name = tmpBuf; if (mdns_compare_name((unsigned char *) tmpBuf, @@ -944,9 +944,9 @@ mdns_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, struct ip_addr *addr, actual_rr = DNS_RRTYPE_A; } } else { - c_strlcpy(tmpBuf,ms_info->host_desc, sizeof(tmpBuf)); - c_strlcat(tmpBuf, ".", sizeof(tmpBuf)); - c_strlcat(tmpBuf, service_name_with_suffix, sizeof(tmpBuf)); + strlcpy(tmpBuf,ms_info->host_desc, sizeof(tmpBuf)); + strlcat(tmpBuf, ".", sizeof(tmpBuf)); + strlcat(tmpBuf, service_name_with_suffix, sizeof(tmpBuf)); if (mdns_compare_name((unsigned char *) tmpBuf, (unsigned char *) qptr, (unsigned char *) hdr) == 0) { if (qry_type == DNS_RRTYPE_TXT || qry_type == DNS_RRTYPE_SRV || qry_type == DNS_RRTYPE_ANY) { @@ -1003,7 +1003,7 @@ mdns_set_servicename(const char *name) { if (service_name_with_suffix) { os_free(service_name_with_suffix); } - service_name_with_suffix = c_strdup(tmpBuf); + service_name_with_suffix = strdup(tmpBuf); } static u8_t reg_counter; @@ -1029,15 +1029,15 @@ mdns_dup_info(const struct nodemcu_mdns_info *info) { // calculate length int len = sizeof(struct nodemcu_mdns_info); - len += c_strlen(info->host_name) + 1; - len += c_strlen(info->host_desc) + 1; - len += c_strlen(info->service_name) + 1; + len += strlen(info->host_name) + 1; + len += strlen(info->host_desc) + 1; + len += strlen(info->service_name) + 1; int i; for (i = 0; i < sizeof(info->txt_data) / sizeof(info->txt_data[0]) && info->txt_data[i]; i++) { - len += c_strlen(info->txt_data[i]) + 1; + len += strlen(info->txt_data[i]) + 1; } -#define COPY_OVER(dest, src, p) len = c_strlen(src) + 1; memcpy(p, src, len); dest = p; p += len +#define COPY_OVER(dest, src, p) len = strlen(src) + 1; memcpy(p, src, len); dest = p; p += len result = (struct nodemcu_mdns_info *) os_zalloc(len); if (result) { diff --git a/app/pcm/drv_sigma_delta.c b/app/pcm/drv_sigma_delta.c index 967df73e..0fdfe1f7 100644 --- a/app/pcm/drv_sigma_delta.c +++ b/app/pcm/drv_sigma_delta.c @@ -5,7 +5,7 @@ #include "platform.h" #include "hw_timer.h" #include "task/task.h" -#include "c_stdlib.h" +#include #include "pcm.h" diff --git a/app/pcm/pcm_core.c b/app/pcm/pcm_core.c index f489630a..0d347dd4 100644 --- a/app/pcm/pcm_core.c +++ b/app/pcm/pcm_core.c @@ -13,8 +13,8 @@ #include "lauxlib.h" #include "task/task.h" -#include "c_string.h" -#include "c_stdlib.h" +#include +#include #include "pcm.h" @@ -58,9 +58,9 @@ void pcm_data_play( task_param_t param, uint8 prio ) if (lua_type( L, -1 ) == LUA_TSTRING) { data = lua_tolstring( L, -1, &string_len ); if (string_len > buf->buf_size) { - uint8_t *new_data = (uint8_t *) c_malloc( string_len ); + uint8_t *new_data = (uint8_t *) malloc( string_len ); if (new_data) { - if (buf->data) c_free( buf->data ); + if (buf->data) free( buf->data ); buf->buf_size = string_len; buf->data = new_data; } @@ -70,7 +70,7 @@ void pcm_data_play( task_param_t param, uint8 prio ) if (data) { size_t to_copy = string_len > buf->buf_size ? buf->buf_size : string_len; - c_memcpy( buf->data, data, to_copy ); + memcpy( buf->data, data, to_copy ); buf->rpos = 0; buf->len = to_copy; diff --git a/app/platform/common.c b/app/platform/common.c index 7de2a948..e047b114 100644 --- a/app/platform/common.c +++ b/app/platform/common.c @@ -2,8 +2,8 @@ #include "platform.h" #include "common.h" -#include "c_string.h" -#include "c_stdio.h" +#include +#include void cmn_platform_init(void) { @@ -102,7 +102,7 @@ uint32_t platform_flash_write( const void *from, uint32_t toaddr, uint32_t size { rest = toaddr & blkmask; temp = toaddr & ~blkmask; // this is the actual aligned address - // c_memcpy( tmpdata, ( const void* )temp, blksize ); + // memcpy( tmpdata, ( const void* )temp, blksize ); platform_s_flash_read( tmpdata, temp, blksize ); for( i = rest; size && ( i < blksize ); i ++, size --, pfrom ++ ) tmpdata[ i ] = *pfrom; @@ -125,7 +125,7 @@ uint32_t platform_flash_write( const void *from, uint32_t toaddr, uint32_t size // And the final part of a block if needed if( rest ) { - // c_memcpy( tmpdata, ( const void* )toaddr, blksize ); + // memcpy( tmpdata, ( const void* )toaddr, blksize ); platform_s_flash_read( tmpdata, toaddr, blksize ); for( i = 0; size && ( i < rest ); i ++, size --, pfrom ++ ) tmpdata[ i ] = *pfrom; diff --git a/app/platform/flash_api.c b/app/platform/flash_api.c index fb77d04b..813be330 100644 --- a/app/platform/flash_api.c +++ b/app/platform/flash_api.c @@ -6,7 +6,8 @@ #include "user_config.h" #include "flash_api.h" #include "spi_flash.h" -#include "c_stdio.h" +#include +#include uint32_t flash_detect_size_byte(void) { @@ -25,7 +26,7 @@ uint32_t flash_detect_size_byte(void) dummy_size = FLASH_SIZE_256KBYTE; while ((dummy_size < FLASH_SIZE_16MBYTE) && (SPI_FLASH_RESULT_OK == flash_read(dummy_size, (uint32 *)data_new, FLASH_BUFFER_SIZE_DETECT)) && - (0 != os_memcmp(data_orig, data_new, FLASH_BUFFER_SIZE_DETECT)) + (0 != memcmp(data_orig, data_new, FLASH_BUFFER_SIZE_DETECT)) ) { dummy_size *= 2; diff --git a/app/platform/hw_timer.c b/app/platform/hw_timer.c index 938d1809..7d1bc744 100644 --- a/app/platform/hw_timer.c +++ b/app/platform/hw_timer.c @@ -17,8 +17,8 @@ * a small numeric value that is known not to clash. *******************************************************************************/ #include "platform.h" -#include "c_stdio.h" -#include "c_stdlib.h" +#include +#include #include "ets_sys.h" #include "os_type.h" #include "osapi.h" @@ -444,7 +444,7 @@ bool platform_hw_timer_init(os_param_t owner, FRC1_TIMER_SOURCE_TYPE source_type timer_user *tu = find_tu_and_remove(owner); if (!tu) { - tu = (timer_user *) c_malloc(sizeof(*tu)); + tu = (timer_user *) malloc(sizeof(*tu)); if (!tu) { return false; } diff --git a/app/platform/platform.c b/app/platform/platform.c index 4ad94dad..a343652c 100644 --- a/app/platform/platform.c +++ b/app/platform/platform.c @@ -2,9 +2,9 @@ #include "platform.h" #include "common.h" -#include "c_stdio.h" -#include "c_string.h" -#include "c_stdlib.h" +#include +#include +#include #include "llimits.h" #include "gpio.h" #include "user_interface.h" @@ -320,7 +320,7 @@ int platform_gpio_register_intr_hook(uint32_t bits, platform_hook_function hook) } // These return NULL if the count = 0 so only error check if > 0) - nh.entry = c_malloc( nh.count * sizeof(*(nh.entry)) ); + nh.entry = malloc( nh.count * sizeof(*(nh.entry)) ); if (nh.count && !(nh.entry)) { return 0; // Allocation failure } @@ -345,7 +345,7 @@ int platform_gpio_register_intr_hook(uint32_t bits, platform_hook_function hook) platform_gpio_hook = nh; ETS_GPIO_INTR_ENABLE(); - c_free(oh.entry); + free(oh.entry); return 1; } #endif // GPIO_INTERRUPT_HOOK_ENABLE @@ -865,15 +865,15 @@ uint32_t platform_s_flash_write( const void *from, uint32_t toaddr, uint32_t siz uint32_t *apbuf = NULL; uint32_t fromaddr = (uint32_t)from; if( (fromaddr & blkmask ) || (fromaddr >= INTERNAL_FLASH_MAPPED_ADDRESS)) { - apbuf = (uint32_t *)c_malloc(size); + apbuf = (uint32_t *)malloc(size); if(!apbuf) return 0; - c_memcpy(apbuf, from, size); + memcpy(apbuf, from, size); } system_soft_wdt_feed (); r = flash_write(toaddr, apbuf?(uint32 *)apbuf:(uint32 *)from, size); if(apbuf) - c_free(apbuf); + free(apbuf); if(SPI_FLASH_RESULT_OK == r) return size; else{ @@ -903,10 +903,10 @@ uint32_t platform_s_flash_read( void *to, uint32_t fromaddr, uint32_t size ) r = flash_read(fromaddr, to2, size2); if(SPI_FLASH_RESULT_OK == r) { - c_memmove(to,to2,size2); // This is overlapped so must be memmove and not memcpy + memmove(to,to2,size2); // This is overlapped so must be memmove and not memcpy char back[ INTERNAL_FLASH_READ_UNIT_SIZE ] __attribute__ ((aligned(INTERNAL_FLASH_READ_UNIT_SIZE))); r=flash_read(fromaddr+size2,(uint32*)back,INTERNAL_FLASH_READ_UNIT_SIZE); - c_memcpy((uint8_t*)to+size2,back,INTERNAL_FLASH_READ_UNIT_SIZE); + memcpy((uint8_t*)to+size2,back,INTERNAL_FLASH_READ_UNIT_SIZE); } } else @@ -1022,7 +1022,7 @@ uint32_t platform_rcr_write (uint8_t rec_id, const void *inrec, uint8_t n) { rec[0] = 0; rec[nwords] = 0; ((platform_rcr_t *) rec)->id = rec_id; ((platform_rcr_t *) rec)->len = nwords; - c_memcpy(rec+1, inrec, n); // let memcpy handle 0 and odd byte cases + memcpy(rec+1, inrec, n); // let memcpy handle 0 and odd byte cases // find previous copy if any and exit if the replacement is the same value uint8_t np = platform_rcr_read (rec_id, (void **) &prev); @@ -1063,19 +1063,19 @@ uint32_t platform_rcr_write (uint8_t rec_id, const void *inrec, uint8_t n) { } if (pass == 2) memcpy(buf + l, rec, reclen); l += nwords + 1; - if (pass == 1) buf = c_malloc(l * WORDSIZE); + if (pass == 1) buf = malloc(l * WORDSIZE); if (l >= FLASH_SECTOR_WORDS || !buf) return ~0; } platform_flash_erase_sector(flash_addr/INTERNAL_FLASH_SECTOR_SIZE); platform_s_flash_write(buf, flash_addr, l*WORDSIZE); - c_free(buf); + free(buf); } return nwords*WORDSIZE; } void* platform_print_deprecation_note( const char *msg, const char *time_frame) { - c_printf( "Warning, deprecated API! %s. It will be removed %s. See documentation for details.\n", msg, time_frame ); + printf( "Warning, deprecated API! %s. It will be removed %s. See documentation for details.\n", msg, time_frame ); } diff --git a/app/platform/u8x8_nodemcu_hal.c b/app/platform/u8x8_nodemcu_hal.c index 321a3093..82a5a81b 100644 --- a/app/platform/u8x8_nodemcu_hal.c +++ b/app/platform/u8x8_nodemcu_hal.c @@ -6,7 +6,7 @@ #ifdef LUA_USE_MODULES_U8G2 #include -#include "c_stdlib.h" +#include #include "platform.h" @@ -189,7 +189,7 @@ uint8_t u8x8_byte_nodemcu_i2c(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void * { // the user pointer initially contains the i2c id int id = (int)hal; - if (!(hal = c_malloc( sizeof ( hal_i2c_t ) ))) + if (!(hal = malloc( sizeof ( hal_i2c_t ) ))) return 0; hal->id = id; u8x8->user_ptr = hal; @@ -240,7 +240,7 @@ uint8_t u8x8_byte_nodemcu_spi(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void * // the user pointer initially contains the spi host id int host = (int)hal; - if (!(hal = c_malloc( sizeof ( hal_spi_t ) ))) + if (!(hal = malloc( sizeof ( hal_spi_t ) ))) return 0; hal->host = host; u8x8->user_ptr = hal; @@ -260,7 +260,7 @@ uint8_t u8x8_byte_nodemcu_spi(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void * case U8X8_MSG_BYTE_START_TRANSFER: hal->buffer.size = 256; - if (!(hal->buffer.data = (uint8_t *)c_malloc( hal->buffer.size ))) + if (!(hal->buffer.data = (uint8_t *)malloc( hal->buffer.size ))) return 0; hal->buffer.used = 0; @@ -274,13 +274,13 @@ uint8_t u8x8_byte_nodemcu_spi(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void * while (hal->buffer.size - hal->buffer.used < arg_int) { hal->buffer.size *= 2; uint8_t *tmp; - if (!(tmp = (uint8_t *)c_malloc( hal->buffer.size ))) { - c_free( hal->buffer.data ); + if (!(tmp = (uint8_t *)malloc( hal->buffer.size ))) { + free( hal->buffer.data ); hal->buffer.data = NULL; return 0; } os_memcpy( tmp, hal->buffer.data, hal->buffer.used ); - c_free( hal->buffer.data ); + free( hal->buffer.data ); hal->buffer.data = tmp; } os_memcpy( hal->buffer.data + hal->buffer.used, arg_ptr, arg_int ); @@ -295,7 +295,7 @@ uint8_t u8x8_byte_nodemcu_spi(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void * u8x8_gpio_SetCS( u8x8, u8x8->display_info->chip_disable_level ); - c_free( hal->buffer.data ); + free( hal->buffer.data ); hal->buffer.data = NULL; break; diff --git a/app/platform/ucg_nodemcu_hal.c b/app/platform/ucg_nodemcu_hal.c index f579cc8c..a72990f6 100644 --- a/app/platform/ucg_nodemcu_hal.c +++ b/app/platform/ucg_nodemcu_hal.c @@ -5,7 +5,7 @@ #ifdef LUA_USE_MODULES_UCG #include -#include "c_stdlib.h" +#include #include "platform.h" diff --git a/app/platform/vfs.c b/app/platform/vfs.c index 76773985..035c7f99 100644 --- a/app/platform/vfs.c +++ b/app/platform/vfs.c @@ -1,27 +1,28 @@ - - -#include "c_stdlib.h" -#include "c_stdio.h" +#include +#include +#include #include "vfs.h" - +#include "vfs_int.h" #define LDRV_TRAVERSAL 0 +// This interferes with our clearerr member in our ops struct +#undef clearerr // --------------------------------------------------------------------------- // RTC system interface // -static sint32_t (*rtc_cb)( vfs_time *tm ) = NULL; +static int32_t (*rtc_cb)( vfs_time *tm ) = NULL; // called by operating system -void vfs_register_rtc_cb( sint32_t (*cb)( vfs_time *tm ) ) +void vfs_register_rtc_cb( int32_t (*cb)( vfs_time *tm ) ) { // allow NULL pointer to unregister callback function rtc_cb = cb; } // called by file system drivers -sint32_t vfs_get_rtc( vfs_time *tm ) +int32_t vfs_get_rtc( vfs_time *tm ) { if (rtc_cb) { return rtc_cb( tm ); @@ -44,7 +45,7 @@ static const char *normalize_path( const char *path ) const char *temp = path; size_t len; - while ((len = c_strlen( temp )) >= 2) { + while ((len = strlen( temp )) >= 2) { if (temp[0] == '.' && temp[1] == '.') { --dir_level; if (len >= 4 && dir_level > 0) { @@ -88,7 +89,7 @@ vfs_vol *vfs_mount( const char *name, int num ) #ifdef BUILD_FATFS if (fs_fns = myfatfs_realm( normname, &outname, FALSE )) { vfs_vol *r = fs_fns->mount( outname, num ); - c_free( outname ); + free( outname ); return r; } #endif @@ -111,7 +112,7 @@ int vfs_open( const char *name, const char *mode ) #ifdef BUILD_FATFS if (fs_fns = myfatfs_realm( normname, &outname, FALSE )) { int r = (int)fs_fns->open( outname, mode ); - c_free( outname ); + free( outname ); return r; } #endif @@ -134,7 +135,7 @@ vfs_dir *vfs_opendir( const char *name ) #ifdef BUILD_FATFS if (fs_fns = myfatfs_realm( normname, &outname, FALSE )) { vfs_dir *r = fs_fns->opendir( outname ); - c_free( outname ); + free( outname ); return r; } #endif @@ -142,7 +143,7 @@ vfs_dir *vfs_opendir( const char *name ) return NULL; } -sint32_t vfs_stat( const char *name, struct vfs_stat *buf ) +int32_t vfs_stat( const char *name, struct vfs_stat *buf ) { vfs_fs_fns *fs_fns; const char *normname = normalize_path( name ); @@ -156,8 +157,8 @@ sint32_t vfs_stat( const char *name, struct vfs_stat *buf ) #ifdef BUILD_FATFS if (fs_fns = myfatfs_realm( normname, &outname, FALSE )) { - sint32_t r = fs_fns->stat( outname, buf ); - c_free( outname ); + int32_t r = fs_fns->stat( outname, buf ); + free( outname ); return r; } #endif @@ -165,7 +166,7 @@ sint32_t vfs_stat( const char *name, struct vfs_stat *buf ) return VFS_RES_ERR; } -sint32_t vfs_remove( const char *name ) +int32_t vfs_remove( const char *name ) { vfs_fs_fns *fs_fns; const char *normname = normalize_path( name ); @@ -179,8 +180,8 @@ sint32_t vfs_remove( const char *name ) #ifdef BUILD_FATFS if (fs_fns = myfatfs_realm( normname, &outname, FALSE )) { - sint32_t r = fs_fns->remove( outname ); - c_free( outname ); + int32_t r = fs_fns->remove( outname ); + free( outname ); return r; } #endif @@ -188,7 +189,7 @@ sint32_t vfs_remove( const char *name ) return VFS_RES_ERR; } -sint32_t vfs_rename( const char *oldname, const char *newname ) +int32_t vfs_rename( const char *oldname, const char *newname ) { vfs_fs_fns *fs_fns; const char *normoldname = normalize_path( oldname ); @@ -206,19 +207,19 @@ sint32_t vfs_rename( const char *oldname, const char *newname ) #ifdef BUILD_FATFS if (myfatfs_realm( normoldname, &oldoutname, FALSE )) { if (fs_fns = myfatfs_realm( normnewname, &newoutname, FALSE )) { - sint32_t r = fs_fns->rename( oldoutname, newoutname ); - c_free( oldoutname ); - c_free( newoutname ); + int32_t r = fs_fns->rename( oldoutname, newoutname ); + free( oldoutname ); + free( newoutname ); return r; } - c_free( oldoutname ); + free( oldoutname ); } #endif return -1; } -sint32_t vfs_mkdir( const char *name ) +int32_t vfs_mkdir( const char *name ) { vfs_fs_fns *fs_fns; const char *normname = normalize_path( name ); @@ -230,8 +231,8 @@ sint32_t vfs_mkdir( const char *name ) #ifdef BUILD_FATFS if (fs_fns = myfatfs_realm( normname, &outname, FALSE )) { - sint32_t r = fs_fns->mkdir( outname ); - c_free( outname ); + int32_t r = fs_fns->mkdir( outname ); + free( outname ); return r; } #endif @@ -239,7 +240,7 @@ sint32_t vfs_mkdir( const char *name ) return VFS_RES_ERR; } -sint32_t vfs_fsinfo( const char *name, uint32_t *total, uint32_t *used ) +int32_t vfs_fsinfo( const char *name, uint32_t *total, uint32_t *used ) { vfs_fs_fns *fs_fns; char *outname; @@ -256,7 +257,7 @@ sint32_t vfs_fsinfo( const char *name, uint32_t *total, uint32_t *used ) #ifdef BUILD_FATFS if (fs_fns = myfatfs_realm( normname, &outname, FALSE )) { - c_free( outname ); + free( outname ); return fs_fns->fsinfo( total, used ); } #endif @@ -264,7 +265,7 @@ sint32_t vfs_fsinfo( const char *name, uint32_t *total, uint32_t *used ) return VFS_RES_ERR; } -sint32_t vfs_fscfg( const char *name, uint32_t *phys_addr, uint32_t *phys_size) +int32_t vfs_fscfg( const char *name, uint32_t *phys_addr, uint32_t *phys_size) { vfs_fs_fns *fs_fns; char *outname; @@ -283,7 +284,7 @@ sint32_t vfs_fscfg( const char *name, uint32_t *phys_addr, uint32_t *phys_size) return VFS_RES_ERR; } -sint32_t vfs_format( void ) +int32_t vfs_format( void ) { vfs_fs_fns *fs_fns; char *outname; @@ -302,7 +303,7 @@ sint32_t vfs_format( void ) return 0; } -sint32_t vfs_chdir( const char *path ) +int32_t vfs_chdir( const char *path ) { vfs_fs_fns *fs_fns; const char *normpath = normalize_path( path ); @@ -318,9 +319,9 @@ sint32_t vfs_chdir( const char *path ) } else { level = normpath; } - while (c_strlen( level ) > 0) { + while (strlen( level ) > 0) { dir_level++; - if (level = c_strchr( level, '/' )) { + if (level = strchr( level, '/' )) { level++; } else { break; @@ -331,7 +332,7 @@ sint32_t vfs_chdir( const char *path ) #ifdef BUILD_SPIFFS if (fs_fns = myspiffs_realm( normpath, &outname, TRUE )) { // our SPIFFS integration doesn't support directories - if (c_strlen( outname ) == 0) { + if (strlen( outname ) == 0) { ok = VFS_RES_OK; } } @@ -339,7 +340,7 @@ sint32_t vfs_chdir( const char *path ) #ifdef BUILD_FATFS if (fs_fns = myfatfs_realm( normpath, &outname, TRUE )) { - if (c_strchr( outname, ':' )) { + if (strchr( outname, ':' )) { // need to set FatFS' default drive fs_fns->chdrive( outname ); // and force chdir to root in case path points only to root @@ -348,14 +349,14 @@ sint32_t vfs_chdir( const char *path ) if (fs_fns->chdir( outname ) == VFS_RES_OK) { ok = VFS_RES_OK; } - c_free( outname ); + free( outname ); } #endif return ok == VFS_RES_OK ? VFS_RES_OK : VFS_RES_ERR; } -sint32_t vfs_errno( const char *name ) +int32_t vfs_errno( const char *name ) { vfs_fs_fns *fs_fns; char *outname; @@ -372,8 +373,8 @@ sint32_t vfs_errno( const char *name ) #ifdef BUILD_FATFS if (fs_fns = myfatfs_realm( normname, &outname, FALSE )) { - sint32_t r = fs_fns->ferrno( ); - c_free( outname ); + int32_t r = fs_fns->ferrno( ); + free( outname ); return r; } #endif @@ -381,7 +382,7 @@ sint32_t vfs_errno( const char *name ) return VFS_RES_ERR; } -sint32_t vfs_ferrno( int fd ) +int32_t vfs_ferrno( int fd ) { vfs_file *f = (vfs_file *)fd; @@ -400,8 +401,8 @@ sint32_t vfs_ferrno( int fd ) #ifdef BUILD_FATFS if (fs_fns = myfatfs_realm( name, &outname, FALSE )) { - sint32_t r = fs_fns->ferrno( ); - c_free( outname ); + int32_t r = fs_fns->ferrno( ); + free( outname ); return r; } #endif @@ -420,14 +421,14 @@ void vfs_clearerr( const char *name ) #ifdef BUILD_SPIFFS if (fs_fns = myspiffs_realm( normname, &outname, FALSE )) { - fs_fns->clearerr( ); + fs_fns->clearerr ( ); } #endif #ifdef BUILD_FATFS if (fs_fns = myfatfs_realm( normname, &outname, FALSE )) { - fs_fns->clearerr( ); - c_free( outname ); + fs_fns->clearerr ( ); + free( outname ); } #endif } @@ -437,9 +438,9 @@ const char *vfs_basename( const char *path ) const char *basename; // deduce basename (incl. extension) for length check - if (basename = c_strrchr( path, '/' )) { + if (basename = strrchr( path, '/' )) { basename++; - } else if (basename = c_strrchr( path, ':' )) { + } else if (basename = strrchr( path, ':' )) { basename++; } else { basename = path; @@ -455,7 +456,7 @@ const char *vfs_basename( const char *path ) int vfs_getc( int fd ) { unsigned char c = 0xFF; - sint32_t res; + int32_t res; if(!vfs_eof( fd )) { if (1 != vfs_read( fd, &c, 1 )) { diff --git a/app/platform/vfs.h b/app/platform/vfs.h index d0ae29f9..e9784e98 100644 --- a/app/platform/vfs.h +++ b/app/platform/vfs.h @@ -15,7 +15,7 @@ // vfs_close - close file descriptor and free memory // fd: file descriptor // Returns: VFS_RES_OK or negative value in case of error -static sint32_t vfs_close( int fd ) { +static int32_t vfs_close( int fd ) { vfs_file *f = (vfs_file *)fd; return f ? f->fns->close( f ) : VFS_RES_ERR; } @@ -25,7 +25,7 @@ static sint32_t vfs_close( int fd ) { // ptr: destination data buffer // len: requested length // Returns: Number of bytes read, or VFS_RES_ERR in case of error -static sint32_t vfs_read( int fd, void *ptr, size_t len ) { +static int32_t vfs_read( int fd, void *ptr, size_t len ) { vfs_file *f = (vfs_file *)fd; return f ? f->fns->read( f, ptr, len ) : VFS_RES_ERR; } @@ -35,7 +35,7 @@ static sint32_t vfs_read( int fd, void *ptr, size_t len ) { // ptr: source data buffer // len: requested length // Returns: Number of bytes written, or VFS_RES_ERR in case of error -static sint32_t vfs_write( int fd, const void *ptr, size_t len ) { +static int32_t vfs_write( int fd, const void *ptr, size_t len ) { vfs_file *f = (vfs_file *)fd; return f ? f->fns->write( f, ptr, len ) : VFS_RES_ERR; } @@ -51,7 +51,7 @@ int vfs_ungetc( int c, int fd ); // VFS_SEEK_CUR - set pointer to current position + off // VFS_SEEK_END - set pointer to end of file + off // Returns: New position, or VFS_RES_ERR in case of error -static sint32_t vfs_lseek( int fd, sint32_t off, int whence ) { +static int32_t vfs_lseek( int fd, int32_t off, int whence ) { vfs_file *f = (vfs_file *)fd; return f ? f->fns->lseek( f, off, whence ) : VFS_RES_ERR; } @@ -59,7 +59,7 @@ static sint32_t vfs_lseek( int fd, sint32_t off, int whence ) { // vfs_eof - test for end-of-file // fd: file descriptor // Returns: 0 if not at end, != 0 if end of file -static sint32_t vfs_eof( int fd ) { +static int32_t vfs_eof( int fd ) { vfs_file *f = (vfs_file *)fd; return f ? f->fns->eof( f ) : VFS_RES_ERR; } @@ -67,7 +67,7 @@ static sint32_t vfs_eof( int fd ) { // vfs_tell - get read/write position // fd: file descriptor // Returns: Current position -static sint32_t vfs_tell( int fd ) { +static int32_t vfs_tell( int fd ) { vfs_file *f = (vfs_file *)fd; return f ? f->fns->tell( f ) : VFS_RES_ERR; } @@ -75,7 +75,7 @@ static sint32_t vfs_tell( int fd ) { // vfs_flush - flush write cache to file // fd: file descriptor // Returns: VFS_RES_OK, or VFS_RES_ERR in case of error -static sint32_t vfs_flush( int fd ) { +static int32_t vfs_flush( int fd ) { vfs_file *f = (vfs_file *)fd; return f ? f->fns->flush( f ) : VFS_RES_ERR; } @@ -91,7 +91,7 @@ static uint32_t vfs_size( int fd ) { // vfs_ferrno - get file system specific errno // fd: file descriptor // Returns: errno -sint32_t vfs_ferrno( int fd ); +int32_t vfs_ferrno( int fd ); // --------------------------------------------------------------------------- // dir functions @@ -100,13 +100,13 @@ sint32_t vfs_ferrno( int fd ); // vfs_closedir - close directory descriptor and free memory // dd: dir descriptor // Returns: VFS_RES_OK, or VFS_RES_ERR in case of error -static sint32_t vfs_closedir( vfs_dir *dd ) { return dd->fns->close( dd ); } +static int32_t vfs_closedir( vfs_dir *dd ) { return dd->fns->close( dd ); } // vfs_readdir - read next directory item // dd: dir descriptor // buf: pre-allocated stat structure to be filled in // Returns: VFS_RES_OK if next item found, otherwise VFS_RES_ERR -static sint32_t vfs_readdir( vfs_dir *dd, struct vfs_stat *buf ) { return dd->fns->readdir( dd, buf ); } +static int32_t vfs_readdir( vfs_dir *dd, struct vfs_stat *buf ) { return dd->fns->readdir( dd, buf ); } // --------------------------------------------------------------------------- // volume functions @@ -115,7 +115,7 @@ static sint32_t vfs_readdir( vfs_dir *dd, struct vfs_stat *buf ) { return dd->fn // vfs_umount - unmount logical drive and free memory // vol: volume object // Returns: VFS_RES_OK, or VFS_RES_ERR in case of error -static sint32_t vfs_umount( vfs_vol *vol ) { return vol->fns->umount( vol ); } +static int32_t vfs_umount( vfs_vol *vol ) { return vol->fns->umount( vol ); } // --------------------------------------------------------------------------- // file system functions @@ -142,56 +142,56 @@ vfs_dir *vfs_opendir( const char *name ); // name: file or directory name // buf: pre-allocated structure to be filled in // Returns: VFS_RES_OK, or VFS_RES_ERR in case of error -sint32_t vfs_stat( const char *name, struct vfs_stat *buf ); +int32_t vfs_stat( const char *name, struct vfs_stat *buf ); // vfs_remove - remove file or directory // name: file or directory name // Returns: VFS_RES_OK, or VFS_RES_ERR in case of error -sint32_t vfs_remove( const char *name ); +int32_t vfs_remove( const char *name ); // vfs_rename - rename file or directory // name: file or directory name // Returns: VFS_RES_OK, or VFS_RES_ERR in case of error -sint32_t vfs_rename( const char *oldname, const char *newname ); +int32_t vfs_rename( const char *oldname, const char *newname ); // vfs_mkdir - create directory // name: directory name // Returns: VFS_RES_OK, or VFS_RES_ERR in case of error -sint32_t vfs_mkdir( const char *name ); +int32_t vfs_mkdir( const char *name ); // vfs_fsinfo - get file system info // name: logical drive identifier // total: receives total amount // used: received used amount // Returns: VFS_RES_OK, or VFS_RES_ERR in case of error -sint32_t vfs_fsinfo( const char *name, uint32_t *total, uint32_t *used ); +int32_t vfs_fsinfo( const char *name, uint32_t *total, uint32_t *used ); // vfs_format - format file system // Returns: 1, or 0 in case of error -sint32_t vfs_format( void ); +int32_t vfs_format( void ); // vfs_chdir - change default directory // path: new default directory // Returns: VFS_RES_OK, or VFS_RES_ERR in case of error -sint32_t vfs_chdir( const char *path ); +int32_t vfs_chdir( const char *path ); // vfs_fscfg - query configuration settings of file system // phys_addr: pointer to store physical address information // phys_size: pointer to store physical size information // Returns: VFS_RES_OK, or VFS_RES_ERR in case of error -sint32_t vfs_fscfg( const char *name, uint32_t *phys_addr, uint32_t *phys_size); +int32_t vfs_fscfg( const char *name, uint32_t *phys_addr, uint32_t *phys_size); // vfs_errno - get file system specific errno // name: logical drive identifier // Returns: errno -sint32_t vfs_errno( const char *name ); +int32_t vfs_errno( const char *name ); // vfs_clearerr - cleaer file system specific errno void vfs_clearerr( const char *name ); // vfs_register_rtc_cb - register callback function for RTC query // cb: pointer to callback function -void vfs_register_rtc_cb( sint32_t (*cb)( vfs_time *tm ) ); +void vfs_register_rtc_cb( int32_t (*cb)( vfs_time *tm ) ); // vfs_basename - identify basename (incl. extension) // path: full file system path diff --git a/app/platform/vfs_int.h b/app/platform/vfs_int.h index f1a0539f..3fccd675 100644 --- a/app/platform/vfs_int.h +++ b/app/platform/vfs_int.h @@ -3,16 +3,10 @@ #ifndef __VFS_INT_H__ #define __VFS_INT_H__ -#include -#include - -#if 0 -#include "spiffs.h" - -#include "fatfs_prefix_lib.h" -#include "ff.h" -#endif +#include +#include +#include "user_config.h" #define VFS_EOF -1 @@ -62,15 +56,15 @@ struct vfs_stat { // file descriptor functions struct vfs_file_fns { - sint32_t (*close)( const struct vfs_file *fd ); - sint32_t (*read)( const struct vfs_file *fd, void *ptr, size_t len ); - sint32_t (*write)( const struct vfs_file *fd, const void *ptr, size_t len ); - sint32_t (*lseek)( const struct vfs_file *fd, sint32_t off, int whence ); - sint32_t (*eof)( const struct vfs_file *fd ); - sint32_t (*tell)( const struct vfs_file *fd ); - sint32_t (*flush)( const struct vfs_file *fd ); + int32_t (*close)( const struct vfs_file *fd ); + int32_t (*read)( const struct vfs_file *fd, void *ptr, size_t len ); + int32_t (*write)( const struct vfs_file *fd, const void *ptr, size_t len ); + int32_t (*lseek)( const struct vfs_file *fd, int32_t off, int whence ); + int32_t (*eof)( const struct vfs_file *fd ); + int32_t (*tell)( const struct vfs_file *fd ); + int32_t (*flush)( const struct vfs_file *fd ); uint32_t (*size)( const struct vfs_file *fd ); - sint32_t (*ferrno)( const struct vfs_file *fd ); + int32_t (*ferrno)( const struct vfs_file *fd ); }; typedef const struct vfs_file_fns vfs_file_fns; @@ -83,8 +77,8 @@ typedef const struct vfs_dir vfs_dir; // dir descriptor functions struct vfs_dir_fns { - sint32_t (*close)( const struct vfs_dir *dd ); - sint32_t (*readdir)( const struct vfs_dir *dd, struct vfs_stat *buf ); + int32_t (*close)( const struct vfs_dir *dd ); + int32_t (*readdir)( const struct vfs_dir *dd, struct vfs_stat *buf ); }; typedef const struct vfs_dir_fns vfs_dir_fns; @@ -97,7 +91,7 @@ typedef const struct vfs_vol vfs_vol; // volume functions struct vfs_vol_fns { - sint32_t (*umount)( const struct vfs_vol *vol ); + int32_t (*umount)( const struct vfs_vol *vol ); }; typedef const struct vfs_vol_fns vfs_vol_fns; @@ -105,17 +99,17 @@ struct vfs_fs_fns { vfs_vol *(*mount)( const char *name, int num ); vfs_file *(*open)( const char *name, const char *mode ); vfs_dir *(*opendir)( const char *name ); - sint32_t (*stat)( const char *name, struct vfs_stat *buf ); - sint32_t (*remove)( const char *name ); - sint32_t (*rename)( const char *oldname, const char *newname ); - sint32_t (*mkdir)( const char *name ); - sint32_t (*fsinfo)( uint32_t *total, uint32_t *used ); - sint32_t (*fscfg)( uint32_t *phys_addr, uint32_t *phys_size ); - sint32_t (*format)( void ); - sint32_t (*chdrive)( const char * ); - sint32_t (*chdir)( const char * ); - sint32_t (*ferrno)( void ); - void (*clearerr)( void ); + int32_t (*stat)( const char *name, struct vfs_stat *buf ); + int32_t (*remove)( const char *name ); + int32_t (*rename)( const char *oldname, const char *newname ); + int32_t (*mkdir)( const char *name ); + int32_t (*fsinfo)( uint32_t *total, uint32_t *used ); + int32_t (*fscfg)( uint32_t *phys_addr, uint32_t *phys_size ); + int32_t (*format)( void ); + int32_t (*chdrive)( const char * ); + int32_t (*chdir)( const char * ); + int32_t (*ferrno)( void ); + void (*clearerr)( void ); }; typedef const struct vfs_fs_fns vfs_fs_fns; @@ -123,6 +117,6 @@ typedef const struct vfs_fs_fns vfs_fs_fns; vfs_fs_fns *myspiffs_realm( const char *inname, char **outname, int set_current_drive ); vfs_fs_fns *myfatfs_realm( const char *inname, char **outname, int set_current_drive ); -sint32_t vfs_get_rtc( vfs_time *tm ); +int32_t vfs_get_rtc( vfs_time *tm ); #endif diff --git a/app/pm/swtimer.c b/app/pm/swtimer.c index 64fbeeb0..0e89a3fd 100644 --- a/app/pm/swtimer.c +++ b/app/pm/swtimer.c @@ -37,16 +37,17 @@ * Once there are no more suspended timers, the function returns * * - */#include "module.h" + */ +#include "module.h" #include "lauxlib.h" #include "platform.h" #include "user_interface.h" #include "user_modules.h" -#include "c_string.h" -#include "c_stdlib.h" -#include "ctype.h" +#include +#include +#include #include "c_types.h" @@ -138,7 +139,7 @@ void swtmr_suspend_timers(){ size_t registered_cb_qty = lua_objlen(L, -1); //allocate a temporary array to hold the list of callback pointers - cb_registry_item_t** cb_reg_array = c_zalloc(sizeof(cb_registry_item_t*)*registered_cb_qty); + cb_registry_item_t** cb_reg_array = calloc(1,sizeof(cb_registry_item_t*)*registered_cb_qty); if(!cb_reg_array){ luaL_error(L, "%s: unable to suspend timers, out of memory!", __func__); return; @@ -242,7 +243,7 @@ void swtmr_suspend_timers(){ } //tmr_cb_ptr_array is no longer needed. - c_free(cb_reg_array); + free(cb_reg_array); //add suspended_timer_list pointer to swtimer table. lua_pushstring(L, SUSP_LIST_STR); @@ -391,7 +392,7 @@ void swtmr_cb_register(void* timer_cb_ptr, uint8 suspend_policy){ static void add_to_reg_queue(void* timer_cb_ptr, uint8 suspend_policy){ if(!timer_cb_ptr) return; - tmr_cb_queue_t* queue_temp = c_zalloc(sizeof(tmr_cb_queue_t)); + tmr_cb_queue_t* queue_temp = calloc(1,sizeof(tmr_cb_queue_t)); if(!queue_temp){ //it's boot time currently and we're already out of memory, something is very wrong... dbg_printf("\n\t%s:out of memory, rebooting.", __FUNCTION__); @@ -430,7 +431,7 @@ static void process_cb_register_queue(task_param_t param, uint8 priority) void* cb_ptr_tmp = register_queue_ptr->tmr_cb_ptr; swtmr_cb_register(cb_ptr_tmp, register_queue_ptr->suspend_policy); register_queue = register_queue->next; - c_free(register_queue_ptr); + free(register_queue_ptr); } return; } @@ -457,7 +458,7 @@ int print_timer_list(lua_State* L){ } lua_pop(L, 1); size_t registered_cb_qty = lua_objlen(L, -1); - cb_registry_item_t** cb_reg_array = c_zalloc(sizeof(cb_registry_item_t*)*registered_cb_qty); + cb_registry_item_t** cb_reg_array = calloc(1,sizeof(cb_registry_item_t*)*registered_cb_qty); if(!cb_reg_array){ luaL_error(L, "%s: unable to suspend timers, out of memory!", __func__); return 0; @@ -490,7 +491,7 @@ int print_timer_list(lua_State* L){ timer_list_ptr = timer_list_ptr->timer_next; } - c_free(cb_reg_array); + free(cb_reg_array); lua_pop(L, 1); return 0; diff --git a/app/sjson/memcompat.h b/app/sjson/memcompat.h index 2e3f84fb..7112e201 100644 --- a/app/sjson/memcompat.h +++ b/app/sjson/memcompat.h @@ -4,8 +4,4 @@ #include "c_types.h" #include "mem.h" -static inline void *malloc(size_t sz) { return os_malloc(sz); } -static inline void free(void *p) { return os_free(p); } -static inline void *calloc(size_t n, size_t sz) { return os_zalloc(n*sz); } - #endif diff --git a/app/smart/smart.c b/app/smart/smart.c index 18af2a86..77b2cdf8 100644 --- a/app/smart/smart.c +++ b/app/smart/smart.c @@ -1,6 +1,6 @@ -#include "c_stdio.h" -#include "c_stdlib.h" -#include "c_string.h" +#include +#include +#include #include "user_interface.h" #include "smart.h" #include "pm/swtimer.h" @@ -39,7 +39,7 @@ int smart_check(uint8_t *nibble, uint16_t len, uint8_t *dst, uint8_t *got){ uint16_t dst_len = len/NIBBLE_PER_BYTE; uint16_t byte_num = 0, bit_num = 0; int i = 0, res = 1; // assume ok. - c_memset(dst,0,dst_len); + memset(dst,0,dst_len); if(NIBBLE_PER_BYTE==1){ for(i=0;ibase_len == am[i]->flag[0]) // store new source-dest adress pair to the map until flag[0] is got { // BSSID, SA, DA, store the SA, DA - c_memcpy(am[i]->addr, &buf[ADDR_MATCH_START], ADDR_MATCH_LENGTH); + memcpy(am[i]->addr, &buf[ADDR_MATCH_START], ADDR_MATCH_LENGTH); am[i]->flag_match_num++; // =1 am[i]->cur_base_seq = seq; // assume the first seq is found am[i]->base_seq_valid = 1; @@ -169,7 +169,7 @@ void detect(uint8 *arg, uint16 len){ } break; // break any way for the next packet to come } - else if(0 == c_memcmp(am[i]->addr, &buf[ADDR_MATCH_START], ADDR_MATCH_LENGTH)){ // source-dest adress pair match + else if(0 == memcmp(am[i]->addr, &buf[ADDR_MATCH_START], ADDR_MATCH_LENGTH)){ // source-dest adress pair match if(am[i]->base_seq_valid == 0){ if ( len - am[i]->base_len == am[i]->flag[0]) { // found the new flag[0] // here flag_match_num is already = 1 @@ -236,7 +236,7 @@ void detect(uint8 *arg, uint16 len){ // break out, or loop done. goto end; } else { // cur_base_seq is ref to SSID_FLAG when patern is alread found - if(0 != c_memcmp(matched->addr, &buf[ADDR_MATCH_START], ADDR_MATCH_LENGTH)){ // source-dest adress pair not match, ignore it + if(0 != memcmp(matched->addr, &buf[ADDR_MATCH_START], ADDR_MATCH_LENGTH)){ // source-dest adress pair not match, ignore it return; } if (matched->base_seq_valid == 0){ // SSID_FLAG seq invalid, need to find the next valid seq number @@ -455,7 +455,7 @@ void reset_map(smart_addr_map **am, size_t num){ am[i]->base_seq_valid = 0; am[i]->ssid_len = 0; am[i]->pwd_len = 0; - c_memset(am[i]->addr, 0, ADDR_MATCH_LENGTH); + memset(am[i]->addr, 0, ADDR_MATCH_LENGTH); if(SEP_1_INDEX==0){ am[i]->flag[0] = SEP_1; am[i]->flag[1] = SEP_2; @@ -511,34 +511,34 @@ void smart_end(){ for (i = 0; i < ADDR_MAP_NUM; ++i) { if(am[i]){ - c_free(am[i]); + free(am[i]); am[i] = NULL; } matched = NULL; } if(sta_conf){ - c_free(sta_conf); + free(sta_conf); sta_conf = NULL; } if(got_password){ - c_free(got_password); + free(got_password); got_password = NULL; } if(got_ssid){ - c_free(got_ssid); + free(got_ssid); got_ssid = NULL; } if(password_nibble){ - c_free(password_nibble); + free(password_nibble); password_nibble = NULL; } if(ssid_nibble){ - c_free(ssid_nibble); + free(ssid_nibble); ssid_nibble = NULL; } // system_restart(); // restart to enable the mode @@ -583,14 +583,14 @@ void smart_next_channel(){ NODE_ERR("switch to channel %d\n", cur_channel); wifi_set_channel(cur_channel); reset_map(am, ADDR_MAP_NUM); - c_memset(sta_conf->ssid, 0, sizeof(sta_conf->ssid)); - c_memset(sta_conf->password, 0, sizeof(sta_conf->password)); + memset(sta_conf->ssid, 0, sizeof(sta_conf->ssid)); + memset(sta_conf->password, 0, sizeof(sta_conf->password)); - c_memset(got_ssid, 0, SSID_BIT_MAX); - c_memset(got_password, 0, PWD_BIT_MAX); + memset(got_ssid, 0, SSID_BIT_MAX); + memset(got_password, 0, PWD_BIT_MAX); - c_memset(ssid_nibble, 0, SSID_NIBBLE_MAX); - c_memset(password_nibble, 0, PWD_NIBBLE_MAX); + memset(ssid_nibble, 0, SSID_NIBBLE_MAX); + memset(password_nibble, 0, PWD_NIBBLE_MAX); os_timer_disarm(&smart_timer); os_timer_arm(&smart_timer, TIME_OUT_PER_CHANNEL, 0); // no repeat @@ -604,7 +604,7 @@ void smart_begin(int chnl, smart_succeed s, void *arg){ for (i = 0; i < ADDR_MAP_NUM; ++i) { if(!am[i]){ - am[i] = (smart_addr_map*)c_zalloc(sizeof(smart_addr_map)); + am[i] = (smart_addr_map*)calloc(1,sizeof(smart_addr_map)); if(!am[i]){ NODE_DBG("smart_begin map no memory\n"); smart_end(); @@ -613,7 +613,7 @@ void smart_begin(int chnl, smart_succeed s, void *arg){ } } if(!sta_conf){ - sta_conf = (struct station_config *)c_zalloc(sizeof(struct station_config)); + sta_conf = (struct station_config *)calloc(1,sizeof(struct station_config)); if(!sta_conf){ NODE_DBG("smart_begin sta_conf no memory\n"); smart_end(); @@ -622,7 +622,7 @@ void smart_begin(int chnl, smart_succeed s, void *arg){ } if(!ssid_nibble){ - ssid_nibble = (uint8_t *)c_zalloc(SSID_NIBBLE_MAX); + ssid_nibble = (uint8_t *)calloc(1,SSID_NIBBLE_MAX); if(!ssid_nibble){ NODE_DBG("smart_begin sta_conf no memory\n"); smart_end(); @@ -631,7 +631,7 @@ void smart_begin(int chnl, smart_succeed s, void *arg){ } if(!password_nibble){ - password_nibble = (uint8_t *)c_zalloc(PWD_NIBBLE_MAX); + password_nibble = (uint8_t *)calloc(1,PWD_NIBBLE_MAX); if(!password_nibble){ NODE_DBG("smart_begin sta_conf no memory\n"); smart_end(); @@ -640,7 +640,7 @@ void smart_begin(int chnl, smart_succeed s, void *arg){ } if(!got_ssid){ - got_ssid = (uint8_t *)c_zalloc(SSID_BIT_MAX); + got_ssid = (uint8_t *)calloc(1,SSID_BIT_MAX); if(!got_ssid){ NODE_DBG("smart_begin sta_conf no memory\n"); smart_end(); @@ -649,7 +649,7 @@ void smart_begin(int chnl, smart_succeed s, void *arg){ } if(!got_password){ - got_password = (uint8_t *)c_zalloc(PWD_BIT_MAX); + got_password = (uint8_t *)calloc(1,PWD_BIT_MAX); if(!got_password){ NODE_DBG("smart_begin sta_conf no memory\n"); smart_end(); @@ -657,14 +657,14 @@ void smart_begin(int chnl, smart_succeed s, void *arg){ } } reset_map(am, ADDR_MAP_NUM); - // c_memset(sta_conf->ssid, 0, sizeof(sta_conf->ssid)); - // c_memset(sta_conf->password, 0, sizeof(sta_conf->password)); + // memset(sta_conf->ssid, 0, sizeof(sta_conf->ssid)); + // memset(sta_conf->password, 0, sizeof(sta_conf->password)); - // c_memset(got_ssid, 0, SSID_BIT_MAX); - // c_memset(got_password, 0, PWD_BIT_MAX); + // memset(got_ssid, 0, SSID_BIT_MAX); + // memset(got_password, 0, PWD_BIT_MAX); - // c_memset(ssid_nibble, 0, SSID_NIBBLE_MAX); - // c_memset(password_nibble, 0, PWD_NIBBLE_MAX); + // memset(ssid_nibble, 0, SSID_NIBBLE_MAX); + // memset(password_nibble, 0, PWD_NIBBLE_MAX); mode = wifi_get_opmode(); if( (STATION_MODE == mode) || (mode == STATIONAP_MODE) ){ wifi_station_set_auto_connect(false); diff --git a/app/spiffs/Makefile b/app/spiffs/Makefile index 2b1af59f..688bc9f3 100644 --- a/app/spiffs/Makefile +++ b/app/spiffs/Makefile @@ -22,7 +22,6 @@ endif # makefile at its root level - these are then overridden # for a subtree within the makefile rooted therein # -DEFINES += -Dprintf=c_printf #DEFINES += -DDEVELOPMENT_TOOLS -DNODE_DEBUG -DSPIFFS_API_DBG=NODE_DBG ############################################################# diff --git a/app/spiffs/nodemcu_spiffs.h b/app/spiffs/nodemcu_spiffs.h index e4026d62..3a8b2c45 100644 --- a/app/spiffs/nodemcu_spiffs.h +++ b/app/spiffs/nodemcu_spiffs.h @@ -2,11 +2,10 @@ #define _NODEMCU_SPIFFS_H #ifndef NODEMCU_SPIFFS_NO_INCLUDE -#include "c_stdint.h" -#include "c_stddef.h" -#include "c_stdio.h" +#include +#include +#include #include "user_interface.h" -typedef uint32_t intptr_t; #endif // Turn off stats diff --git a/app/spiffs/spiffs.c b/app/spiffs/spiffs.c index 1809b0f3..57f15a27 100644 --- a/app/spiffs/spiffs.c +++ b/app/spiffs/spiffs.c @@ -1,4 +1,4 @@ -#include "c_stdio.h" +#include #include "platform.h" #include "spiffs.h" @@ -170,7 +170,7 @@ int myspiffs_format( void ) // vfs API // *************************************************************************** -#include +#include #include "vfs_int.h" #define MY_LDRV_ID "FLASH" @@ -281,7 +281,7 @@ static sint32_t myspiffs_vfs_closedir( const struct vfs_dir *dd ) { sint32_t res = SPIFFS_closedir( d ); // free descriptor memory - c_free( (void *)dd ); + free( (void *)dd ); } static sint32_t myspiffs_vfs_readdir( const struct vfs_dir *dd, struct vfs_stat *buf ) { @@ -289,11 +289,11 @@ static sint32_t myspiffs_vfs_readdir( const struct vfs_dir *dd, struct vfs_stat struct spiffs_dirent dirent; if (SPIFFS_readdir( d, &dirent )) { - c_memset( buf, 0, sizeof( struct vfs_stat ) ); + memset( buf, 0, sizeof( struct vfs_stat ) ); // copy entries to item // fill in supported stat entries - c_strncpy( buf->name, dirent.name, FS_OBJ_NAME_LEN+1 ); + strncpy( buf->name, dirent.name, FS_OBJ_NAME_LEN+1 ); buf->name[FS_OBJ_NAME_LEN] = '\0'; buf->size = dirent.size; return VFS_RES_OK; @@ -316,7 +316,7 @@ static sint32_t myspiffs_vfs_close( const struct vfs_file *fd ) { sint32_t res = SPIFFS_close( &fs, fh ); // free descriptor memory - c_free( (void *)fd ); + free( (void *)fd ); return res; } @@ -392,21 +392,21 @@ static sint32_t myspiffs_vfs_ferrno( const struct vfs_file *fd ) { static int fs_mode2flag(const char *mode){ - if(c_strlen(mode)==1){ - if(c_strcmp(mode,"w")==0) + if(strlen(mode)==1){ + if(strcmp(mode,"w")==0) return SPIFFS_WRONLY|SPIFFS_CREAT|SPIFFS_TRUNC; - else if(c_strcmp(mode, "r")==0) + else if(strcmp(mode, "r")==0) return SPIFFS_RDONLY; - else if(c_strcmp(mode, "a")==0) + else if(strcmp(mode, "a")==0) return SPIFFS_WRONLY|SPIFFS_CREAT|SPIFFS_APPEND; else return SPIFFS_RDONLY; - } else if (c_strlen(mode)==2){ - if(c_strcmp(mode,"r+")==0) + } else if (strlen(mode)==2){ + if(strcmp(mode,"r+")==0) return SPIFFS_RDWR; - else if(c_strcmp(mode, "w+")==0) + else if(strcmp(mode, "w+")==0) return SPIFFS_RDWR|SPIFFS_CREAT|SPIFFS_TRUNC; - else if(c_strcmp(mode, "a+")==0) + else if(strcmp(mode, "a+")==0) return SPIFFS_RDWR|SPIFFS_CREAT|SPIFFS_APPEND; else return SPIFFS_RDONLY; @@ -422,13 +422,13 @@ static vfs_file *myspiffs_vfs_open( const char *name, const char *mode ) { struct myvfs_file *fd; int flags = fs_mode2flag( mode ); - if (fd = (struct myvfs_file *)c_malloc( sizeof( struct myvfs_file ) )) { + if (fd = (struct myvfs_file *)malloc( sizeof( struct myvfs_file ) )) { if (0 < (fd->fh = SPIFFS_open( &fs, name, flags, 0 ))) { fd->vfs_file.fs_type = VFS_FS_SPIFFS; fd->vfs_file.fns = &myspiffs_file_fns; return (vfs_file *)fd; } else { - c_free( fd ); + free( fd ); } } @@ -438,13 +438,13 @@ static vfs_file *myspiffs_vfs_open( const char *name, const char *mode ) { static vfs_dir *myspiffs_vfs_opendir( const char *name ){ struct myvfs_dir *dd; - if (dd = (struct myvfs_dir *)c_malloc( sizeof( struct myvfs_dir ) )) { + if (dd = (struct myvfs_dir *)malloc( sizeof( struct myvfs_dir ) )) { if (SPIFFS_opendir( &fs, name, &(dd->d) )) { dd->vfs_dir.fs_type = VFS_FS_SPIFFS; dd->vfs_dir.fns = &myspiffs_dd_fns; return (vfs_dir *)dd; } else { - c_free( dd ); + free( dd ); } } @@ -455,10 +455,10 @@ static sint32_t myspiffs_vfs_stat( const char *name, struct vfs_stat *buf ) { spiffs_stat stat; if (0 <= SPIFFS_stat( &fs, name, &stat )) { - c_memset( buf, 0, sizeof( struct vfs_stat ) ); + memset( buf, 0, sizeof( struct vfs_stat ) ); // fill in supported stat entries - c_strncpy( buf->name, stat.name, FS_OBJ_NAME_LEN+1 ); + strncpy( buf->name, stat.name, FS_OBJ_NAME_LEN+1 ); buf->name[FS_OBJ_NAME_LEN] = '\0'; buf->size = stat.size; @@ -511,7 +511,7 @@ static void myspiffs_vfs_clearerr( void ) { vfs_fs_fns *myspiffs_realm( const char *inname, char **outname, int set_current_drive ) { if (inname[0] == '/') { // logical drive is specified, check if it's our id - if (0 == c_strncmp(inname + 1, MY_LDRV_ID, sizeof(MY_LDRV_ID)-1)) { + if (0 == strncmp(inname + 1, MY_LDRV_ID, sizeof(MY_LDRV_ID)-1)) { *outname = (char *)(inname + sizeof(MY_LDRV_ID)); if (*outname[0] == '/') { // skip leading / diff --git a/app/sqlite3/esp8266.c b/app/sqlite3/esp8266.c index 99809167..1cd8f1da 100644 --- a/app/sqlite3/esp8266.c +++ b/app/sqlite3/esp8266.c @@ -7,10 +7,10 @@ * http://www.sqlite.org/src/doc/trunk/src/test_vfs.c **/ -#include -#include -#include -#include +#include +#include +#include +#include "c_types.h" #include #include #include diff --git a/app/sqlite3/sqlite3.c b/app/sqlite3/sqlite3.c index 0f550abf..8cfe9305 100644 --- a/app/sqlite3/sqlite3.c +++ b/app/sqlite3/sqlite3.c @@ -11017,7 +11017,7 @@ struct fts5_api { ** Include standard header files as necessary */ #ifdef HAVE_STDINT_H -#include +#include #endif #ifdef HAVE_INTTYPES_H #include @@ -11608,9 +11608,9 @@ SQLITE_PRIVATE void sqlite3HashClear(Hash*); /************** End of parse.h ***********************************************/ /************** Continuing where we left off in sqliteInt.h ******************/ -#include -#include -#include +#include +#include +#include #include #include @@ -12585,7 +12585,7 @@ SQLITE_PRIVATE int sqlite3SchemaMutexHeld(sqlite3*,int,Schema*); */ #ifndef SQLITE_VDBE_H #define SQLITE_VDBE_H -/* #include */ +/* #include */ /* ** A single VDBE is an opaque structure named "Vdbe". Only routines @@ -18868,7 +18868,7 @@ SQLITE_API int sqlite3_db_status( ** Richmond, Virginia (USA) */ /* #include "sqliteInt.h" */ -/* #include */ +/* #include */ /* #include */ #include @@ -20978,7 +20978,7 @@ SQLITE_PRIVATE void sqlite3MemSetDefault(void){ # define backtrace(A,B) 1 # define backtrace_symbols_fd(A,B,C) #endif -/* #include */ +/* #include */ /* ** Each memory allocation looks like this: diff --git a/app/task/task.c b/app/task/task.c index 5d68c76e..e9bc9ef6 100644 --- a/app/task/task.c +++ b/app/task/task.c @@ -3,7 +3,7 @@ */ #include "task/task.h" #include "mem.h" -#include "c_stdio.h" +#include #define TASK_HANDLE_MONIKER 0x68680000 #define TASK_HANDLE_MASK 0xFFF80000 diff --git a/app/u8g2lib/u8x8_d_fbrle.c b/app/u8g2lib/u8x8_d_fbrle.c index 93875513..8dd74360 100644 --- a/app/u8g2lib/u8x8_d_fbrle.c +++ b/app/u8g2lib/u8x8_d_fbrle.c @@ -6,7 +6,7 @@ #include "u8x8_nodemcu_hal.h" -#include "c_stdlib.h" +#include static const u8x8_display_info_t u8x8_fbrle_display_info = @@ -104,7 +104,7 @@ static uint8_t u8x8_d_fbrle(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *ar uint8_t *buf = ((u8x8_tile_t *)arg_ptr)->tile_ptr; struct fbrle_line *fbrle_line; - if (!(fbrle_line = (struct fbrle_line *)c_malloc( fbrle_line_size ))) { + if (!(fbrle_line = (struct fbrle_line *)malloc( fbrle_line_size ))) { break; } @@ -147,7 +147,7 @@ static uint8_t u8x8_d_fbrle(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *ar } } - c_free( fbrle_line ); + free( fbrle_line ); } break; diff --git a/app/libc/dbg_printf.c b/app/user/dbg_printf.c similarity index 98% rename from app/libc/dbg_printf.c rename to app/user/dbg_printf.c index 0772b696..6dcb5895 100644 --- a/app/libc/dbg_printf.c +++ b/app/user/dbg_printf.c @@ -39,9 +39,9 @@ // overflows. The downside is that it does not implement a wide range // of formatting characters. -#include -#include -#include +#include +#include +#include #include "driver/uart.h" static void kprintn (void (*)(const char), uint32_t, int, int, char); diff --git a/app/user/user_main.c b/app/user/user_main.c index 008e384b..9afb1fb8 100644 --- a/app/user/user_main.c +++ b/app/user/user_main.c @@ -10,9 +10,9 @@ *******************************************************************************/ #include "lua.h" #include "platform.h" -#include "c_string.h" -#include "c_stdlib.h" -#include "c_stdio.h" +#include +#include +#include #include "vfs.h" #include "flash_api.h" #include "user_interface.h" diff --git a/app/uzlib/uzlib.h b/app/uzlib/uzlib.h index ae9c99ac..0627f44e 100644 --- a/app/uzlib/uzlib.h +++ b/app/uzlib/uzlib.h @@ -12,21 +12,20 @@ #define UZLIB_INFLATE_H #include +#include +#include + +#define uz_malloc malloc +#define uz_free free #if defined(__XTENSA__) -#include "c_stdint.h" #include "mem.h" #define UZLIB_THROW(v) longjmp(unwindAddr, (v)) #define UZLIB_SETJMP setjmp -#define uz_malloc os_malloc -#define uz_free os_free #else /* Host */ -#include -#include - extern int dbg_break(void); #if defined(_MSC_VER) || defined(__MINGW32__) //msvc requires old name for longjmp #define UZLIB_THROW(v) {dbg_break();longjmp(unwindAddr, (v));} @@ -36,9 +35,6 @@ extern int dbg_break(void); #define UZLIB_SETJMP(n) _setjmp(n) #endif -#define uz_malloc malloc -#define uz_free free - #endif /* defined(__XTENSA__) */ extern jmp_buf unwindAddr; diff --git a/app/uzlib/uzlib_inflate.c b/app/uzlib/uzlib_inflate.c index 39456053..a3eec362 100644 --- a/app/uzlib/uzlib_inflate.c +++ b/app/uzlib/uzlib_inflate.c @@ -39,11 +39,7 @@ */ #include -#ifdef __XTENSA__ -#include "c_stdio.h" -#else #include -#endif #include "uzlib.h" diff --git a/app/websocket/websocketclient.c b/app/websocket/websocketclient.c index 8a4bbd69..b96e4726 100644 --- a/app/websocket/websocketclient.c +++ b/app/websocket/websocketclient.c @@ -30,9 +30,9 @@ #include "stdlib.h" #include "c_types.h" -#include "c_string.h" -#include "c_stdlib.h" -#include "c_stdio.h" +#include +#include +#include #include "websocketclient.h" @@ -83,7 +83,7 @@ static char *cryptoSha1(char *data, unsigned int len) { SHA1Init(&ctx); SHA1Update(&ctx, data, len); - uint8_t *digest = (uint8_t *) c_zalloc(20); + uint8_t *digest = (uint8_t *) calloc(1,20); SHA1Final(digest, &ctx); return (char *) digest; // Requires free } @@ -93,7 +93,7 @@ static const char *bytes64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwx static char *base64Encode(char *data, unsigned int len) { int blen = (len + 2) / 3 * 4; - char *out = (char *) c_zalloc(blen + 1); + char *out = (char *) calloc(1,blen + 1); out[blen] = '\0'; int j = 0, i; for (i = 0; i < len; i += 3) { @@ -197,7 +197,7 @@ static void ws_sendFrame(struct espconn *conn, int opCode, const char *data, uns return; } - char *b = c_zalloc(10 + len); // 10 bytes = worst case scenario for framming + char *b = calloc(1,10 + len); // 10 bytes = worst case scenario for framming if (b == NULL) { NODE_DBG("Out of memory when receiving message, disconnecting...\n"); @@ -301,7 +301,7 @@ static void ws_receiveCallback(void *arg, char *buf, unsigned short len) { if (ws->frameBuffer != NULL) { // Append previous frameBuffer with new content NODE_DBG("Appending new frameBuffer to old one \n"); - ws->frameBuffer = c_realloc(ws->frameBuffer, ws->frameBufferLen + len); + ws->frameBuffer = realloc(ws->frameBuffer, ws->frameBufferLen + len); if (ws->frameBuffer == NULL) { NODE_DBG("Failed to allocate new framebuffer, disconnecting...\n"); @@ -358,7 +358,7 @@ static void ws_receiveCallback(void *arg, char *buf, unsigned short len) { NODE_DBG("INCOMPLETE Frame \n"); if (ws->frameBuffer == NULL) { NODE_DBG("Allocing new frameBuffer \n"); - ws->frameBuffer = c_zalloc(len); + ws->frameBuffer = calloc(1,len); if (ws->frameBuffer == NULL) { NODE_DBG("Failed to allocate framebuffer, disconnecting... \n"); @@ -379,7 +379,7 @@ static void ws_receiveCallback(void *arg, char *buf, unsigned short len) { NODE_DBG("PARTIAL frame! Should concat payload and later restore opcode\n"); if(ws->payloadBuffer == NULL) { NODE_DBG("Allocing new payloadBuffer \n"); - ws->payloadBuffer = c_zalloc(payloadLength); + ws->payloadBuffer = calloc(1,payloadLength); if (ws->payloadBuffer == NULL) { NODE_DBG("Failed to allocate payloadBuffer, disconnecting...\n"); @@ -395,7 +395,7 @@ static void ws_receiveCallback(void *arg, char *buf, unsigned short len) { ws->payloadOriginalOpCode = opCode; } else { NODE_DBG("Appending new payloadBuffer to old one \n"); - ws->payloadBuffer = c_realloc(ws->payloadBuffer, ws->payloadBufferLen + payloadLength); + ws->payloadBuffer = realloc(ws->payloadBuffer, ws->payloadBufferLen + payloadLength); if (ws->payloadBuffer == NULL) { NODE_DBG("Failed to allocate new framebuffer, disconnecting...\n"); @@ -425,7 +425,7 @@ static void ws_receiveCallback(void *arg, char *buf, unsigned short len) { return; } // concat buffer with payload - payload = c_zalloc(ws->payloadBufferLen + payloadLength); + payload = calloc(1,ws->payloadBufferLen + payloadLength); if (payload == NULL) { NODE_DBG("Failed to allocate new framebuffer, disconnecting...\n"); @@ -457,7 +457,7 @@ static void ws_receiveCallback(void *arg, char *buf, unsigned short len) { extensionDataOffset += 2; } - payload = c_zalloc(payloadLength - extensionDataOffset + 1); + payload = calloc(1,payloadLength - extensionDataOffset + 1); if (payload == NULL) { NODE_DBG("Failed to allocate payload, disconnecting...\n"); @@ -511,7 +511,7 @@ static void ws_receiveCallback(void *arg, char *buf, unsigned short len) { if (ws->frameBuffer != NULL) { NODE_DBG("Reallocing frameBuffer to remove consumed frame\n"); - ws->frameBuffer = c_realloc(ws->frameBuffer, ws->frameBufferLen + len); + ws->frameBuffer = realloc(ws->frameBuffer, ws->frameBufferLen + len); if (ws->frameBuffer == NULL) { NODE_DBG("Failed to allocate new frame buffer, disconnecting...\n"); @@ -738,12 +738,12 @@ void ws_connect(ws_info *ws, const char *url) { } // Extract protocol - either ws or wss - bool isSecure = c_strncasecmp(url, PROTOCOL_SECURE, strlen(PROTOCOL_SECURE)) == 0; + bool isSecure = strncasecmp(url, PROTOCOL_SECURE, strlen(PROTOCOL_SECURE)) == 0; if (isSecure) { url += strlen(PROTOCOL_SECURE); } else { - if (c_strncasecmp(url, PROTOCOL_INSECURE, strlen(PROTOCOL_INSECURE)) != 0) { + if (strncasecmp(url, PROTOCOL_INSECURE, strlen(PROTOCOL_INSECURE)) != 0) { NODE_DBG("Failed to extract protocol from: %s\n", url); if (ws->onFailure) ws->onFailure(ws, -1); return; @@ -752,7 +752,7 @@ void ws_connect(ws_info *ws, const char *url) { } // Extract path - it should start with '/' - char *path = c_strchr(url, '/'); + char *path = strchr(url, '/'); // Extract hostname, possibly including port char hostname[256]; @@ -800,9 +800,9 @@ void ws_connect(ws_info *ws, const char *url) { // Prepare internal ws_info ws->connectionState = 1; ws->isSecure = isSecure; - ws->hostname = c_strdup(hostname); + ws->hostname = strdup(hostname); ws->port = port; - ws->path = c_strdup(path); + ws->path = strdup(path); ws->expectedSecKey = NULL; ws->knownFailureCode = 0; ws->frameBuffer = NULL; @@ -813,10 +813,10 @@ void ws_connect(ws_info *ws, const char *url) { ws->unhealthyPoints = 0; // Prepare espconn - struct espconn *conn = (struct espconn *) c_zalloc(sizeof(struct espconn)); + struct espconn *conn = (struct espconn *) calloc(1,sizeof(struct espconn)); conn->type = ESPCONN_TCP; conn->state = ESPCONN_NONE; - conn->proto.tcp = (esp_tcp *) c_zalloc(sizeof(esp_tcp)); + conn->proto.tcp = (esp_tcp *) calloc(1,sizeof(esp_tcp)); conn->proto.tcp->local_port = espconn_port(); conn->proto.tcp->remote_port = ws->port; diff --git a/ld/defsym.rom b/ld/defsym.rom index 5369fb0f..542201dc 100644 --- a/ld/defsym.rom +++ b/ld/defsym.rom @@ -4,6 +4,7 @@ --defsym=strncmp=ets_strncmp --defsym=strncpy=ets_strncpy --defsym=strstr=ets_strstr +--defsym=strdup=ets_strdup --defsym=memcmp=ets_memcmp --defsym=memcpy=ets_memcpy --defsym=memmove=ets_memmove diff --git a/sdk-overrides/include/c_types.h b/sdk-overrides/include/c_types.h deleted file mode 100644 index 115b66af..00000000 --- a/sdk-overrides/include/c_types.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef _OVERRIDE_C_TYPES_H_ -#define _OVERRIDE_C_TYPES_H_ - -#include_next "c_types.h" - -typedef long long int64_t; -typedef int8_t sint8_t; -typedef int16_t sint16_t; -typedef int64_t sint64_t; - -#endif diff --git a/sdk-overrides/include/ets_sys.h b/sdk-overrides/include/ets_sys.h index eb4cf80d..157e835f 100644 --- a/sdk-overrides/include/ets_sys.h +++ b/sdk-overrides/include/ets_sys.h @@ -3,7 +3,7 @@ #include_next "ets_sys.h" -#include "../libc/c_stdarg.h" +#include int ets_sprintf(char *str, const char *format, ...) __attribute__ ((format (printf, 2, 3))); diff --git a/sdk-overrides/include/mem.h b/sdk-overrides/include/mem.h new file mode 100644 index 00000000..b55c7bd5 --- /dev/null +++ b/sdk-overrides/include/mem.h @@ -0,0 +1,2 @@ +#include +#include_next "mem.h" diff --git a/sdk-overrides/include/osapi.h b/sdk-overrides/include/osapi.h index 7b751c37..4e503f8a 100644 --- a/sdk-overrides/include/osapi.h +++ b/sdk-overrides/include/osapi.h @@ -1,11 +1,10 @@ #ifndef _SDK_OVERRIDE_OSAPI_H_ #define _SDK_OVERRIDE_OSAPI_H_ -#include "rom.h" +#include_next "osapi.h" -int atoi(const char *nptr); -int os_printf(const char *format, ...) __attribute__ ((format (printf, 1, 2))); -int os_printf_plus(const char *format, ...) __attribute__ ((format (printf, 1, 2))); +#include +#include "rom.h" unsigned int uart_baudrate_detect(unsigned int uart_no, unsigned int async); @@ -13,6 +12,4 @@ void NmiTimSetFunc(void (*func)(void)); void call_user_start(void); -#include_next "osapi.h" - #endif diff --git a/sdk-overrides/include/stdbool.h b/sdk-overrides/include/stdbool.h new file mode 100644 index 00000000..2d7131d3 --- /dev/null +++ b/sdk-overrides/include/stdbool.h @@ -0,0 +1,7 @@ +#ifndef __stdbool_h__ +#define __stdbool_h__ + +// For compatibility with SDK. Boo. +#include_next "c_types.h" + +#endif diff --git a/sdk-overrides/include/stdio.h b/sdk-overrides/include/stdio.h new file mode 100644 index 00000000..1abc104a --- /dev/null +++ b/sdk-overrides/include/stdio.h @@ -0,0 +1,21 @@ +#ifndef _OVERRIDE_STDIO_H_ +#define _OVERRIDE_STDIO_H_ + +#include_next "stdio.h" + +#ifdef __BUFSIZ__ +# define BUFSIZ __BUFSIZ__ +#else +# define BUFSIZ 1024 +#endif + +#define printf(...) do { \ + unsigned char __printf_buf[BUFSIZ]; \ + sprintf(__printf_buf, __VA_ARGS__); \ + puts(__printf_buf); \ +} while(0) + +extern void output_redirect(const char *str); +#define puts output_redirect + +#endif diff --git a/sdk-overrides/include/stdlib.h b/sdk-overrides/include/stdlib.h new file mode 100644 index 00000000..a420d3ca --- /dev/null +++ b/sdk-overrides/include/stdlib.h @@ -0,0 +1,13 @@ +#ifndef _OVERRIDE_STDLIB_H_ +#define _OVERRIDE_STDLIB_H_ + +#include_next "stdlib.h" + +#include "mem.h" + +#define free os_free +#define malloc os_malloc +#define calloc(n,sz) os_zalloc(n*sz) +#define realloc os_realloc + +#endif