diff --git a/source/libs/grid/malloc/malloc.h b/source/libs/grid/include/malloc.h similarity index 78% rename from source/libs/grid/malloc/malloc.h rename to source/libs/grid/include/malloc.h index 46414ef..34eb6ef 100644 --- a/source/libs/grid/malloc/malloc.h +++ b/source/libs/grid/include/malloc.h @@ -11,5 +11,6 @@ #define _MALLOC_H bool init_malloc(); +void * malloc(size_t _Size); -#endif \ No newline at end of file +#endif diff --git a/source/libs/grid/stdlib/getenv.c b/source/libs/grid/stdlib/getenv.c index ad821de..e724e1c 100644 --- a/source/libs/grid/stdlib/getenv.c +++ b/source/libs/grid/stdlib/getenv.c @@ -14,6 +14,10 @@ #include #include #include "env.h" +#include "string.h" +#include "crt.h" +#include "malloc.h" +#include "stdio.h" extern char *_environ ; //环境变量首指针 @@ -53,3 +57,4 @@ DLLEXPORT __weak char *getenv(const char * name) UNLOCK_ENV_VARIABLE; return NULL; } + diff --git a/source/libs/grid/stdlib/setenv.c b/source/libs/grid/stdlib/setenv.c index 248233b..6e268e5 100644 --- a/source/libs/grid/stdlib/setenv.c +++ b/source/libs/grid/stdlib/setenv.c @@ -13,11 +13,17 @@ #include #include #include "env.h" +#include "string.h" +#include "crt.h" +#include "malloc.h" +#include "stdio.h" char *_environ = NULL; //环境变量首指针 char *_cur_env = NULL; //指向环境变量空闲空间首地址 unsigned long _env_len = NULL; //当前环境变量指针所指向的空间的总大小 +/* 变量存放格式: 名称+值长度+值内容*/ + DLLEXPORT __weak int setenv(const char * name, const char * value, int overwrite) { char *p = _environ, *tmpp; @@ -53,19 +59,19 @@ DLLEXPORT __weak int setenv(const char * name, const char * value, int overwrit { break; } - p = p + strlen(name) + __SIZE_OF_END_CHAR_; // name eof + p = p + strlen(name) + __SIZE_OF_END_CHAR_; memcpy(&oldlen, p, sizeof(int)); p += sizeof(int); - p += oldlen + __SIZE_OF_END_CHAR_; //eof + p += oldlen + __SIZE_OF_END_CHAR_; } ; - if (*p == 0) //需新增 + if (*p == 0) /*需新增 */ { p = _cur_env; strcpy(p, name); p += strlen(name); - *p = NULL; //eof + *p = NULL; p++; newlen = strlen(value); memcpy(p, (char*)&newlen, sizeof(int)); @@ -125,3 +131,4 @@ DLLEXPORT __weak int setenv(const char * name, const char * value, int overwrit UNLOCK_ENV_VARIABLE; return 0; } +