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