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
#include <stdlib.h>
#include <stdio.h>
#include "c_stdlib.h" #include <stdbool.h>
#include "c_stdio.h"
#include "vfs.h" #include "vfs.h"
#include "vfs_int.h"
#define LDRV_TRAVERSAL 0 #define LDRV_TRAVERSAL 0
// This interferes with our clearerr member in our ops struct
#undef clearerr
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// RTC system interface // 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 // 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 // allow NULL pointer to unregister callback function
rtc_cb = cb; rtc_cb = cb;
} }
// called by file system drivers // called by file system drivers
sint32_t vfs_get_rtc( vfs_time *tm ) int32_t vfs_get_rtc( vfs_time *tm )
{ {
if (rtc_cb) { if (rtc_cb) {
return rtc_cb( tm ); return rtc_cb( tm );
...@@ -44,7 +45,7 @@ static const char *normalize_path( const char *path ) ...@@ -44,7 +45,7 @@ static const char *normalize_path( const char *path )
const char *temp = path; const char *temp = path;
size_t len; size_t len;
while ((len = c_strlen( temp )) >= 2) { while ((len = strlen( temp )) >= 2) {
if (temp[0] == '.' && temp[1] == '.') { if (temp[0] == '.' && temp[1] == '.') {
--dir_level; --dir_level;
if (len >= 4 && dir_level > 0) { if (len >= 4 && dir_level > 0) {
...@@ -88,7 +89,7 @@ vfs_vol *vfs_mount( const char *name, int num ) ...@@ -88,7 +89,7 @@ vfs_vol *vfs_mount( const char *name, int num )
#ifdef BUILD_FATFS #ifdef BUILD_FATFS
if (fs_fns = myfatfs_realm( normname, &outname, FALSE )) { if (fs_fns = myfatfs_realm( normname, &outname, FALSE )) {
vfs_vol *r = fs_fns->mount( outname, num ); vfs_vol *r = fs_fns->mount( outname, num );
c_free( outname ); free( outname );
return r; return r;
} }
#endif #endif
...@@ -111,7 +112,7 @@ int vfs_open( const char *name, const char *mode ) ...@@ -111,7 +112,7 @@ int vfs_open( const char *name, const char *mode )
#ifdef BUILD_FATFS #ifdef BUILD_FATFS
if (fs_fns = myfatfs_realm( normname, &outname, FALSE )) { if (fs_fns = myfatfs_realm( normname, &outname, FALSE )) {
int r = (int)fs_fns->open( outname, mode ); int r = (int)fs_fns->open( outname, mode );
c_free( outname ); free( outname );
return r; return r;
} }
#endif #endif
...@@ -134,7 +135,7 @@ vfs_dir *vfs_opendir( const char *name ) ...@@ -134,7 +135,7 @@ vfs_dir *vfs_opendir( const char *name )
#ifdef BUILD_FATFS #ifdef BUILD_FATFS
if (fs_fns = myfatfs_realm( normname, &outname, FALSE )) { if (fs_fns = myfatfs_realm( normname, &outname, FALSE )) {
vfs_dir *r = fs_fns->opendir( outname ); vfs_dir *r = fs_fns->opendir( outname );
c_free( outname ); free( outname );
return r; return r;
} }
#endif #endif
...@@ -142,7 +143,7 @@ vfs_dir *vfs_opendir( const char *name ) ...@@ -142,7 +143,7 @@ vfs_dir *vfs_opendir( const char *name )
return NULL; 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; vfs_fs_fns *fs_fns;
const char *normname = normalize_path( name ); const char *normname = normalize_path( name );
...@@ -156,8 +157,8 @@ sint32_t vfs_stat( const char *name, struct vfs_stat *buf ) ...@@ -156,8 +157,8 @@ sint32_t vfs_stat( const char *name, struct vfs_stat *buf )
#ifdef BUILD_FATFS #ifdef BUILD_FATFS
if (fs_fns = myfatfs_realm( normname, &outname, FALSE )) { if (fs_fns = myfatfs_realm( normname, &outname, FALSE )) {
sint32_t r = fs_fns->stat( outname, buf ); int32_t r = fs_fns->stat( outname, buf );
c_free( outname ); free( outname );
return r; return r;
} }
#endif #endif
...@@ -165,7 +166,7 @@ sint32_t vfs_stat( const char *name, struct vfs_stat *buf ) ...@@ -165,7 +166,7 @@ sint32_t vfs_stat( const char *name, struct vfs_stat *buf )
return VFS_RES_ERR; return VFS_RES_ERR;
} }
sint32_t vfs_remove( const char *name ) int32_t vfs_remove( const char *name )
{ {
vfs_fs_fns *fs_fns; vfs_fs_fns *fs_fns;
const char *normname = normalize_path( name ); const char *normname = normalize_path( name );
...@@ -179,8 +180,8 @@ sint32_t vfs_remove( const char *name ) ...@@ -179,8 +180,8 @@ sint32_t vfs_remove( const char *name )
#ifdef BUILD_FATFS #ifdef BUILD_FATFS
if (fs_fns = myfatfs_realm( normname, &outname, FALSE )) { if (fs_fns = myfatfs_realm( normname, &outname, FALSE )) {
sint32_t r = fs_fns->remove( outname ); int32_t r = fs_fns->remove( outname );
c_free( outname ); free( outname );
return r; return r;
} }
#endif #endif
...@@ -188,7 +189,7 @@ sint32_t vfs_remove( const char *name ) ...@@ -188,7 +189,7 @@ sint32_t vfs_remove( const char *name )
return VFS_RES_ERR; 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; vfs_fs_fns *fs_fns;
const char *normoldname = normalize_path( oldname ); const char *normoldname = normalize_path( oldname );
...@@ -206,19 +207,19 @@ sint32_t vfs_rename( const char *oldname, const char *newname ) ...@@ -206,19 +207,19 @@ sint32_t vfs_rename( const char *oldname, const char *newname )
#ifdef BUILD_FATFS #ifdef BUILD_FATFS
if (myfatfs_realm( normoldname, &oldoutname, FALSE )) { if (myfatfs_realm( normoldname, &oldoutname, FALSE )) {
if (fs_fns = myfatfs_realm( normnewname, &newoutname, FALSE )) { if (fs_fns = myfatfs_realm( normnewname, &newoutname, FALSE )) {
sint32_t r = fs_fns->rename( oldoutname, newoutname ); int32_t r = fs_fns->rename( oldoutname, newoutname );
c_free( oldoutname ); free( oldoutname );
c_free( newoutname ); free( newoutname );
return r; return r;
} }
c_free( oldoutname ); free( oldoutname );
} }
#endif #endif
return -1; return -1;
} }
sint32_t vfs_mkdir( const char *name ) int32_t vfs_mkdir( const char *name )
{ {
vfs_fs_fns *fs_fns; vfs_fs_fns *fs_fns;
const char *normname = normalize_path( name ); const char *normname = normalize_path( name );
...@@ -230,8 +231,8 @@ sint32_t vfs_mkdir( const char *name ) ...@@ -230,8 +231,8 @@ sint32_t vfs_mkdir( const char *name )
#ifdef BUILD_FATFS #ifdef BUILD_FATFS
if (fs_fns = myfatfs_realm( normname, &outname, FALSE )) { if (fs_fns = myfatfs_realm( normname, &outname, FALSE )) {
sint32_t r = fs_fns->mkdir( outname ); int32_t r = fs_fns->mkdir( outname );
c_free( outname ); free( outname );
return r; return r;
} }
#endif #endif
...@@ -239,7 +240,7 @@ sint32_t vfs_mkdir( const char *name ) ...@@ -239,7 +240,7 @@ sint32_t vfs_mkdir( const char *name )
return VFS_RES_ERR; 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; vfs_fs_fns *fs_fns;
char *outname; char *outname;
...@@ -256,7 +257,7 @@ sint32_t vfs_fsinfo( const char *name, uint32_t *total, uint32_t *used ) ...@@ -256,7 +257,7 @@ sint32_t vfs_fsinfo( const char *name, uint32_t *total, uint32_t *used )
#ifdef BUILD_FATFS #ifdef BUILD_FATFS
if (fs_fns = myfatfs_realm( normname, &outname, FALSE )) { if (fs_fns = myfatfs_realm( normname, &outname, FALSE )) {
c_free( outname ); free( outname );
return fs_fns->fsinfo( total, used ); return fs_fns->fsinfo( total, used );
} }
#endif #endif
...@@ -264,7 +265,7 @@ sint32_t vfs_fsinfo( const char *name, uint32_t *total, uint32_t *used ) ...@@ -264,7 +265,7 @@ sint32_t vfs_fsinfo( const char *name, uint32_t *total, uint32_t *used )
return VFS_RES_ERR; 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; vfs_fs_fns *fs_fns;
char *outname; char *outname;
...@@ -283,7 +284,7 @@ sint32_t vfs_fscfg( const char *name, uint32_t *phys_addr, uint32_t *phys_size) ...@@ -283,7 +284,7 @@ sint32_t vfs_fscfg( const char *name, uint32_t *phys_addr, uint32_t *phys_size)
return VFS_RES_ERR; return VFS_RES_ERR;
} }
sint32_t vfs_format( void ) int32_t vfs_format( void )
{ {
vfs_fs_fns *fs_fns; vfs_fs_fns *fs_fns;
char *outname; char *outname;
...@@ -302,7 +303,7 @@ sint32_t vfs_format( void ) ...@@ -302,7 +303,7 @@ sint32_t vfs_format( void )
return 0; return 0;
} }
sint32_t vfs_chdir( const char *path ) int32_t vfs_chdir( const char *path )
{ {
vfs_fs_fns *fs_fns; vfs_fs_fns *fs_fns;
const char *normpath = normalize_path( path ); const char *normpath = normalize_path( path );
...@@ -318,9 +319,9 @@ sint32_t vfs_chdir( const char *path ) ...@@ -318,9 +319,9 @@ sint32_t vfs_chdir( const char *path )
} else { } else {
level = normpath; level = normpath;
} }
while (c_strlen( level ) > 0) { while (strlen( level ) > 0) {
dir_level++; dir_level++;
if (level = c_strchr( level, '/' )) { if (level = strchr( level, '/' )) {
level++; level++;
} else { } else {
break; break;
...@@ -331,7 +332,7 @@ sint32_t vfs_chdir( const char *path ) ...@@ -331,7 +332,7 @@ sint32_t vfs_chdir( const char *path )
#ifdef BUILD_SPIFFS #ifdef BUILD_SPIFFS
if (fs_fns = myspiffs_realm( normpath, &outname, TRUE )) { if (fs_fns = myspiffs_realm( normpath, &outname, TRUE )) {
// our SPIFFS integration doesn't support directories // our SPIFFS integration doesn't support directories
if (c_strlen( outname ) == 0) { if (strlen( outname ) == 0) {
ok = VFS_RES_OK; ok = VFS_RES_OK;
} }
} }
...@@ -339,7 +340,7 @@ sint32_t vfs_chdir( const char *path ) ...@@ -339,7 +340,7 @@ sint32_t vfs_chdir( const char *path )
#ifdef BUILD_FATFS #ifdef BUILD_FATFS
if (fs_fns = myfatfs_realm( normpath, &outname, TRUE )) { if (fs_fns = myfatfs_realm( normpath, &outname, TRUE )) {
if (c_strchr( outname, ':' )) { if (strchr( outname, ':' )) {
// need to set FatFS' default drive // need to set FatFS' default drive
fs_fns->chdrive( outname ); fs_fns->chdrive( outname );
// and force chdir to root in case path points only to root // and force chdir to root in case path points only to root
...@@ -348,14 +349,14 @@ sint32_t vfs_chdir( const char *path ) ...@@ -348,14 +349,14 @@ sint32_t vfs_chdir( const char *path )
if (fs_fns->chdir( outname ) == VFS_RES_OK) { if (fs_fns->chdir( outname ) == VFS_RES_OK) {
ok = VFS_RES_OK; ok = VFS_RES_OK;
} }
c_free( outname ); free( outname );
} }
#endif #endif
return ok == VFS_RES_OK ? VFS_RES_OK : VFS_RES_ERR; 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; vfs_fs_fns *fs_fns;
char *outname; char *outname;
...@@ -372,8 +373,8 @@ sint32_t vfs_errno( const char *name ) ...@@ -372,8 +373,8 @@ sint32_t vfs_errno( const char *name )
#ifdef BUILD_FATFS #ifdef BUILD_FATFS
if (fs_fns = myfatfs_realm( normname, &outname, FALSE )) { if (fs_fns = myfatfs_realm( normname, &outname, FALSE )) {
sint32_t r = fs_fns->ferrno( ); int32_t r = fs_fns->ferrno( );
c_free( outname ); free( outname );
return r; return r;
} }
#endif #endif
...@@ -381,7 +382,7 @@ sint32_t vfs_errno( const char *name ) ...@@ -381,7 +382,7 @@ sint32_t vfs_errno( const char *name )
return VFS_RES_ERR; return VFS_RES_ERR;
} }
sint32_t vfs_ferrno( int fd ) int32_t vfs_ferrno( int fd )
{ {
vfs_file *f = (vfs_file *)fd; vfs_file *f = (vfs_file *)fd;
...@@ -400,8 +401,8 @@ sint32_t vfs_ferrno( int fd ) ...@@ -400,8 +401,8 @@ sint32_t vfs_ferrno( int fd )
#ifdef BUILD_FATFS #ifdef BUILD_FATFS
if (fs_fns = myfatfs_realm( name, &outname, FALSE )) { if (fs_fns = myfatfs_realm( name, &outname, FALSE )) {
sint32_t r = fs_fns->ferrno( ); int32_t r = fs_fns->ferrno( );
c_free( outname ); free( outname );
return r; return r;
} }
#endif #endif
...@@ -420,14 +421,14 @@ void vfs_clearerr( const char *name ) ...@@ -420,14 +421,14 @@ void vfs_clearerr( const char *name )
#ifdef BUILD_SPIFFS #ifdef BUILD_SPIFFS
if (fs_fns = myspiffs_realm( normname, &outname, FALSE )) { if (fs_fns = myspiffs_realm( normname, &outname, FALSE )) {
fs_fns->clearerr( ); fs_fns->clearerr ( );
} }
#endif #endif
#ifdef BUILD_FATFS #ifdef BUILD_FATFS
if (fs_fns = myfatfs_realm( normname, &outname, FALSE )) { if (fs_fns = myfatfs_realm( normname, &outname, FALSE )) {
fs_fns->clearerr( ); fs_fns->clearerr ( );
c_free( outname ); free( outname );
} }
#endif #endif
} }
...@@ -437,9 +438,9 @@ const char *vfs_basename( const char *path ) ...@@ -437,9 +438,9 @@ const char *vfs_basename( const char *path )
const char *basename; const char *basename;
// deduce basename (incl. extension) for length check // deduce basename (incl. extension) for length check
if (basename = c_strrchr( path, '/' )) { if (basename = strrchr( path, '/' )) {
basename++; basename++;
} else if (basename = c_strrchr( path, ':' )) { } else if (basename = strrchr( path, ':' )) {
basename++; basename++;
} else { } else {
basename = path; basename = path;
...@@ -455,7 +456,7 @@ const char *vfs_basename( const char *path ) ...@@ -455,7 +456,7 @@ const char *vfs_basename( const char *path )
int vfs_getc( int fd ) int vfs_getc( int fd )
{ {
unsigned char c = 0xFF; unsigned char c = 0xFF;
sint32_t res; int32_t res;
if(!vfs_eof( fd )) { if(!vfs_eof( fd )) {
if (1 != vfs_read( fd, &c, 1 )) { if (1 != vfs_read( fd, &c, 1 )) {
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
// vfs_close - close file descriptor and free memory // vfs_close - close file descriptor and free memory
// fd: file descriptor // fd: file descriptor
// Returns: VFS_RES_OK or negative value in case of error // 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; vfs_file *f = (vfs_file *)fd;
return f ? f->fns->close( f ) : VFS_RES_ERR; return f ? f->fns->close( f ) : VFS_RES_ERR;
} }
...@@ -25,7 +25,7 @@ static sint32_t vfs_close( int fd ) { ...@@ -25,7 +25,7 @@ static sint32_t vfs_close( int fd ) {
// ptr: destination data buffer // ptr: destination data buffer
// len: requested length // len: requested length
// Returns: Number of bytes read, or VFS_RES_ERR in case of error // 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; vfs_file *f = (vfs_file *)fd;
return f ? f->fns->read( f, ptr, len ) : VFS_RES_ERR; 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 ) { ...@@ -35,7 +35,7 @@ static sint32_t vfs_read( int fd, void *ptr, size_t len ) {
// ptr: source data buffer // ptr: source data buffer
// len: requested length // len: requested length
// Returns: Number of bytes written, or VFS_RES_ERR in case of error // 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; vfs_file *f = (vfs_file *)fd;
return f ? f->fns->write( f, ptr, len ) : VFS_RES_ERR; return f ? f->fns->write( f, ptr, len ) : VFS_RES_ERR;
} }
...@@ -51,7 +51,7 @@ int vfs_ungetc( int c, int fd ); ...@@ -51,7 +51,7 @@ int vfs_ungetc( int c, int fd );
// VFS_SEEK_CUR - set pointer to current position + off // VFS_SEEK_CUR - set pointer to current position + off
// VFS_SEEK_END - set pointer to end of file + off // VFS_SEEK_END - set pointer to end of file + off
// Returns: New position, or VFS_RES_ERR in case of error // 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; vfs_file *f = (vfs_file *)fd;
return f ? f->fns->lseek( f, off, whence ) : VFS_RES_ERR; 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 ) { ...@@ -59,7 +59,7 @@ static sint32_t vfs_lseek( int fd, sint32_t off, int whence ) {
// vfs_eof - test for end-of-file // vfs_eof - test for end-of-file
// fd: file descriptor // fd: file descriptor
// Returns: 0 if not at end, != 0 if end of file // 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; vfs_file *f = (vfs_file *)fd;
return f ? f->fns->eof( f ) : VFS_RES_ERR; return f ? f->fns->eof( f ) : VFS_RES_ERR;
} }
...@@ -67,7 +67,7 @@ static sint32_t vfs_eof( int fd ) { ...@@ -67,7 +67,7 @@ static sint32_t vfs_eof( int fd ) {
// vfs_tell - get read/write position // vfs_tell - get read/write position
// fd: file descriptor // fd: file descriptor
// Returns: Current position // Returns: Current position
static sint32_t vfs_tell( int fd ) { static int32_t vfs_tell( int fd ) {
vfs_file *f = (vfs_file *)fd; vfs_file *f = (vfs_file *)fd;
return f ? f->fns->tell( f ) : VFS_RES_ERR; return f ? f->fns->tell( f ) : VFS_RES_ERR;
} }
...@@ -75,7 +75,7 @@ static sint32_t vfs_tell( int fd ) { ...@@ -75,7 +75,7 @@ static sint32_t vfs_tell( int fd ) {
// vfs_flush - flush write cache to file // vfs_flush - flush write cache to file
// fd: file descriptor // fd: file descriptor
// Returns: VFS_RES_OK, or VFS_RES_ERR in case of error // 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; vfs_file *f = (vfs_file *)fd;
return f ? f->fns->flush( f ) : VFS_RES_ERR; return f ? f->fns->flush( f ) : VFS_RES_ERR;
} }
...@@ -91,7 +91,7 @@ static uint32_t vfs_size( int fd ) { ...@@ -91,7 +91,7 @@ static uint32_t vfs_size( int fd ) {
// vfs_ferrno - get file system specific errno // vfs_ferrno - get file system specific errno
// fd: file descriptor // fd: file descriptor
// Returns: errno // Returns: errno
sint32_t vfs_ferrno( int fd ); int32_t vfs_ferrno( int fd );
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// dir functions // dir functions
...@@ -100,13 +100,13 @@ sint32_t vfs_ferrno( int fd ); ...@@ -100,13 +100,13 @@ sint32_t vfs_ferrno( int fd );
// vfs_closedir - close directory descriptor and free memory // vfs_closedir - close directory descriptor and free memory
// dd: dir descriptor // dd: dir descriptor
// Returns: VFS_RES_OK, or VFS_RES_ERR in case of error // 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 // vfs_readdir - read next directory item
// dd: dir descriptor // dd: dir descriptor
// buf: pre-allocated stat structure to be filled in // buf: pre-allocated stat structure to be filled in
// Returns: VFS_RES_OK if next item found, otherwise VFS_RES_ERR // 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 // volume functions
...@@ -115,7 +115,7 @@ static sint32_t vfs_readdir( vfs_dir *dd, struct vfs_stat *buf ) { return dd->fn ...@@ -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 // vfs_umount - unmount logical drive and free memory
// vol: volume object // vol: volume object
// Returns: VFS_RES_OK, or VFS_RES_ERR in case of error // 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 // file system functions
...@@ -142,56 +142,56 @@ vfs_dir *vfs_opendir( const char *name ); ...@@ -142,56 +142,56 @@ vfs_dir *vfs_opendir( const char *name );
// name: file or directory name // name: file or directory name
// buf: pre-allocated structure to be filled in // buf: pre-allocated structure to be filled in
// Returns: VFS_RES_OK, or VFS_RES_ERR in case of error // 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 // vfs_remove - remove file or directory
// name: file or directory name // name: file or directory name
// Returns: VFS_RES_OK, or VFS_RES_ERR in case of error // 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 // vfs_rename - rename file or directory
// name: file or directory name // name: file or directory name
// Returns: VFS_RES_OK, or VFS_RES_ERR in case of error // 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 // vfs_mkdir - create directory
// name: directory name // name: directory name
// Returns: VFS_RES_OK, or VFS_RES_ERR in case of error // 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 // vfs_fsinfo - get file system info
// name: logical drive identifier // name: logical drive identifier
// total: receives total amount // total: receives total amount
// used: received used amount // used: received used amount
// Returns: VFS_RES_OK, or VFS_RES_ERR in case of error // 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 // vfs_format - format file system
// Returns: 1, or 0 in case of error // Returns: 1, or 0 in case of error
sint32_t vfs_format( void ); int32_t vfs_format( void );
// vfs_chdir - change default directory // vfs_chdir - change default directory
// path: new default directory // path: new default directory
// Returns: VFS_RES_OK, or VFS_RES_ERR in case of error // 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 // vfs_fscfg - query configuration settings of file system
// phys_addr: pointer to store physical address information // phys_addr: pointer to store physical address information
// phys_size: pointer to store physical size information // phys_size: pointer to store physical size information
// Returns: VFS_RES_OK, or VFS_RES_ERR in case of error // 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 // vfs_errno - get file system specific errno
// name: logical drive identifier // name: logical drive identifier
// Returns: errno // Returns: errno
sint32_t vfs_errno( const char *name ); int32_t vfs_errno( const char *name );
// vfs_clearerr - cleaer file system specific errno // vfs_clearerr - cleaer file system specific errno
void vfs_clearerr( const char *name ); void vfs_clearerr( const char *name );
// vfs_register_rtc_cb - register callback function for RTC query // vfs_register_rtc_cb - register callback function for RTC query
// cb: pointer to callback function // 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) // vfs_basename - identify basename (incl. extension)
// path: full file system path // path: full file system path
......
...@@ -3,16 +3,10 @@ ...@@ -3,16 +3,10 @@
#ifndef __VFS_INT_H__ #ifndef __VFS_INT_H__
#define __VFS_INT_H__ #define __VFS_INT_H__
#include <c_string.h> #include <string.h>
#include <c_stdint.h> #include <stdint.h>
#if 0
#include "spiffs.h"
#include "fatfs_prefix_lib.h"
#include "ff.h"
#endif
#include "user_config.h"
#define VFS_EOF -1 #define VFS_EOF -1
...@@ -62,15 +56,15 @@ struct vfs_stat { ...@@ -62,15 +56,15 @@ struct vfs_stat {
// file descriptor functions // file descriptor functions
struct vfs_file_fns { struct vfs_file_fns {
sint32_t (*close)( const struct vfs_file *fd ); int32_t (*close)( const struct vfs_file *fd );
sint32_t (*read)( const struct vfs_file *fd, void *ptr, size_t len ); int32_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 ); int32_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 ); int32_t (*lseek)( const struct vfs_file *fd, int32_t off, int whence );
sint32_t (*eof)( const struct vfs_file *fd ); int32_t (*eof)( const struct vfs_file *fd );
sint32_t (*tell)( const struct vfs_file *fd ); int32_t (*tell)( const struct vfs_file *fd );
sint32_t (*flush)( const struct vfs_file *fd ); int32_t (*flush)( const struct vfs_file *fd );
uint32_t (*size)( 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; typedef const struct vfs_file_fns vfs_file_fns;
...@@ -83,8 +77,8 @@ typedef const struct vfs_dir vfs_dir; ...@@ -83,8 +77,8 @@ typedef const struct vfs_dir vfs_dir;
// dir descriptor functions // dir descriptor functions
struct vfs_dir_fns { struct vfs_dir_fns {
sint32_t (*close)( const struct vfs_dir *dd ); int32_t (*close)( const struct vfs_dir *dd );
sint32_t (*readdir)( const struct vfs_dir *dd, struct vfs_stat *buf ); int32_t (*readdir)( const struct vfs_dir *dd, struct vfs_stat *buf );
}; };
typedef const struct vfs_dir_fns vfs_dir_fns; typedef const struct vfs_dir_fns vfs_dir_fns;
...@@ -97,7 +91,7 @@ typedef const struct vfs_vol vfs_vol; ...@@ -97,7 +91,7 @@ typedef const struct vfs_vol vfs_vol;
// volume functions // volume functions
struct vfs_vol_fns { 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; typedef const struct vfs_vol_fns vfs_vol_fns;
...@@ -105,17 +99,17 @@ struct vfs_fs_fns { ...@@ -105,17 +99,17 @@ struct vfs_fs_fns {
vfs_vol *(*mount)( const char *name, int num ); vfs_vol *(*mount)( const char *name, int num );
vfs_file *(*open)( const char *name, const char *mode ); vfs_file *(*open)( const char *name, const char *mode );
vfs_dir *(*opendir)( const char *name ); vfs_dir *(*opendir)( const char *name );
sint32_t (*stat)( const char *name, struct vfs_stat *buf ); int32_t (*stat)( const char *name, struct vfs_stat *buf );
sint32_t (*remove)( const char *name ); int32_t (*remove)( const char *name );
sint32_t (*rename)( const char *oldname, const char *newname ); int32_t (*rename)( const char *oldname, const char *newname );
sint32_t (*mkdir)( const char *name ); int32_t (*mkdir)( const char *name );
sint32_t (*fsinfo)( uint32_t *total, uint32_t *used ); int32_t (*fsinfo)( uint32_t *total, uint32_t *used );
sint32_t (*fscfg)( uint32_t *phys_addr, uint32_t *phys_size ); int32_t (*fscfg)( uint32_t *phys_addr, uint32_t *phys_size );
sint32_t (*format)( void ); int32_t (*format)( void );
sint32_t (*chdrive)( const char * ); int32_t (*chdrive)( const char * );
sint32_t (*chdir)( const char * ); int32_t (*chdir)( const char * );
sint32_t (*ferrno)( void ); int32_t (*ferrno)( void );
void (*clearerr)( void ); void (*clearerr)( void );
}; };
typedef const struct vfs_fs_fns vfs_fs_fns; typedef const struct vfs_fs_fns vfs_fs_fns;
...@@ -123,6 +117,6 @@ 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 *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 ); 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 #endif
...@@ -37,16 +37,17 @@ ...@@ -37,16 +37,17 @@
* Once there are no more suspended timers, the function returns * Once there are no more suspended timers, the function returns
* *
* *
*/#include "module.h" */
#include "module.h"
#include "lauxlib.h" #include "lauxlib.h"
#include "platform.h" #include "platform.h"
#include "user_interface.h" #include "user_interface.h"
#include "user_modules.h" #include "user_modules.h"
#include "c_string.h" #include <string.h>
#include "c_stdlib.h" #include <stdlib.h>
#include "ctype.h" #include <ctype.h>
#include "c_types.h" #include "c_types.h"
...@@ -138,7 +139,7 @@ void swtmr_suspend_timers(){ ...@@ -138,7 +139,7 @@ void swtmr_suspend_timers(){
size_t registered_cb_qty = lua_objlen(L, -1); size_t registered_cb_qty = lua_objlen(L, -1);
//allocate a temporary array to hold the list of callback pointers //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){ if(!cb_reg_array){
luaL_error(L, "%s: unable to suspend timers, out of memory!", __func__); luaL_error(L, "%s: unable to suspend timers, out of memory!", __func__);
return; return;
...@@ -242,7 +243,7 @@ void swtmr_suspend_timers(){ ...@@ -242,7 +243,7 @@ void swtmr_suspend_timers(){
} }
//tmr_cb_ptr_array is no longer needed. //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. //add suspended_timer_list pointer to swtimer table.
lua_pushstring(L, SUSP_LIST_STR); lua_pushstring(L, SUSP_LIST_STR);
...@@ -391,7 +392,7 @@ void swtmr_cb_register(void* timer_cb_ptr, uint8 suspend_policy){ ...@@ -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){ static void add_to_reg_queue(void* timer_cb_ptr, uint8 suspend_policy){
if(!timer_cb_ptr) if(!timer_cb_ptr)
return; 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){ if(!queue_temp){
//it's boot time currently and we're already out of memory, something is very wrong... //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__); 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) ...@@ -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; void* cb_ptr_tmp = register_queue_ptr->tmr_cb_ptr;
swtmr_cb_register(cb_ptr_tmp, register_queue_ptr->suspend_policy); swtmr_cb_register(cb_ptr_tmp, register_queue_ptr->suspend_policy);
register_queue = register_queue->next; register_queue = register_queue->next;
c_free(register_queue_ptr); free(register_queue_ptr);
} }
return; return;
} }
...@@ -457,7 +458,7 @@ int print_timer_list(lua_State* L){ ...@@ -457,7 +458,7 @@ int print_timer_list(lua_State* L){
} }
lua_pop(L, 1); lua_pop(L, 1);
size_t registered_cb_qty = lua_objlen(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){ if(!cb_reg_array){
luaL_error(L, "%s: unable to suspend timers, out of memory!", __func__); luaL_error(L, "%s: unable to suspend timers, out of memory!", __func__);
return 0; return 0;
...@@ -490,7 +491,7 @@ int print_timer_list(lua_State* L){ ...@@ -490,7 +491,7 @@ int print_timer_list(lua_State* L){
timer_list_ptr = timer_list_ptr->timer_next; timer_list_ptr = timer_list_ptr->timer_next;
} }
c_free(cb_reg_array); free(cb_reg_array);
lua_pop(L, 1); lua_pop(L, 1);
return 0; return 0;
......
...@@ -4,8 +4,4 @@ ...@@ -4,8 +4,4 @@
#include "c_types.h" #include "c_types.h"
#include "mem.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 #endif
#include "c_stdio.h" #include <stdio.h>
#include "c_stdlib.h" #include <stdlib.h>
#include "c_string.h" #include <string.h>
#include "user_interface.h" #include "user_interface.h"
#include "smart.h" #include "smart.h"
#include "pm/swtimer.h" #include "pm/swtimer.h"
...@@ -39,7 +39,7 @@ int smart_check(uint8_t *nibble, uint16_t len, uint8_t *dst, uint8_t *got){ ...@@ -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 dst_len = len/NIBBLE_PER_BYTE;
uint16_t byte_num = 0, bit_num = 0; uint16_t byte_num = 0, bit_num = 0;
int i = 0, res = 1; // assume ok. int i = 0, res = 1; // assume ok.
c_memset(dst,0,dst_len); memset(dst,0,dst_len);
if(NIBBLE_PER_BYTE==1){ if(NIBBLE_PER_BYTE==1){
for(i=0;i<len;i++){ for(i=0;i<len;i++){
...@@ -161,7 +161,7 @@ void detect(uint8 *arg, uint16 len){ ...@@ -161,7 +161,7 @@ void detect(uint8 *arg, uint16 len){
if ( len - am[i]->base_len == am[i]->flag[0]) // store new source-dest adress pair to the map until flag[0] is got if ( len - am[i]->base_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 // 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]->flag_match_num++; // =1
am[i]->cur_base_seq = seq; // assume the first seq is found am[i]->cur_base_seq = seq; // assume the first seq is found
am[i]->base_seq_valid = 1; am[i]->base_seq_valid = 1;
...@@ -169,7 +169,7 @@ void detect(uint8 *arg, uint16 len){ ...@@ -169,7 +169,7 @@ void detect(uint8 *arg, uint16 len){
} }
break; // break any way for the next packet to come 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(am[i]->base_seq_valid == 0){
if ( len - am[i]->base_len == am[i]->flag[0]) { // found the new flag[0] if ( len - am[i]->base_len == am[i]->flag[0]) { // found the new flag[0]
// here flag_match_num is already = 1 // here flag_match_num is already = 1
...@@ -236,7 +236,7 @@ void detect(uint8 *arg, uint16 len){ ...@@ -236,7 +236,7 @@ void detect(uint8 *arg, uint16 len){
// break out, or loop done. // break out, or loop done.
goto end; goto end;
} else { // cur_base_seq is ref to SSID_FLAG when patern is alread found } 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; return;
} }
if (matched->base_seq_valid == 0){ // SSID_FLAG seq invalid, need to find the next valid seq number 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){ ...@@ -455,7 +455,7 @@ void reset_map(smart_addr_map **am, size_t num){
am[i]->base_seq_valid = 0; am[i]->base_seq_valid = 0;
am[i]->ssid_len = 0; am[i]->ssid_len = 0;
am[i]->pwd_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){ if(SEP_1_INDEX==0){
am[i]->flag[0] = SEP_1; am[i]->flag[0] = SEP_1;
am[i]->flag[1] = SEP_2; am[i]->flag[1] = SEP_2;
...@@ -511,34 +511,34 @@ void smart_end(){ ...@@ -511,34 +511,34 @@ void smart_end(){
for (i = 0; i < ADDR_MAP_NUM; ++i) for (i = 0; i < ADDR_MAP_NUM; ++i)
{ {
if(am[i]){ if(am[i]){
c_free(am[i]); free(am[i]);
am[i] = NULL; am[i] = NULL;
} }
matched = NULL; matched = NULL;
} }
if(sta_conf){ if(sta_conf){
c_free(sta_conf); free(sta_conf);
sta_conf = NULL; sta_conf = NULL;
} }
if(got_password){ if(got_password){
c_free(got_password); free(got_password);
got_password = NULL; got_password = NULL;
} }
if(got_ssid){ if(got_ssid){
c_free(got_ssid); free(got_ssid);
got_ssid = NULL; got_ssid = NULL;
} }
if(password_nibble){ if(password_nibble){
c_free(password_nibble); free(password_nibble);
password_nibble = NULL; password_nibble = NULL;
} }
if(ssid_nibble){ if(ssid_nibble){
c_free(ssid_nibble); free(ssid_nibble);
ssid_nibble = NULL; ssid_nibble = NULL;
} }
// system_restart(); // restart to enable the mode // system_restart(); // restart to enable the mode
...@@ -583,14 +583,14 @@ void smart_next_channel(){ ...@@ -583,14 +583,14 @@ void smart_next_channel(){
NODE_ERR("switch to channel %d\n", cur_channel); NODE_ERR("switch to channel %d\n", cur_channel);
wifi_set_channel(cur_channel); wifi_set_channel(cur_channel);
reset_map(am, ADDR_MAP_NUM); reset_map(am, ADDR_MAP_NUM);
c_memset(sta_conf->ssid, 0, sizeof(sta_conf->ssid)); memset(sta_conf->ssid, 0, sizeof(sta_conf->ssid));
c_memset(sta_conf->password, 0, sizeof(sta_conf->password)); memset(sta_conf->password, 0, sizeof(sta_conf->password));
c_memset(got_ssid, 0, SSID_BIT_MAX); memset(got_ssid, 0, SSID_BIT_MAX);
c_memset(got_password, 0, PWD_BIT_MAX); memset(got_password, 0, PWD_BIT_MAX);
c_memset(ssid_nibble, 0, SSID_NIBBLE_MAX); memset(ssid_nibble, 0, SSID_NIBBLE_MAX);
c_memset(password_nibble, 0, PWD_NIBBLE_MAX); memset(password_nibble, 0, PWD_NIBBLE_MAX);
os_timer_disarm(&smart_timer); os_timer_disarm(&smart_timer);
os_timer_arm(&smart_timer, TIME_OUT_PER_CHANNEL, 0); // no repeat 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){ ...@@ -604,7 +604,7 @@ void smart_begin(int chnl, smart_succeed s, void *arg){
for (i = 0; i < ADDR_MAP_NUM; ++i) for (i = 0; i < ADDR_MAP_NUM; ++i)
{ {
if(!am[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]){ if(!am[i]){
NODE_DBG("smart_begin map no memory\n"); NODE_DBG("smart_begin map no memory\n");
smart_end(); smart_end();
...@@ -613,7 +613,7 @@ void smart_begin(int chnl, smart_succeed s, void *arg){ ...@@ -613,7 +613,7 @@ void smart_begin(int chnl, smart_succeed s, void *arg){
} }
} }
if(!sta_conf){ 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){ if(!sta_conf){
NODE_DBG("smart_begin sta_conf no memory\n"); NODE_DBG("smart_begin sta_conf no memory\n");
smart_end(); smart_end();
...@@ -622,7 +622,7 @@ void smart_begin(int chnl, smart_succeed s, void *arg){ ...@@ -622,7 +622,7 @@ void smart_begin(int chnl, smart_succeed s, void *arg){
} }
if(!ssid_nibble){ if(!ssid_nibble){
ssid_nibble = (uint8_t *)c_zalloc(SSID_NIBBLE_MAX); ssid_nibble = (uint8_t *)calloc(1,SSID_NIBBLE_MAX);
if(!ssid_nibble){ if(!ssid_nibble){
NODE_DBG("smart_begin sta_conf no memory\n"); NODE_DBG("smart_begin sta_conf no memory\n");
smart_end(); smart_end();
...@@ -631,7 +631,7 @@ void smart_begin(int chnl, smart_succeed s, void *arg){ ...@@ -631,7 +631,7 @@ void smart_begin(int chnl, smart_succeed s, void *arg){
} }
if(!password_nibble){ if(!password_nibble){
password_nibble = (uint8_t *)c_zalloc(PWD_NIBBLE_MAX); password_nibble = (uint8_t *)calloc(1,PWD_NIBBLE_MAX);
if(!password_nibble){ if(!password_nibble){
NODE_DBG("smart_begin sta_conf no memory\n"); NODE_DBG("smart_begin sta_conf no memory\n");
smart_end(); smart_end();
...@@ -640,7 +640,7 @@ void smart_begin(int chnl, smart_succeed s, void *arg){ ...@@ -640,7 +640,7 @@ void smart_begin(int chnl, smart_succeed s, void *arg){
} }
if(!got_ssid){ if(!got_ssid){
got_ssid = (uint8_t *)c_zalloc(SSID_BIT_MAX); got_ssid = (uint8_t *)calloc(1,SSID_BIT_MAX);
if(!got_ssid){ if(!got_ssid){
NODE_DBG("smart_begin sta_conf no memory\n"); NODE_DBG("smart_begin sta_conf no memory\n");
smart_end(); smart_end();
...@@ -649,7 +649,7 @@ void smart_begin(int chnl, smart_succeed s, void *arg){ ...@@ -649,7 +649,7 @@ void smart_begin(int chnl, smart_succeed s, void *arg){
} }
if(!got_password){ if(!got_password){
got_password = (uint8_t *)c_zalloc(PWD_BIT_MAX); got_password = (uint8_t *)calloc(1,PWD_BIT_MAX);
if(!got_password){ if(!got_password){
NODE_DBG("smart_begin sta_conf no memory\n"); NODE_DBG("smart_begin sta_conf no memory\n");
smart_end(); smart_end();
...@@ -657,14 +657,14 @@ void smart_begin(int chnl, smart_succeed s, void *arg){ ...@@ -657,14 +657,14 @@ void smart_begin(int chnl, smart_succeed s, void *arg){
} }
} }
reset_map(am, ADDR_MAP_NUM); reset_map(am, ADDR_MAP_NUM);
// c_memset(sta_conf->ssid, 0, sizeof(sta_conf->ssid)); // memset(sta_conf->ssid, 0, sizeof(sta_conf->ssid));
// c_memset(sta_conf->password, 0, sizeof(sta_conf->password)); // memset(sta_conf->password, 0, sizeof(sta_conf->password));
// c_memset(got_ssid, 0, SSID_BIT_MAX); // memset(got_ssid, 0, SSID_BIT_MAX);
// c_memset(got_password, 0, PWD_BIT_MAX); // memset(got_password, 0, PWD_BIT_MAX);
// c_memset(ssid_nibble, 0, SSID_NIBBLE_MAX); // memset(ssid_nibble, 0, SSID_NIBBLE_MAX);
// c_memset(password_nibble, 0, PWD_NIBBLE_MAX); // memset(password_nibble, 0, PWD_NIBBLE_MAX);
mode = wifi_get_opmode(); mode = wifi_get_opmode();
if( (STATION_MODE == mode) || (mode == STATIONAP_MODE) ){ if( (STATION_MODE == mode) || (mode == STATIONAP_MODE) ){
wifi_station_set_auto_connect(false); wifi_station_set_auto_connect(false);
......
...@@ -22,7 +22,6 @@ endif ...@@ -22,7 +22,6 @@ endif
# makefile at its root level - these are then overridden # makefile at its root level - these are then overridden
# for a subtree within the makefile rooted therein # for a subtree within the makefile rooted therein
# #
DEFINES += -Dprintf=c_printf
#DEFINES += -DDEVELOPMENT_TOOLS -DNODE_DEBUG -DSPIFFS_API_DBG=NODE_DBG #DEFINES += -DDEVELOPMENT_TOOLS -DNODE_DEBUG -DSPIFFS_API_DBG=NODE_DBG
############################################################# #############################################################
......
...@@ -2,11 +2,10 @@ ...@@ -2,11 +2,10 @@
#define _NODEMCU_SPIFFS_H #define _NODEMCU_SPIFFS_H
#ifndef NODEMCU_SPIFFS_NO_INCLUDE #ifndef NODEMCU_SPIFFS_NO_INCLUDE
#include "c_stdint.h" #include <stdint.h>
#include "c_stddef.h" #include <stddef.h>
#include "c_stdio.h" #include <stdio.h>
#include "user_interface.h" #include "user_interface.h"
typedef uint32_t intptr_t;
#endif #endif
// Turn off stats // Turn off stats
......
#include "c_stdio.h" #include <stdio.h>
#include "platform.h" #include "platform.h"
#include "spiffs.h" #include "spiffs.h"
...@@ -170,7 +170,7 @@ int myspiffs_format( void ) ...@@ -170,7 +170,7 @@ int myspiffs_format( void )
// vfs API // vfs API
// *************************************************************************** // ***************************************************************************
#include <c_stdlib.h> #include <stdlib.h>
#include "vfs_int.h" #include "vfs_int.h"
#define MY_LDRV_ID "FLASH" #define MY_LDRV_ID "FLASH"
...@@ -281,7 +281,7 @@ static sint32_t myspiffs_vfs_closedir( const struct vfs_dir *dd ) { ...@@ -281,7 +281,7 @@ static sint32_t myspiffs_vfs_closedir( const struct vfs_dir *dd ) {
sint32_t res = SPIFFS_closedir( d ); sint32_t res = SPIFFS_closedir( d );
// free descriptor memory // 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 ) { 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 ...@@ -289,11 +289,11 @@ static sint32_t myspiffs_vfs_readdir( const struct vfs_dir *dd, struct vfs_stat
struct spiffs_dirent dirent; struct spiffs_dirent dirent;
if (SPIFFS_readdir( d, &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 // copy entries to item
// fill in supported stat entries // 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->name[FS_OBJ_NAME_LEN] = '\0';
buf->size = dirent.size; buf->size = dirent.size;
return VFS_RES_OK; return VFS_RES_OK;
...@@ -316,7 +316,7 @@ static sint32_t myspiffs_vfs_close( const struct vfs_file *fd ) { ...@@ -316,7 +316,7 @@ static sint32_t myspiffs_vfs_close( const struct vfs_file *fd ) {
sint32_t res = SPIFFS_close( &fs, fh ); sint32_t res = SPIFFS_close( &fs, fh );
// free descriptor memory // free descriptor memory
c_free( (void *)fd ); free( (void *)fd );
return res; return res;
} }
...@@ -392,21 +392,21 @@ static sint32_t myspiffs_vfs_ferrno( const struct vfs_file *fd ) { ...@@ -392,21 +392,21 @@ static sint32_t myspiffs_vfs_ferrno( const struct vfs_file *fd ) {
static int fs_mode2flag(const char *mode){ static int fs_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 SPIFFS_WRONLY|SPIFFS_CREAT|SPIFFS_TRUNC; return SPIFFS_WRONLY|SPIFFS_CREAT|SPIFFS_TRUNC;
else if(c_strcmp(mode, "r")==0) else if(strcmp(mode, "r")==0)
return SPIFFS_RDONLY; return SPIFFS_RDONLY;
else if(c_strcmp(mode, "a")==0) else if(strcmp(mode, "a")==0)
return SPIFFS_WRONLY|SPIFFS_CREAT|SPIFFS_APPEND; return SPIFFS_WRONLY|SPIFFS_CREAT|SPIFFS_APPEND;
else else
return SPIFFS_RDONLY; return SPIFFS_RDONLY;
} else if (c_strlen(mode)==2){ } else if (strlen(mode)==2){
if(c_strcmp(mode,"r+")==0) if(strcmp(mode,"r+")==0)
return SPIFFS_RDWR; return SPIFFS_RDWR;
else if(c_strcmp(mode, "w+")==0) else if(strcmp(mode, "w+")==0)
return SPIFFS_RDWR|SPIFFS_CREAT|SPIFFS_TRUNC; 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; return SPIFFS_RDWR|SPIFFS_CREAT|SPIFFS_APPEND;
else else
return SPIFFS_RDONLY; return SPIFFS_RDONLY;
...@@ -422,13 +422,13 @@ static vfs_file *myspiffs_vfs_open( const char *name, const char *mode ) { ...@@ -422,13 +422,13 @@ static vfs_file *myspiffs_vfs_open( const char *name, const char *mode ) {
struct myvfs_file *fd; struct myvfs_file *fd;
int flags = fs_mode2flag( mode ); 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 ))) { if (0 < (fd->fh = SPIFFS_open( &fs, name, flags, 0 ))) {
fd->vfs_file.fs_type = VFS_FS_SPIFFS; fd->vfs_file.fs_type = VFS_FS_SPIFFS;
fd->vfs_file.fns = &myspiffs_file_fns; fd->vfs_file.fns = &myspiffs_file_fns;
return (vfs_file *)fd; return (vfs_file *)fd;
} else { } else {
c_free( fd ); free( fd );
} }
} }
...@@ -438,13 +438,13 @@ static vfs_file *myspiffs_vfs_open( const char *name, const char *mode ) { ...@@ -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 ){ static vfs_dir *myspiffs_vfs_opendir( const char *name ){
struct myvfs_dir *dd; 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) )) { if (SPIFFS_opendir( &fs, name, &(dd->d) )) {
dd->vfs_dir.fs_type = VFS_FS_SPIFFS; dd->vfs_dir.fs_type = VFS_FS_SPIFFS;
dd->vfs_dir.fns = &myspiffs_dd_fns; dd->vfs_dir.fns = &myspiffs_dd_fns;
return (vfs_dir *)dd; return (vfs_dir *)dd;
} else { } else {
c_free( dd ); free( dd );
} }
} }
...@@ -455,10 +455,10 @@ static sint32_t myspiffs_vfs_stat( const char *name, struct vfs_stat *buf ) { ...@@ -455,10 +455,10 @@ static sint32_t myspiffs_vfs_stat( const char *name, struct vfs_stat *buf ) {
spiffs_stat stat; spiffs_stat stat;
if (0 <= SPIFFS_stat( &fs, name, &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 // 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->name[FS_OBJ_NAME_LEN] = '\0';
buf->size = stat.size; buf->size = stat.size;
...@@ -511,7 +511,7 @@ static void myspiffs_vfs_clearerr( void ) { ...@@ -511,7 +511,7 @@ static void myspiffs_vfs_clearerr( void ) {
vfs_fs_fns *myspiffs_realm( const char *inname, char **outname, int set_current_drive ) { vfs_fs_fns *myspiffs_realm( const char *inname, char **outname, int set_current_drive ) {
if (inname[0] == '/') { if (inname[0] == '/') {
// logical drive is specified, check if it's our id // 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)); *outname = (char *)(inname + sizeof(MY_LDRV_ID));
if (*outname[0] == '/') { if (*outname[0] == '/') {
// skip leading / // skip leading /
......
...@@ -7,10 +7,10 @@ ...@@ -7,10 +7,10 @@
* http://www.sqlite.org/src/doc/trunk/src/test_vfs.c * http://www.sqlite.org/src/doc/trunk/src/test_vfs.c
**/ **/
#include <c_stdio.h> #include <stdio.h>
#include <c_stdlib.h> #include <stdlib.h>
#include <c_string.h> #include <string.h>
#include <c_types.h> #include "c_types.h"
#include <osapi.h> #include <osapi.h>
#include <vfs.h> #include <vfs.h>
#include <time.h> #include <time.h>
......
...@@ -11017,7 +11017,7 @@ struct fts5_api { ...@@ -11017,7 +11017,7 @@ struct fts5_api {
** Include standard header files as necessary ** Include standard header files as necessary
*/ */
#ifdef HAVE_STDINT_H #ifdef HAVE_STDINT_H
#include <c_stdint.h> #include <stdint.h>
#endif #endif
#ifdef HAVE_INTTYPES_H #ifdef HAVE_INTTYPES_H
#include <inttypes.h> #include <inttypes.h>
...@@ -11608,9 +11608,9 @@ SQLITE_PRIVATE void sqlite3HashClear(Hash*); ...@@ -11608,9 +11608,9 @@ SQLITE_PRIVATE void sqlite3HashClear(Hash*);
   
/************** End of parse.h ***********************************************/ /************** End of parse.h ***********************************************/
/************** Continuing where we left off in sqliteInt.h ******************/ /************** Continuing where we left off in sqliteInt.h ******************/
#include <c_stdio.h> #include <stdio.h>
#include <c_stdlib.h> #include <stdlib.h>
#include <c_string.h> #include <string.h>
#include <assert.h> #include <assert.h>
#include <stddef.h> #include <stddef.h>
   
...@@ -12585,7 +12585,7 @@ SQLITE_PRIVATE int sqlite3SchemaMutexHeld(sqlite3*,int,Schema*); ...@@ -12585,7 +12585,7 @@ SQLITE_PRIVATE int sqlite3SchemaMutexHeld(sqlite3*,int,Schema*);
*/ */
#ifndef SQLITE_VDBE_H #ifndef SQLITE_VDBE_H
#define SQLITE_VDBE_H #define SQLITE_VDBE_H
/* #include <c_stdio.h> */ /* #include <stdio.h> */
   
/* /*
** A single VDBE is an opaque structure named "Vdbe". Only routines ** A single VDBE is an opaque structure named "Vdbe". Only routines
...@@ -18868,7 +18868,7 @@ SQLITE_API int sqlite3_db_status( ...@@ -18868,7 +18868,7 @@ SQLITE_API int sqlite3_db_status(
** Richmond, Virginia (USA) ** Richmond, Virginia (USA)
*/ */
/* #include "sqliteInt.h" */ /* #include "sqliteInt.h" */
/* #include <c_stdlib.h> */ /* #include <stdlib.h> */
/* #include <assert.h> */ /* #include <assert.h> */
#include <time.h> #include <time.h>
   
...@@ -20978,7 +20978,7 @@ SQLITE_PRIVATE void sqlite3MemSetDefault(void){ ...@@ -20978,7 +20978,7 @@ SQLITE_PRIVATE void sqlite3MemSetDefault(void){
# define backtrace(A,B) 1 # define backtrace(A,B) 1
# define backtrace_symbols_fd(A,B,C) # define backtrace_symbols_fd(A,B,C)
#endif #endif
/* #include <c_stdio.h> */ /* #include <stdio.h> */
   
/* /*
** Each memory allocation looks like this: ** Each memory allocation looks like this:
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
*/ */
#include "task/task.h" #include "task/task.h"
#include "mem.h" #include "mem.h"
#include "c_stdio.h" #include <stdio.h>
#define TASK_HANDLE_MONIKER 0x68680000 #define TASK_HANDLE_MONIKER 0x68680000
#define TASK_HANDLE_MASK 0xFFF80000 #define TASK_HANDLE_MASK 0xFFF80000
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
#include "u8x8_nodemcu_hal.h" #include "u8x8_nodemcu_hal.h"
#include "c_stdlib.h" #include <stdlib.h>
static const u8x8_display_info_t u8x8_fbrle_display_info = 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 ...@@ -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; uint8_t *buf = ((u8x8_tile_t *)arg_ptr)->tile_ptr;
struct fbrle_line *fbrle_line; 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; break;
} }
...@@ -147,7 +147,7 @@ static uint8_t u8x8_d_fbrle(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *ar ...@@ -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; break;
......
...@@ -39,9 +39,9 @@ ...@@ -39,9 +39,9 @@
// overflows. The downside is that it does not implement a wide range // overflows. The downside is that it does not implement a wide range
// of formatting characters. // of formatting characters.
#include <c_stdlib.h> #include <stdlib.h>
#include <c_types.h> #include <stdarg.h>
#include <c_stdarg.h> #include <stddef.h>
#include "driver/uart.h" #include "driver/uart.h"
static void kprintn (void (*)(const char), uint32_t, int, int, char); static void kprintn (void (*)(const char), uint32_t, int, int, char);
......
...@@ -10,9 +10,9 @@ ...@@ -10,9 +10,9 @@
*******************************************************************************/ *******************************************************************************/
#include "lua.h" #include "lua.h"
#include "platform.h" #include "platform.h"
#include "c_string.h" #include <string.h>
#include "c_stdlib.h" #include <stdlib.h>
#include "c_stdio.h" #include <stdio.h>
#include "vfs.h" #include "vfs.h"
#include "flash_api.h" #include "flash_api.h"
#include "user_interface.h" #include "user_interface.h"
......
...@@ -12,21 +12,20 @@ ...@@ -12,21 +12,20 @@
#define UZLIB_INFLATE_H #define UZLIB_INFLATE_H
#include <setjmp.h> #include <setjmp.h>
#include <stdint.h>
#include <stdlib.h>
#define uz_malloc malloc
#define uz_free free
#if defined(__XTENSA__) #if defined(__XTENSA__)
#include "c_stdint.h"
#include "mem.h" #include "mem.h"
#define UZLIB_THROW(v) longjmp(unwindAddr, (v)) #define UZLIB_THROW(v) longjmp(unwindAddr, (v))
#define UZLIB_SETJMP setjmp #define UZLIB_SETJMP setjmp
#define uz_malloc os_malloc
#define uz_free os_free
#else /* Host */ #else /* Host */
#include <stdint.h>
#include <stdlib.h>
extern int dbg_break(void); extern int dbg_break(void);
#if defined(_MSC_VER) || defined(__MINGW32__) //msvc requires old name for longjmp #if defined(_MSC_VER) || defined(__MINGW32__) //msvc requires old name for longjmp
#define UZLIB_THROW(v) {dbg_break();longjmp(unwindAddr, (v));} #define UZLIB_THROW(v) {dbg_break();longjmp(unwindAddr, (v));}
...@@ -36,9 +35,6 @@ extern int dbg_break(void); ...@@ -36,9 +35,6 @@ extern int dbg_break(void);
#define UZLIB_SETJMP(n) _setjmp(n) #define UZLIB_SETJMP(n) _setjmp(n)
#endif #endif
#define uz_malloc malloc
#define uz_free free
#endif /* defined(__XTENSA__) */ #endif /* defined(__XTENSA__) */
extern jmp_buf unwindAddr; extern jmp_buf unwindAddr;
......
...@@ -39,11 +39,7 @@ ...@@ -39,11 +39,7 @@
*/ */
#include <string.h> #include <string.h>
#ifdef __XTENSA__
#include "c_stdio.h"
#else
#include <stdio.h> #include <stdio.h>
#endif
#include "uzlib.h" #include "uzlib.h"
......
...@@ -30,9 +30,9 @@ ...@@ -30,9 +30,9 @@
#include "stdlib.h" #include "stdlib.h"
#include "c_types.h" #include "c_types.h"
#include "c_string.h" #include <string.h>
#include "c_stdlib.h" #include <stdlib.h>
#include "c_stdio.h" #include <stdio.h>
#include "websocketclient.h" #include "websocketclient.h"
...@@ -83,7 +83,7 @@ static char *cryptoSha1(char *data, unsigned int len) { ...@@ -83,7 +83,7 @@ static char *cryptoSha1(char *data, unsigned int len) {
SHA1Init(&ctx); SHA1Init(&ctx);
SHA1Update(&ctx, data, len); SHA1Update(&ctx, data, len);
uint8_t *digest = (uint8_t *) c_zalloc(20); uint8_t *digest = (uint8_t *) calloc(1,20);
SHA1Final(digest, &ctx); SHA1Final(digest, &ctx);
return (char *) digest; // Requires free return (char *) digest; // Requires free
} }
...@@ -93,7 +93,7 @@ static const char *bytes64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwx ...@@ -93,7 +93,7 @@ static const char *bytes64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwx
static char *base64Encode(char *data, unsigned int len) { static char *base64Encode(char *data, unsigned int len) {
int blen = (len + 2) / 3 * 4; int blen = (len + 2) / 3 * 4;
char *out = (char *) c_zalloc(blen + 1); char *out = (char *) calloc(1,blen + 1);
out[blen] = '\0'; out[blen] = '\0';
int j = 0, i; int j = 0, i;
for (i = 0; i < len; i += 3) { for (i = 0; i < len; i += 3) {
...@@ -197,7 +197,7 @@ static void ws_sendFrame(struct espconn *conn, int opCode, const char *data, uns ...@@ -197,7 +197,7 @@ static void ws_sendFrame(struct espconn *conn, int opCode, const char *data, uns
return; 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) { if (b == NULL) {
NODE_DBG("Out of memory when receiving message, disconnecting...\n"); 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) { ...@@ -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 if (ws->frameBuffer != NULL) { // Append previous frameBuffer with new content
NODE_DBG("Appending new frameBuffer to old one \n"); 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) { if (ws->frameBuffer == NULL) {
NODE_DBG("Failed to allocate new framebuffer, disconnecting...\n"); NODE_DBG("Failed to allocate new framebuffer, disconnecting...\n");
...@@ -358,7 +358,7 @@ static void ws_receiveCallback(void *arg, char *buf, unsigned short len) { ...@@ -358,7 +358,7 @@ static void ws_receiveCallback(void *arg, char *buf, unsigned short len) {
NODE_DBG("INCOMPLETE Frame \n"); NODE_DBG("INCOMPLETE Frame \n");
if (ws->frameBuffer == NULL) { if (ws->frameBuffer == NULL) {
NODE_DBG("Allocing new frameBuffer \n"); NODE_DBG("Allocing new frameBuffer \n");
ws->frameBuffer = c_zalloc(len); ws->frameBuffer = calloc(1,len);
if (ws->frameBuffer == NULL) { if (ws->frameBuffer == NULL) {
NODE_DBG("Failed to allocate framebuffer, disconnecting... \n"); NODE_DBG("Failed to allocate framebuffer, disconnecting... \n");
...@@ -379,7 +379,7 @@ static void ws_receiveCallback(void *arg, char *buf, unsigned short len) { ...@@ -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"); NODE_DBG("PARTIAL frame! Should concat payload and later restore opcode\n");
if(ws->payloadBuffer == NULL) { if(ws->payloadBuffer == NULL) {
NODE_DBG("Allocing new payloadBuffer \n"); NODE_DBG("Allocing new payloadBuffer \n");
ws->payloadBuffer = c_zalloc(payloadLength); ws->payloadBuffer = calloc(1,payloadLength);
if (ws->payloadBuffer == NULL) { if (ws->payloadBuffer == NULL) {
NODE_DBG("Failed to allocate payloadBuffer, disconnecting...\n"); NODE_DBG("Failed to allocate payloadBuffer, disconnecting...\n");
...@@ -395,7 +395,7 @@ static void ws_receiveCallback(void *arg, char *buf, unsigned short len) { ...@@ -395,7 +395,7 @@ static void ws_receiveCallback(void *arg, char *buf, unsigned short len) {
ws->payloadOriginalOpCode = opCode; ws->payloadOriginalOpCode = opCode;
} else { } else {
NODE_DBG("Appending new payloadBuffer to old one \n"); 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) { if (ws->payloadBuffer == NULL) {
NODE_DBG("Failed to allocate new framebuffer, disconnecting...\n"); NODE_DBG("Failed to allocate new framebuffer, disconnecting...\n");
...@@ -425,7 +425,7 @@ static void ws_receiveCallback(void *arg, char *buf, unsigned short len) { ...@@ -425,7 +425,7 @@ static void ws_receiveCallback(void *arg, char *buf, unsigned short len) {
return; return;
} }
// concat buffer with payload // concat buffer with payload
payload = c_zalloc(ws->payloadBufferLen + payloadLength); payload = calloc(1,ws->payloadBufferLen + payloadLength);
if (payload == NULL) { if (payload == NULL) {
NODE_DBG("Failed to allocate new framebuffer, disconnecting...\n"); NODE_DBG("Failed to allocate new framebuffer, disconnecting...\n");
...@@ -457,7 +457,7 @@ static void ws_receiveCallback(void *arg, char *buf, unsigned short len) { ...@@ -457,7 +457,7 @@ static void ws_receiveCallback(void *arg, char *buf, unsigned short len) {
extensionDataOffset += 2; extensionDataOffset += 2;
} }
payload = c_zalloc(payloadLength - extensionDataOffset + 1); payload = calloc(1,payloadLength - extensionDataOffset + 1);
if (payload == NULL) { if (payload == NULL) {
NODE_DBG("Failed to allocate payload, disconnecting...\n"); NODE_DBG("Failed to allocate payload, disconnecting...\n");
...@@ -511,7 +511,7 @@ static void ws_receiveCallback(void *arg, char *buf, unsigned short len) { ...@@ -511,7 +511,7 @@ static void ws_receiveCallback(void *arg, char *buf, unsigned short len) {
if (ws->frameBuffer != NULL) { if (ws->frameBuffer != NULL) {
NODE_DBG("Reallocing frameBuffer to remove consumed frame\n"); 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) { if (ws->frameBuffer == NULL) {
NODE_DBG("Failed to allocate new frame buffer, disconnecting...\n"); NODE_DBG("Failed to allocate new frame buffer, disconnecting...\n");
...@@ -738,12 +738,12 @@ void ws_connect(ws_info *ws, const char *url) { ...@@ -738,12 +738,12 @@ void ws_connect(ws_info *ws, const char *url) {
} }
// Extract protocol - either ws or wss // 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) { if (isSecure) {
url += strlen(PROTOCOL_SECURE); url += strlen(PROTOCOL_SECURE);
} else { } 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); NODE_DBG("Failed to extract protocol from: %s\n", url);
if (ws->onFailure) ws->onFailure(ws, -1); if (ws->onFailure) ws->onFailure(ws, -1);
return; return;
...@@ -752,7 +752,7 @@ void ws_connect(ws_info *ws, const char *url) { ...@@ -752,7 +752,7 @@ void ws_connect(ws_info *ws, const char *url) {
} }
// Extract path - it should start with '/' // Extract path - it should start with '/'
char *path = c_strchr(url, '/'); char *path = strchr(url, '/');
// Extract hostname, possibly including port // Extract hostname, possibly including port
char hostname[256]; char hostname[256];
...@@ -800,9 +800,9 @@ void ws_connect(ws_info *ws, const char *url) { ...@@ -800,9 +800,9 @@ void ws_connect(ws_info *ws, const char *url) {
// Prepare internal ws_info // Prepare internal ws_info
ws->connectionState = 1; ws->connectionState = 1;
ws->isSecure = isSecure; ws->isSecure = isSecure;
ws->hostname = c_strdup(hostname); ws->hostname = strdup(hostname);
ws->port = port; ws->port = port;
ws->path = c_strdup(path); ws->path = strdup(path);
ws->expectedSecKey = NULL; ws->expectedSecKey = NULL;
ws->knownFailureCode = 0; ws->knownFailureCode = 0;
ws->frameBuffer = NULL; ws->frameBuffer = NULL;
...@@ -813,10 +813,10 @@ void ws_connect(ws_info *ws, const char *url) { ...@@ -813,10 +813,10 @@ void ws_connect(ws_info *ws, const char *url) {
ws->unhealthyPoints = 0; ws->unhealthyPoints = 0;
// Prepare espconn // 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->type = ESPCONN_TCP;
conn->state = ESPCONN_NONE; 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->local_port = espconn_port();
conn->proto.tcp->remote_port = ws->port; conn->proto.tcp->remote_port = ws->port;
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
--defsym=strncmp=ets_strncmp --defsym=strncmp=ets_strncmp
--defsym=strncpy=ets_strncpy --defsym=strncpy=ets_strncpy
--defsym=strstr=ets_strstr --defsym=strstr=ets_strstr
--defsym=strdup=ets_strdup
--defsym=memcmp=ets_memcmp --defsym=memcmp=ets_memcmp
--defsym=memcpy=ets_memcpy --defsym=memcpy=ets_memcpy
--defsym=memmove=ets_memmove --defsym=memmove=ets_memmove
......
#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
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