2014-12-22 12:35:05 +01:00
|
|
|
#include "c_stdlib.h"
|
|
|
|
#include "c_stdio.h"
|
|
|
|
#include "c_types.h"
|
|
|
|
#include "c_string.h"
|
|
|
|
#include "user_interface.h"
|
|
|
|
|
|
|
|
// const char *lua_init_value = "print(\"Hello world\")";
|
|
|
|
const char *lua_init_value = "@init.lua";
|
|
|
|
|
2015-01-05 03:09:51 +01:00
|
|
|
// int c_abs(int x){
|
2014-12-22 12:35:05 +01:00
|
|
|
// return x>0?x:0-x;
|
|
|
|
// }
|
2015-01-05 03:09:51 +01:00
|
|
|
// void c_exit(int e){
|
2014-12-22 12:35:05 +01:00
|
|
|
// }
|
2015-01-05 03:09:51 +01:00
|
|
|
const char *c_getenv(const char *__string){
|
2014-12-22 12:35:05 +01:00
|
|
|
if (c_strcmp(__string, "LUA_INIT") == 0){
|
|
|
|
return lua_init_value;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// make sure there is enough memory before real malloc, otherwise malloc will panic and reset
|
2015-01-05 03:09:51 +01:00
|
|
|
void *c_malloc(size_t __size){
|
2014-12-22 12:35:05 +01:00
|
|
|
if(__size>system_get_free_heap_size()){
|
|
|
|
NODE_ERR("malloc: not enough memory\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return (void *)os_malloc(__size);
|
|
|
|
}
|
|
|
|
|
2015-01-05 03:09:51 +01:00
|
|
|
void *c_zalloc(size_t __size){
|
2014-12-22 12:35:05 +01:00
|
|
|
if(__size>system_get_free_heap_size()){
|
|
|
|
NODE_ERR("zalloc: not enough memory\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return (void *)os_zalloc(__size);
|
|
|
|
}
|
|
|
|
|
2015-01-05 03:09:51 +01:00
|
|
|
void c_free(void *p){
|
2014-12-22 12:35:05 +01:00
|
|
|
// NODE_ERR("free1: %d\n", system_get_free_heap_size());
|
|
|
|
os_free(p);
|
|
|
|
// NODE_ERR("-free1: %d\n", system_get_free_heap_size());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-01-05 03:09:51 +01:00
|
|
|
// int c_rand(void){
|
2014-12-22 12:35:05 +01:00
|
|
|
// }
|
2015-01-05 03:09:51 +01:00
|
|
|
// void c_srand(unsigned int __seed){
|
2014-12-22 12:35:05 +01:00
|
|
|
// }
|
|
|
|
|
2015-01-05 03:09:51 +01:00
|
|
|
// int c_atoi(const char *__nptr){
|
2014-12-22 12:35:05 +01:00
|
|
|
// }
|
2015-01-05 03:09:51 +01:00
|
|
|
// double c_strtod(const char *__n, char **__end_PTR){
|
2014-12-22 12:35:05 +01:00
|
|
|
// }
|
2015-01-05 03:09:51 +01:00
|
|
|
// long c_strtol(const char *__n, char **__end_PTR, int __base){
|
2014-12-22 12:35:05 +01:00
|
|
|
// }
|
2015-01-05 03:09:51 +01:00
|
|
|
// unsigned long c_strtoul(const char *__n, char **__end_PTR, int __base){
|
2014-12-22 12:35:05 +01:00
|
|
|
// }
|
2015-01-05 03:09:51 +01:00
|
|
|
// long long c_strtoll(const char *__n, char **__end_PTR, int __base){
|
2014-12-22 12:35:05 +01:00
|
|
|
// }
|