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

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

The PR removed the bulk of non-newlib headers from the NodeMCU source base.  
app/libc has now been cut down to the bare minimum overrides to shadow the 
corresponding functions in the SDK's libc. The old c_xyz.h headerfiles have been 
nuked in favour of the standard <xyz.h> headers, with a few exceptions over in 
sdk-overrides. Again, shipping a libc.a without headers is a terrible thing to do. We're 
still living on a prayer that libc was configured the same was as a default-configured
xtensa gcc toolchain assumes it is. That part I cannot do anything about, unfortunately, 
but it's no worse than it has been before.

This enables our source files to compile successfully using the standard header files, 
and use the typical malloc()/calloc()/realloc()/free(), the strwhatever()s and 
memwhatever()s. These end up, through macro and linker magic, mapped to the 
appropriate SDK or ROM functions.
parent 9f8b74de
...@@ -90,31 +90,33 @@ COMPONENTS_eagle.app.v6 = \ ...@@ -90,31 +90,33 @@ COMPONENTS_eagle.app.v6 = \
# only those) modules are pulled in. # only those) modules are pulled in.
SELECTED_MODULE_SYMS=$(filter %_module_selected %module_selected1,$(shell $(NM) modules/.output/$(TARGET)/$(FLAVOR)/lib/libmodules.a)) SELECTED_MODULE_SYMS=$(filter %_module_selected %module_selected1,$(shell $(NM) modules/.output/$(TARGET)/$(FLAVOR)/lib/libmodules.a))
LINKFLAGS_eagle.app.v6 = \ LINKFLAGS_eagle.app.v6 = \
-Wl,--gc-sections \ -Wl,--gc-sections \
-Wl,-Map=mapfile \ -Wl,-Map=mapfile \
-nostdlib \ -nostdlib \
-T$(LD_FILE) \ -T$(LD_FILE) \
-Wl,@../ld/defsym.rom \ -Wl,@../ld/defsym.rom \
-Wl,--no-check-sections \ -Wl,--no-check-sections \
-Wl,-static \ -Wl,-static \
$(addprefix -u , $(SELECTED_MODULE_SYMS)) \ $(addprefix -u , $(SELECTED_MODULE_SYMS)) \
-Wl,--start-group \ -Wl,--start-group \
-lmain \ -lmain \
-lc \ $(DEP_LIBS_eagle.app.v6)\
-Wl,--end-group \
-Wl,--start-group \
-lgcc \ -lgcc \
-lhal \ -lhal \
-lphy \ -lphy \
-lpp \ -lpp \
-lnet80211 \ -lnet80211 \
-lsmartconfig \
-lwpa \ -lwpa \
-lwpa2 \ -lwpa2 \
-lsmartconfig \
-lcrypto \ -lcrypto \
-lwps \ -lwps \
$(DEP_LIBS_eagle.app.v6) \ -lc \
-Wl,--end-group \ -lm \
-lm -Wl,--end-group
# -Wl,--cref # -Wl,--cref
# -Wl,--wrap=_xtos_set_exception_handler # -Wl,--wrap=_xtos_set_exception_handler
......
#include "user_config.h" #include "user_config.h"
#include "c_stdio.h" #include <stdio.h>
#include "c_string.h" #include <string.h>
#include "coap.h" #include "coap.h"
#include "uri.h" #include "uri.h"
...@@ -10,12 +10,12 @@ extern const coap_endpoint_t endpoints[]; ...@@ -10,12 +10,12 @@ extern const coap_endpoint_t endpoints[];
#ifdef COAP_DEBUG #ifdef COAP_DEBUG
void coap_dumpHeader(coap_header_t *hdr) void coap_dumpHeader(coap_header_t *hdr)
{ {
c_printf("Header:\n"); printf("Header:\n");
c_printf(" ver 0x%02X\n", hdr->ver); printf(" ver 0x%02X\n", hdr->ver);
c_printf(" t 0x%02X\n", hdr->ver); printf(" t 0x%02X\n", hdr->ver);
c_printf(" tkl 0x%02X\n", hdr->tkl); printf(" tkl 0x%02X\n", hdr->tkl);
c_printf(" code 0x%02X\n", hdr->code); printf(" code 0x%02X\n", hdr->code);
c_printf(" id 0x%02X%02X\n", hdr->id[0], hdr->id[1]); printf(" id 0x%02X%02X\n", hdr->id[0], hdr->id[1]);
} }
void coap_dump(const uint8_t *buf, size_t buflen, bool bare) 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) ...@@ -23,14 +23,14 @@ void coap_dump(const uint8_t *buf, size_t buflen, bool bare)
if (bare) if (bare)
{ {
while(buflen--) while(buflen--)
c_printf("%02X%s", *buf++, (buflen > 0) ? " " : ""); printf("%02X%s", *buf++, (buflen > 0) ? " " : "");
} }
else else
{ {
c_printf("Dump: "); printf("Dump: ");
while(buflen--) while(buflen--)
c_printf("%02X%s", *buf++, (buflen > 0) ? " " : ""); printf("%02X%s", *buf++, (buflen > 0) ? " " : "");
c_printf("\n"); printf("\n");
} }
} }
#endif #endif
...@@ -100,7 +100,7 @@ int coap_buildToken(const coap_buffer_t *tokbuf, const coap_header_t *hdr, uint8 ...@@ -100,7 +100,7 @@ int coap_buildToken(const coap_buffer_t *tokbuf, const coap_header_t *hdr, uint8
return COAP_ERR_UNSUPPORTED; return COAP_ERR_UNSUPPORTED;
if (hdr->tkl > 0) 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 // http://tools.ietf.org/html/rfc7252#section-3.1
// inject options // inject options
...@@ -260,12 +260,12 @@ int coap_buildOptionHeader(uint32_t optDelta, size_t length, uint8_t *buf, size_ ...@@ -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) void coap_dumpOptions(coap_option_t *opts, size_t numopt)
{ {
size_t i; size_t i;
c_printf(" Options:\n"); printf(" Options:\n");
for (i=0;i<numopt;i++) for (i=0;i<numopt;i++)
{ {
c_printf(" 0x%02X [ ", opts[i].num); printf(" 0x%02X [ ", opts[i].num);
coap_dump(opts[i].buf.p, opts[i].buf.len, true); coap_dump(opts[i].buf.p, opts[i].buf.len, true);
c_printf(" ]\n"); printf(" ]\n");
} }
} }
...@@ -273,9 +273,9 @@ void coap_dumpPacket(coap_packet_t *pkt) ...@@ -273,9 +273,9 @@ void coap_dumpPacket(coap_packet_t *pkt)
{ {
coap_dumpHeader(&pkt->hdr); coap_dumpHeader(&pkt->hdr);
coap_dumpOptions(pkt->opts, pkt->numopts); coap_dumpOptions(pkt->opts, pkt->numopts);
c_printf("Payload: "); printf("Payload: ");
coap_dump(pkt->payload.p, pkt->payload.len, true); coap_dump(pkt->payload.p, pkt->payload.len, true);
c_printf("\n"); printf("\n");
} }
#endif #endif
...@@ -325,7 +325,7 @@ int coap_buffer_to_string(char *strbuf, size_t strbuflen, const coap_buffer_t *b ...@@ -325,7 +325,7 @@ int coap_buffer_to_string(char *strbuf, size_t strbuflen, const coap_buffer_t *b
{ {
if (buf->len+1 > strbuflen) if (buf->len+1 > strbuflen)
return COAP_ERR_BUFFER_TOO_SMALL; return COAP_ERR_BUFFER_TOO_SMALL;
c_memcpy(strbuf, buf->p, buf->len); memcpy(strbuf, buf->p, buf->len);
strbuf[buf->len] = 0; strbuf[buf->len] = 0;
return 0; return 0;
} }
...@@ -360,7 +360,7 @@ int coap_build(uint8_t *buf, size_t *buflen, const coap_packet_t *pkt) ...@@ -360,7 +360,7 @@ int coap_build(uint8_t *buf, size_t *buflen, const coap_packet_t *pkt)
p += rc; p += rc;
left -= 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; p += pkt->opts[i].buf.len;
left -= pkt->opts[i].buf.len; left -= pkt->opts[i].buf.len;
running_delta = pkt->opts[i].num; running_delta = pkt->opts[i].num;
...@@ -373,7 +373,7 @@ int coap_build(uint8_t *buf, size_t *buflen, const coap_packet_t *pkt) ...@@ -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) if (*buflen < 4 + 1 + pkt->payload.len + opts_len)
return COAP_ERR_BUFFER_TOO_SMALL; return COAP_ERR_BUFFER_TOO_SMALL;
buf[4 + opts_len] = 0xFF; // payload marker 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; *buflen = opts_len + 5 + pkt->payload.len;
} }
else else
...@@ -471,7 +471,7 @@ int coap_make_request(coap_rw_buffer_t *scratch, coap_packet_t *pkt, coap_msgtyp ...@@ -471,7 +471,7 @@ int coap_make_request(coap_rw_buffer_t *scratch, coap_packet_t *pkt, coap_msgtyp
/* split arg into Uri-* options */ /* split arg into Uri-* options */
// const char *addr = uri->host.s; // 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){ if(uri->host.length){
/* add Uri-Host */ /* add Uri-Host */
// addr is destination address // addr is destination address
...@@ -525,9 +525,9 @@ int coap_handle_req(coap_rw_buffer_t *scratch, const coap_packet_t *inpkt, coap_ ...@@ -525,9 +525,9 @@ int coap_handle_req(coap_rw_buffer_t *scratch, const coap_packet_t *inpkt, coap_
goto next; goto next;
for (i=0;i<ep->path->count;i++) for (i=0;i<ep->path->count;i++)
{ {
if (opt[i].buf.len != c_strlen(ep->path->elems[i])) if (opt[i].buf.len != strlen(ep->path->elems[i]))
goto next; 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; goto next;
} }
// pre-path match! // pre-path match!
...@@ -551,5 +551,5 @@ void coap_setup(void) ...@@ -551,5 +551,5 @@ void coap_setup(void)
int int
check_token(coap_packet_t *pkt) { check_token(coap_packet_t *pkt) {
return pkt->tok.len == the_token.len && c_memcmp(pkt->tok.p, the_token.p, the_token.len) == 0; return pkt->tok.len == the_token.len && memcmp(pkt->tok.p, the_token.p, the_token.len) == 0;
} }
...@@ -5,8 +5,8 @@ ...@@ -5,8 +5,8 @@
extern "C" { extern "C" {
#endif #endif
#include "c_stdint.h" #include <stdint.h>
#include "c_stddef.h" #include <stddef.h>
#include "lualib.h" #include "lualib.h"
#include "lauxlib.h" #include "lauxlib.h"
......
#include "c_string.h" #include <string.h>
#include "coap_io.h" #include "coap_io.h"
#include "node.h" #include "node.h"
#include "espconn.h" #include "espconn.h"
...@@ -16,10 +16,10 @@ coap_tid_t coap_send(struct espconn *pesp_conn, coap_pdu_t *pdu) { ...@@ -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); espconn_sent(pesp_conn, (unsigned char *)(pdu->msg.p), pdu->msg.len);
if(pesp_conn->type == ESPCONN_TCP){ 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; port = pesp_conn->proto.tcp->remote_port;
}else{ }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; port = pesp_conn->proto.udp->remote_port;
} }
coap_transaction_id(ip, port, pdu->pkt, &id); coap_transaction_id(ip, port, pdu->pkt, &id);
......
#include "user_config.h" #include "user_config.h"
#include "c_types.h" #include "c_types.h"
#include "c_stdlib.h" #include <stdlib.h>
#include "coap.h" #include "coap.h"
...@@ -51,7 +51,7 @@ size_t coap_server_respond(char *req, unsigned short reqlen, char *rsp, unsigned ...@@ -51,7 +51,7 @@ size_t coap_server_respond(char *req, unsigned short reqlen, char *rsp, unsigned
#endif #endif
} }
if(rsppkt.content.p){ if(rsppkt.content.p){
c_free(rsppkt.content.p); free(rsppkt.content.p);
rsppkt.content.p = NULL; rsppkt.content.p = NULL;
rsppkt.content.len = 0; rsppkt.content.len = 0;
} }
......
#include "node.h" #include "node.h"
#include "coap_timer.h" #include "coap_timer.h"
#include "os_type.h" #include "os_type.h"
#include "osapi.h"
#include "pm/swtimer.h" #include "pm/swtimer.h"
static os_timer_t coap_timer; static os_timer_t coap_timer;
......
#include "c_stdio.h" #include <stdio.h>
#include "c_string.h" #include <string.h>
#include "c_stdlib.h" #include <stdlib.h>
#include "coap.h" #include "coap.h"
#include "lua.h" #include "lua.h"
...@@ -21,14 +21,14 @@ void endpoint_setup(void) ...@@ -21,14 +21,14 @@ void endpoint_setup(void)
static const coap_endpoint_path_t path_well_known_core = {2, {".well-known", "core"}}; 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) 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){ if(outpkt->content.p == NULL){
NODE_DBG("not enough memory\n"); NODE_DBG("not enough memory\n");
return COAP_ERR_BUFFER_TOO_SMALL; return COAP_ERR_BUFFER_TOO_SMALL;
} }
outpkt->content.len = MAX_PAYLOAD_SIZE; outpkt->content.len = MAX_PAYLOAD_SIZE;
build_well_known_rsp(outpkt->content.p, outpkt->content.len); 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"}}; 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 ...@@ -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) coap_luser_entry *h = ep->user_entry->next; // ->next: skip the first entry(head)
while(NULL != h){ 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; h = h->next;
continue; 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("/v1/v/");
NODE_DBG((char *)h->name); NODE_DBG((char *)h->name);
NODE_DBG(" match.\n"); NODE_DBG(" match.\n");
if(c_strlen(h->name)) if(strlen(h->name))
{ {
n = lua_gettop(L); n = lua_gettop(L);
lua_getglobal(L, h->name); lua_getglobal(L, h->name);
...@@ -70,7 +70,7 @@ static int handle_get_variable(const coap_endpoint_t *ep, coap_rw_buffer_t *scra ...@@ -70,7 +70,7 @@ static int handle_get_variable(const coap_endpoint_t *ep, coap_rw_buffer_t *scra
} else { } else {
const char *res = lua_tostring(L,-1); const char *res = lua_tostring(L,-1);
lua_settop(L, n); 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 { } else {
...@@ -105,18 +105,18 @@ static int handle_post_function(const coap_endpoint_t *ep, coap_rw_buffer_t *scr ...@@ -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) coap_luser_entry *h = ep->user_entry->next; // ->next: skip the first entry(head)
while(NULL != h){ 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; h = h->next;
continue; 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("/v1/f/");
NODE_DBG((char *)h->name); NODE_DBG((char *)h->name);
NODE_DBG(" match.\n"); NODE_DBG(" match.\n");
if(c_strlen(h->name)) if(strlen(h->name))
{ {
n = lua_gettop(L); n = lua_gettop(L);
lua_getglobal(L, h->name); lua_getglobal(L, h->name);
...@@ -173,7 +173,7 @@ static int handle_post_command(const coap_endpoint_t *ep, coap_rw_buffer_t *scra ...@@ -173,7 +173,7 @@ static int handle_post_command(const coap_endpoint_t *ep, coap_rw_buffer_t *scra
{ {
char line[LUA_MAXINPUT]; char line[LUA_MAXINPUT];
if (!coap_buffer_to_string(line, LUA_MAXINPUT, &inpkt->payload) && 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"); NODE_DBG("\nResult(if any):\n");
system_os_post (LUA_TASK_PRIO, LUA_PROCESS_LINE_SIG, 0); 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) ...@@ -211,7 +211,7 @@ void build_well_known_rsp(char *rsp, uint16_t rsplen)
int i; int i;
uint16_t len = rsplen; uint16_t len = rsplen;
c_memset(rsp, 0, len); memset(rsp, 0, len);
len--; // Null-terminated string len--; // Null-terminated string
...@@ -222,57 +222,57 @@ void build_well_known_rsp(char *rsp, uint16_t rsplen) ...@@ -222,57 +222,57 @@ void build_well_known_rsp(char *rsp, uint16_t rsplen)
continue; continue;
} }
if (NULL == ep->user_entry){ if (NULL == ep->user_entry){
if (0 < c_strlen(rsp)) { if (0 < strlen(rsp)) {
c_strncat(rsp, ",", len); strncat(rsp, ",", len);
len--; len--;
} }
c_strncat(rsp, "<", len); strncat(rsp, "<", len);
len--; len--;
for (i = 0; i < ep->path->count; i++) { for (i = 0; i < ep->path->count; i++) {
c_strncat(rsp, "/", len); strncat(rsp, "/", len);
len--; len--;
c_strncat(rsp, ep->path->elems[i], len); strncat(rsp, ep->path->elems[i], len);
len -= c_strlen(ep->path->elems[i]); len -= strlen(ep->path->elems[i]);
} }
c_strncat(rsp, ">;", len); strncat(rsp, ">;", len);
len -= 2; len -= 2;
c_strncat(rsp, ep->core_attr, len); strncat(rsp, ep->core_attr, len);
len -= c_strlen(ep->core_attr); len -= strlen(ep->core_attr);
} else { } else {
coap_luser_entry *h = ep->user_entry->next; // ->next: skip the first entry(head) coap_luser_entry *h = ep->user_entry->next; // ->next: skip the first entry(head)
while(NULL != h){ while(NULL != h){
if (0 < c_strlen(rsp)) { if (0 < strlen(rsp)) {
c_strncat(rsp, ",", len); strncat(rsp, ",", len);
len--; len--;
} }
c_strncat(rsp, "<", len); strncat(rsp, "<", len);
len--; len--;
for (i = 0; i < ep->path->count; i++) { for (i = 0; i < ep->path->count; i++) {
c_strncat(rsp, "/", len); strncat(rsp, "/", len);
len--; len--;
c_strncat(rsp, ep->path->elems[i], len); strncat(rsp, ep->path->elems[i], len);
len -= c_strlen(ep->path->elems[i]); len -= strlen(ep->path->elems[i]);
} }
c_strncat(rsp, "/", len); strncat(rsp, "/", len);
len--; len--;
c_strncat(rsp, h->name, len); strncat(rsp, h->name, len);
len -= c_strlen(h->name); len -= strlen(h->name);
c_strncat(rsp, ">;", len); strncat(rsp, ">;", len);
len -= 2; len -= 2;
c_strncat(rsp, ep->core_attr, len); strncat(rsp, ep->core_attr, len);
len -= c_strlen(ep->core_attr); len -= strlen(ep->core_attr);
h = h->next; h = h->next;
} }
......
#include "hash.h" #include "hash.h"
#include "c_string.h" #include <string.h>
/* Caution: When changing this, update COAP_DEFAULT_WKC_HASHKEY /* Caution: When changing this, update COAP_DEFAULT_WKC_HASHKEY
* accordingly (see int coap_hash_path()); * accordingly (see int coap_hash_path());
*/ */
...@@ -20,7 +20,7 @@ void coap_hash(const unsigned char *s, unsigned int len, coap_key_t h) { ...@@ -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) { 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; coap_key_t h;
c_memset(h, 0, sizeof(coap_key_t)); memset(h, 0, sizeof(coap_key_t));
/* Compare the transport address. */ /* Compare the transport address. */
coap_hash((const unsigned char *)&(port), sizeof(port), h); coap_hash((const unsigned char *)&(port), sizeof(port), h);
......
#include "c_string.h" #include <string.h>
#include "c_stdlib.h" #include <stdlib.h>
#include "node.h" #include "node.h"
static inline coap_queue_t * static inline coap_queue_t *
coap_malloc_node(void) { 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) { 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) { int coap_insert_node(coap_queue_t **queue, coap_queue_t *node) {
...@@ -73,7 +73,7 @@ coap_queue_t * coap_new_node(void) { ...@@ -73,7 +73,7 @@ coap_queue_t * coap_new_node(void) {
return NULL; return NULL;
} }
c_memset(node, 0, sizeof(*node)); memset(node, 0, sizeof(*node));
return node; return node;
} }
......
#include "c_stdlib.h" #include <stdlib.h>
#include "pdu.h" #include "pdu.h"
coap_pdu_t * coap_new_pdu(void) { coap_pdu_t * coap_new_pdu(void) {
coap_pdu_t *pdu = NULL; 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){ if(!pdu){
NODE_DBG("coap_new_pdu malloc error.\n"); NODE_DBG("coap_new_pdu malloc error.\n");
return NULL; 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){ if(!pdu->scratch.p){
NODE_DBG("coap_new_pdu malloc error.\n"); NODE_DBG("coap_new_pdu malloc error.\n");
c_free(pdu); free(pdu);
return NULL; return NULL;
} }
pdu->scratch.len = MAX_REQ_SCRATCH_SIZE; 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){ if(!pdu->pkt){
NODE_DBG("coap_new_pdu malloc error.\n"); NODE_DBG("coap_new_pdu malloc error.\n");
c_free(pdu->scratch.p); free(pdu->scratch.p);
c_free(pdu); free(pdu);
return NULL; return NULL;
} }
pdu->pkt->content.p = NULL; pdu->pkt->content.p = NULL;
pdu->pkt->content.len = 0; 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){ if(!pdu->msg.p){
NODE_DBG("coap_new_pdu malloc error.\n"); NODE_DBG("coap_new_pdu malloc error.\n");
c_free(pdu->pkt); free(pdu->pkt);
c_free(pdu->scratch.p); free(pdu->scratch.p);
c_free(pdu); free(pdu);
return NULL; return NULL;
} }
pdu->msg.len = MAX_REQUEST_SIZE; pdu->msg.len = MAX_REQUEST_SIZE;
...@@ -44,22 +44,22 @@ void coap_delete_pdu(coap_pdu_t *pdu){ ...@@ -44,22 +44,22 @@ void coap_delete_pdu(coap_pdu_t *pdu){
return; return;
if(pdu->scratch.p){ if(pdu->scratch.p){
c_free(pdu->scratch.p); free(pdu->scratch.p);
pdu->scratch.p = NULL; pdu->scratch.p = NULL;
pdu->scratch.len = 0; pdu->scratch.len = 0;
} }
if(pdu->pkt){ if(pdu->pkt){
c_free(pdu->pkt); free(pdu->pkt);
pdu->pkt = NULL; pdu->pkt = NULL;
} }
if(pdu->msg.p){ if(pdu->msg.p){
c_free(pdu->msg.p); free(pdu->msg.p);
pdu->msg.p = NULL; pdu->msg.p = NULL;
pdu->msg.len = 0; pdu->msg.len = 0;
} }
c_free(pdu); free(pdu);
pdu = NULL; pdu = NULL;
} }
...@@ -6,23 +6,23 @@ ...@@ -6,23 +6,23 @@
* README for terms of use. * README for terms of use.
*/ */
#include "c_stdlib.h" #include <stdlib.h>
#include "c_types.h" #include "c_types.h"
#include "str.h" #include "str.h"
str * coap_new_string(size_t size) { 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 ) { if ( !s ) {
return NULL; return NULL;
} }
c_memset(s, 0, sizeof(str)); memset(s, 0, sizeof(str));
s->s = ((unsigned char *)s) + sizeof(str); s->s = ((unsigned char *)s) + sizeof(str);
return s; return s;
} }
void coap_delete_string(str *s) { void coap_delete_string(str *s) {
c_free(s); free(s);
} }
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
#ifndef _COAP_STR_H_ #ifndef _COAP_STR_H_
#define _COAP_STR_H_ #define _COAP_STR_H_
#include "c_string.h" #include <string.h>
typedef struct { typedef struct {
size_t length; /* length of string */ size_t length; /* length of string */
......
/* uri.c -- helper functions for URI treatment /* uri.c -- helper functions for URI treatment
*/ */
#include "c_stdio.h" #include <stdio.h>
#include "c_stdlib.h" #include <stdlib.h>
#include "c_string.h" #include <string.h>
#include "c_ctype.h" #include <ctype.h>
#include "coap.h" #include "coap.h"
#include "uri.h" #include "uri.h"
...@@ -43,7 +43,7 @@ int coap_split_uri(unsigned char *str_var, size_t len, coap_uri_t *uri) { ...@@ -43,7 +43,7 @@ int coap_split_uri(unsigned char *str_var, size_t len, coap_uri_t *uri) {
if (!str_var || !uri) if (!str_var || !uri)
return -1; return -1;
c_memset(uri, 0, sizeof(coap_uri_t)); memset(uri, 0, sizeof(coap_uri_t));
uri->port = COAP_DEFAULT_PORT; uri->port = COAP_DEFAULT_PORT;
/* search for scheme */ /* search for scheme */
...@@ -394,16 +394,16 @@ int coap_split_query(coap_rw_buffer_t *scratch, coap_packet_t *pkt, const unsign ...@@ -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) { coap_uri_t * coap_new_uri(const unsigned char *uri, unsigned int length) {
unsigned char *result; 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) if (!result)
return NULL; return NULL;
c_memcpy(URI_DATA(result), uri, length); memcpy(URI_DATA(result), uri, length);
URI_DATA(result)[length] = '\0'; /* make it zero-terminated */ URI_DATA(result)[length] = '\0'; /* make it zero-terminated */
if (coap_split_uri(URI_DATA(result), length, (coap_uri_t *)result) < 0) { if (coap_split_uri(URI_DATA(result), length, (coap_uri_t *)result) < 0) {
c_free(result); free(result);
return NULL; return NULL;
} }
return (coap_uri_t *)result; return (coap_uri_t *)result;
......
...@@ -34,7 +34,8 @@ ...@@ -34,7 +34,8 @@
#include "osapi.h" #include "osapi.h"
#include "mem.h" #include "mem.h"
#include <string.h> #include <string.h>
#include <c_errno.h> #include <strings.h>
#include <errno.h>
#ifdef MD2_ENABLE #ifdef MD2_ENABLE
#include "ssl/ssl_crypto.h" #include "ssl/ssl_crypto.h"
......
...@@ -33,7 +33,8 @@ ...@@ -33,7 +33,8 @@
#include "mech.h" #include "mech.h"
#include "sdk-aes.h" #include "sdk-aes.h"
#include "c_string.h" #include <string.h>
#include <strings.h>
/* ----- AES ---------------------------------------------------------- */ /* ----- AES ---------------------------------------------------------- */
...@@ -58,7 +59,7 @@ static bool do_aes (crypto_op_t *co, bool with_cbc) ...@@ -58,7 +59,7 @@ static bool do_aes (crypto_op_t *co, bool with_cbc)
char iv[AES_BLOCKSIZE] = { 0 }; char iv[AES_BLOCKSIZE] = { 0 };
if (with_cbc && co->ivlen) 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; const char *src = co->data;
char *dst = co->out; char *dst = co->out;
...@@ -68,7 +69,7 @@ static bool do_aes (crypto_op_t *co, bool with_cbc) ...@@ -68,7 +69,7 @@ static bool do_aes (crypto_op_t *co, bool with_cbc)
{ {
char block[AES_BLOCKSIZE] = { 0 }; char block[AES_BLOCKSIZE] = { 0 };
size_t n = left > AES_BLOCKSIZE ? AES_BLOCKSIZE : left; 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) if (with_cbc && co->op == OP_ENCRYPT)
{ {
......
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
#include "user_interface.h" #include "user_interface.h"
#include "platform.h" #include "platform.h"
#include "c_stdio.h" #include <stdio.h>
#include "dht.h" #include "dht.h"
#ifndef LOW #ifndef LOW
......
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
* Rework of original driver: Natalia Sorokina <sonaux@gmail.com>, 2018 * Rework of original driver: Natalia Sorokina <sonaux@gmail.com>, 2018
*/ */
#include "../libc/c_stdlib.h" #include <stdlib.h>
#include "ets_sys.h" #include "ets_sys.h"
#include "osapi.h" #include "osapi.h"
#include "gpio.h" #include "gpio.h"
......
...@@ -12,8 +12,8 @@ ...@@ -12,8 +12,8 @@
#include "platform.h" #include "platform.h"
#include "c_types.h" #include "c_types.h"
#include "../libc/c_stdlib.h" #include <stdlib.h>
#include "../libc/c_stdio.h" #include <stdio.h>
#include "driver/rotary.h" #include "driver/rotary.h"
#include "user_interface.h" #include "user_interface.h"
#include "task/task.h" #include "task/task.h"
...@@ -87,7 +87,7 @@ int rotary_close(uint32_t channel) ...@@ -87,7 +87,7 @@ int rotary_close(uint32_t channel)
rotary_clear_pin(d->phase_b_pin); rotary_clear_pin(d->phase_b_pin);
rotary_clear_pin(d->press_pin); rotary_clear_pin(d->press_pin);
c_free(d); free(d);
set_gpio_bits(); set_gpio_bits();
...@@ -207,7 +207,7 @@ int rotary_setup(uint32_t channel, int phase_a, int phase_b, int press, task_han ...@@ -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) { if (!d) {
return -1; return -1;
} }
......
...@@ -15,8 +15,8 @@ ...@@ -15,8 +15,8 @@
#include "platform.h" #include "platform.h"
#include "c_types.h" #include "c_types.h"
#include "../libc/c_stdlib.h" #include <stdlib.h>
#include "../libc/c_stdio.h" #include <stdio.h>
#include "driver/switec.h" #include "driver/switec.h"
#include "ets_sys.h" #include "ets_sys.h"
#include "os_type.h" #include "os_type.h"
...@@ -101,7 +101,7 @@ int switec_close(uint32_t channel) ...@@ -101,7 +101,7 @@ int switec_close(uint32_t channel)
gpio_output_set(0, 0, 0, d->mask); gpio_output_set(0, 0, 0, d->mask);
data[channel] = NULL; data[channel] = NULL;
c_free(d); free(d);
// See if there are any other channels active // See if there are any other channels active
for (channel = 0; channel < sizeof(data)/sizeof(data[0]); channel++) { 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 ...@@ -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) { if (!d) {
return -1; return -1;
} }
...@@ -269,7 +269,7 @@ int switec_setup(uint32_t channel, int *pin, int max_deg_per_sec, task_handle_t ...@@ -269,7 +269,7 @@ int switec_setup(uint32_t channel, int *pin, int max_deg_per_sec, task_handle_t
// no autoreload // no autoreload
if (!platform_hw_timer_init(TIMER_OWNER, FRC1_SOURCE, FALSE)) { if (!platform_hw_timer_init(TIMER_OWNER, FRC1_SOURCE, FALSE)) {
// Failed to get the timer // Failed to get the timer
c_free(d); free(d);
return -1; return -1;
} }
} }
...@@ -299,12 +299,12 @@ int switec_setup(uint32_t channel, int *pin, int max_deg_per_sec, task_handle_t ...@@ -299,12 +299,12 @@ int switec_setup(uint32_t channel, int *pin, int max_deg_per_sec, task_handle_t
#ifdef SWITEC_DEBUG #ifdef SWITEC_DEBUG
for (i = 0; i < 4; i++) { 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++) { 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 #endif
......
#include <c_stdlib.h> #include <stdlib.h>
#include <c_string.h> #include <string.h>
#include <stdbool.h>
#include "vfs_int.h" #include "vfs_int.h"
...@@ -12,37 +13,37 @@ static FRESULT last_result = FR_OK; ...@@ -12,37 +13,37 @@ static FRESULT last_result = FR_OK;
static const char* const volstr[FF_VOLUMES] = {FF_VOLUME_STRS}; static const char* const volstr[FF_VOLUMES] = {FF_VOLUME_STRS};
static int is_current_drive = FALSE; static int is_current_drive = false;
// forward declarations // forward declarations
static sint32_t myfatfs_close( const struct vfs_file *fd ); static int32_t myfatfs_close( const struct vfs_file *fd );
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 );
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 );
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 );
static sint32_t myfatfs_eof( const struct vfs_file *fd ); static int32_t myfatfs_eof( const struct vfs_file *fd );
static sint32_t myfatfs_tell( const struct vfs_file *fd ); static int32_t myfatfs_tell( const struct vfs_file *fd );
static sint32_t myfatfs_flush( 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 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 int32_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_readdir( const struct vfs_dir *dd, struct vfs_stat *buf );
static vfs_vol *myfatfs_mount( const char *name, int num ); static vfs_vol *myfatfs_mount( const char *name, int num );
static vfs_file *myfatfs_open( const char *name, const char *mode ); static vfs_file *myfatfs_open( const char *name, const char *mode );
static vfs_dir *myfatfs_opendir( const char *name ); static vfs_dir *myfatfs_opendir( const char *name );
static sint32_t myfatfs_stat( const char *name, struct vfs_stat *buf ); static int32_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 );
static sint32_t myfatfs_rename( const char *oldname, const char *newname ); static int32_t myfatfs_rename( const char *oldname, const char *newname );
static sint32_t myfatfs_mkdir( const char *name ); static int32_t myfatfs_mkdir( const char *name );
static sint32_t myfatfs_fsinfo( uint32_t *total, uint32_t *used ); static int32_t myfatfs_fsinfo( uint32_t *total, uint32_t *used );
static sint32_t myfatfs_chdrive( const char *name ); static int32_t myfatfs_chdrive( const char *name );
static sint32_t myfatfs_chdir( const char *name ); static int32_t myfatfs_chdir( const char *name );
static sint32_t myfatfs_errno( void ); static int32_t myfatfs_errno( void );
static void myfatfs_clearerr( 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 { ...@@ -112,12 +113,12 @@ struct myvfs_dir {
// //
void *ff_memalloc( UINT size ) void *ff_memalloc( UINT size )
{ {
return c_malloc( size ); return malloc( size );
} }
void ff_memfree( void *mblock ) void ff_memfree( void *mblock )
{ {
c_free( mblock ); free( mblock );
} }
// TODO // TODO
...@@ -153,14 +154,14 @@ DWORD get_fattime( void ) ...@@ -153,14 +154,14 @@ DWORD get_fattime( void )
const struct myvfs_vol *myvol = (const struct myvfs_vol *)descr; \ const struct myvfs_vol *myvol = (const struct myvfs_vol *)descr; \
FATFS *fs = (FATFS *)&(myvol->fs); 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); GET_FATFS_FS(vol);
last_result = f_mount( NULL, myvol->ldrname, 0 ); last_result = f_mount( NULL, myvol->ldrname, 0 );
c_free( myvol->ldrname ); free( myvol->ldrname );
c_free( (void *)vol ); free( (void *)vol );
return last_result == FR_OK ? VFS_RES_OK : VFS_RES_ERR; 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 ) ...@@ -173,19 +174,19 @@ static sint32_t myfatfs_umount( const struct vfs_vol *vol )
const struct myvfs_file *myfd = (const struct myvfs_file *)descr; \ const struct myvfs_file *myfd = (const struct myvfs_file *)descr; \
FIL *fp = (FIL *)&(myfd->fp); 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) GET_FIL_FP(fd)
last_result = f_close( fp ); last_result = f_close( fp );
// free descriptor memory // free descriptor memory
c_free( (void *)fd ); free( (void *)fd );
return last_result == FR_OK ? VFS_RES_OK : VFS_RES_ERR; 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); GET_FIL_FP(fd);
UINT act_read; UINT act_read;
...@@ -195,7 +196,7 @@ static sint32_t myfatfs_read( const struct vfs_file *fd, void *ptr, size_t len ) ...@@ -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; 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); GET_FIL_FP(fd);
UINT act_written; UINT act_written;
...@@ -205,7 +206,7 @@ static sint32_t myfatfs_write( const struct vfs_file *fd, const void *ptr, size_ ...@@ -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; 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); GET_FIL_FP(fd);
FSIZE_t new_pos; FSIZE_t new_pos;
...@@ -231,7 +232,7 @@ static sint32_t myfatfs_lseek( const struct vfs_file *fd, sint32_t off, int when ...@@ -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; 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); GET_FIL_FP(fd);
...@@ -240,7 +241,7 @@ static sint32_t myfatfs_eof( const struct vfs_file *fd ) ...@@ -240,7 +241,7 @@ static sint32_t myfatfs_eof( const struct vfs_file *fd )
return f_eof( fp ); 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); GET_FIL_FP(fd);
...@@ -249,7 +250,7 @@ static sint32_t myfatfs_tell( const struct vfs_file *fd ) ...@@ -249,7 +250,7 @@ static sint32_t myfatfs_tell( const struct vfs_file *fd )
return f_tell( fp ); 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); GET_FIL_FP(fd);
...@@ -267,7 +268,7 @@ static uint32_t myfatfs_fsize( const struct vfs_file *fd ) ...@@ -267,7 +268,7 @@ static uint32_t myfatfs_fsize( const struct vfs_file *fd )
return f_size( fp ); 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; return -last_result;
} }
...@@ -280,24 +281,24 @@ static sint32_t myfatfs_ferrno( const struct vfs_file *fd ) ...@@ -280,24 +281,24 @@ static sint32_t myfatfs_ferrno( const struct vfs_file *fd )
const struct myvfs_dir *mydd = (const struct myvfs_dir *)descr; \ const struct myvfs_dir *mydd = (const struct myvfs_dir *)descr; \
DIR *dp = (DIR *)&(mydd->dp); 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); GET_DIR_DP(dd);
last_result = f_closedir( dp ); last_result = f_closedir( dp );
// free descriptor memory // free descriptor memory
c_free( (void *)dd ); free( (void *)dd );
return last_result == FR_OK ? VFS_RES_OK : VFS_RES_ERR; return last_result == FR_OK ? VFS_RES_OK : VFS_RES_ERR;
} }
static void myfatfs_fill_stat( const FILINFO *fno, struct vfs_stat *buf ) 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 // 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->name[FS_OBJ_NAME_LEN] = '\0';
buf->size = fno->fsize; buf->size = fno->fsize;
buf->is_dir = fno->fattrib & AM_DIR ? 1 : 0; 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 ) ...@@ -316,7 +317,7 @@ static void myfatfs_fill_stat( const FILINFO *fno, struct vfs_stat *buf )
buf->tm_valid = 1; 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); GET_DIR_DP(dd);
FILINFO fno; FILINFO fno;
...@@ -340,19 +341,19 @@ static sint32_t myfatfs_readdir( const struct vfs_dir *dd, struct vfs_stat *buf ...@@ -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 ) static vfs_vol *myfatfs_mount( const char *name, int num )
{ {
struct myvfs_vol *vol; 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 // num argument specifies the physical driver = SS/CS pin number for this sd card
if (num >= 0) { if (num >= 0) {
for (int i = 0; i < NUM_LOGICAL_DRIVES; i++) { 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; VolToPart[i].pd = num;
} }
} }
} }
if (vol = c_malloc( sizeof( struct myvfs_vol ) )) { if (vol = malloc( sizeof( struct myvfs_vol ) )) {
if (vol->ldrname = c_strdup( name )) { if (vol->ldrname = strdup( name )) {
if (FR_OK == (last_result = f_mount( &(vol->fs), name, 1 ))) { if (FR_OK == (last_result = f_mount( &(vol->fs), name, 1 ))) {
vol->vfs_vol.fs_type = VFS_FS_FATFS; vol->vfs_vol.fs_type = VFS_FS_FATFS;
vol->vfs_vol.fns = &myfatfs_vol_fns; vol->vfs_vol.fns = &myfatfs_vol_fns;
...@@ -362,29 +363,29 @@ static vfs_vol *myfatfs_mount( const char *name, int num ) ...@@ -362,29 +363,29 @@ static vfs_vol *myfatfs_mount( const char *name, int num )
} }
if (vol) { if (vol) {
if (vol->ldrname) c_free( vol->ldrname ); if (vol->ldrname) free( vol->ldrname );
c_free( vol ); free( vol );
} }
return NULL; return NULL;
} }
static BYTE myfatfs_mode2flag( const char *mode ) static BYTE myfatfs_mode2flag( const char *mode )
{ {
if (c_strlen( mode ) == 1) { if (strlen( mode ) == 1) {
if(c_strcmp( mode, "w" ) == 0) if(strcmp( mode, "w" ) == 0)
return FA_WRITE | FA_CREATE_ALWAYS; 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; 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; return FA_WRITE | FA_OPEN_ALWAYS;
else else
return FA_READ | FA_OPEN_EXISTING; return FA_READ | FA_OPEN_EXISTING;
} else if (c_strlen( mode ) == 2) { } else if (strlen( mode ) == 2) {
if (c_strcmp( mode, "r+" ) == 0) if (strcmp( mode, "r+" ) == 0)
return FA_READ | FA_WRITE | FA_OPEN_EXISTING; 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; 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; return FA_READ | FA_WRITE | FA_OPEN_ALWAYS;
else else
return FA_READ | FA_OPEN_EXISTING; return FA_READ | FA_OPEN_EXISTING;
...@@ -398,7 +399,7 @@ static vfs_file *myfatfs_open( const char *name, const char *mode ) ...@@ -398,7 +399,7 @@ static vfs_file *myfatfs_open( const char *name, const char *mode )
struct myvfs_file *fd; struct myvfs_file *fd;
const BYTE flags = myfatfs_mode2flag( mode ); 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 ))) { if (FR_OK == (last_result = f_open( &(fd->fp), name, flags ))) {
// skip to end of file for append mode // skip to end of file for append mode
if (flags & FA_OPEN_ALWAYS) if (flags & FA_OPEN_ALWAYS)
...@@ -408,7 +409,7 @@ static vfs_file *myfatfs_open( const char *name, const char *mode ) ...@@ -408,7 +409,7 @@ static vfs_file *myfatfs_open( const char *name, const char *mode )
fd->vfs_file.fns = &myfatfs_file_fns; fd->vfs_file.fns = &myfatfs_file_fns;
return (vfs_file *)fd; return (vfs_file *)fd;
} else { } else {
c_free( fd ); free( fd );
} }
} }
...@@ -419,20 +420,20 @@ static vfs_dir *myfatfs_opendir( const char *name ) ...@@ -419,20 +420,20 @@ static vfs_dir *myfatfs_opendir( const char *name )
{ {
struct myvfs_dir *dd; 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 ))) { if (FR_OK == (last_result = f_opendir( &(dd->dp), name ))) {
dd->vfs_dir.fs_type = VFS_FS_FATFS; dd->vfs_dir.fs_type = VFS_FS_FATFS;
dd->vfs_dir.fns = &myfatfs_dir_fns; dd->vfs_dir.fns = &myfatfs_dir_fns;
return (vfs_dir *)dd; return (vfs_dir *)dd;
} else { } else {
c_free( dd ); free( dd );
} }
} }
return NULL; 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; FILINFO fno;
...@@ -445,28 +446,28 @@ static sint32_t myfatfs_stat( const char *name, struct vfs_stat *buf ) ...@@ -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 ); last_result = f_unlink( name );
return last_result == FR_OK ? VFS_RES_OK : VFS_RES_ERR; 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 ); last_result = f_rename( oldname, newname );
return last_result == FR_OK ? VFS_RES_OK : VFS_RES_ERR; 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 ); last_result = f_mkdir( name );
return last_result == FR_OK ? VFS_RES_OK : VFS_RES_ERR; 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; DWORD free_clusters;
FATFS *fatfs; FATFS *fatfs;
...@@ -480,21 +481,21 @@ static sint32_t myfatfs_fsinfo( uint32_t *total, uint32_t *used ) ...@@ -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; 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 ); last_result = f_chdrive( name );
return last_result == FR_OK ? VFS_RES_OK : VFS_RES_ERR; 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 ); last_result = f_chdir( name );
return last_result == FR_OK ? VFS_RES_OK : VFS_RES_ERR; 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; return -last_result;
} }
...@@ -515,10 +516,10 @@ vfs_fs_fns *myfatfs_realm( const char *inname, char **outname, int set_current_d ...@@ -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 // logical drive is specified, check if it's one of ours
for (int i = 0; i < FF_VOLUMES; i++) { for (int i = 0; i < FF_VOLUMES; i++) {
size_t volstr_len = c_strlen( volstr[i] ); size_t volstr_len = strlen( volstr[i] );
if (0 == c_strncmp( &(inname[1]), volstr[i], volstr_len )) { if (0 == strncmp( &(inname[1]), volstr[i], volstr_len )) {
oname = c_strdup( inname ); oname = strdup( inname );
c_strcpy( oname, volstr[i] ); strcpy( oname, volstr[i] );
oname[volstr_len] = ':'; oname[volstr_len] = ':';
*outname = oname; *outname = oname;
...@@ -529,11 +530,11 @@ vfs_fs_fns *myfatfs_realm( const char *inname, char **outname, int set_current_d ...@@ -529,11 +530,11 @@ vfs_fs_fns *myfatfs_realm( const char *inname, char **outname, int set_current_d
} else { } else {
// no logical drive in patchspec, are we current drive? // no logical drive in patchspec, are we current drive?
if (is_current_drive) { if (is_current_drive) {
*outname = c_strdup( inname ); *outname = strdup( inname );
return &myfatfs_fs_fns; return &myfatfs_fs_fns;
} }
} }
if (set_current_drive) is_current_drive = FALSE; if (set_current_drive) is_current_drive = false;
return NULL; return NULL;
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment