Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@
#define _MALLOC_H

bool init_malloc();
void * malloc(size_t _Size);

#endif
#endif
5 changes: 5 additions & 0 deletions source/libs/grid/stdlib/getenv.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
#include <compiler.h>
#include <types.h>
#include "env.h"
#include "string.h"
#include "crt.h"
#include "malloc.h"
#include "stdio.h"

extern char *_environ ; //����������ָ��

Expand Down Expand Up @@ -53,3 +57,4 @@ DLLEXPORT __weak char *getenv(const char * name)
UNLOCK_ENV_VARIABLE;
return NULL;
}

15 changes: 11 additions & 4 deletions source/libs/grid/stdlib/setenv.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,17 @@
#include <types.h>
#include <errno.h>
#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;
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -125,3 +131,4 @@ DLLEXPORT __weak int setenv(const char * name, const char * value, int overwrit
UNLOCK_ENV_VARIABLE;
return 0;
}