config: delete existing variable before writing new contents

This commit is contained in:
C. Masloch 2023-08-30 10:57:24 +02:00 committed by Kenneth J Davis
parent 132a0a9f94
commit 3dafa54e8b
3 changed files with 27 additions and 2 deletions

View File

@ -327,7 +327,6 @@ strcpy_loop:
jmp short pascal_return
;******************************************************************
%ifndef _INIT
global FSTRLEN
FSTRLEN:
call pascal_setup
@ -337,7 +336,6 @@ FSTRLEN:
mov bl,4
jmp short dostrlen
%endif
;**********************************************
global STRLEN

View File

@ -2739,6 +2739,30 @@ VOID DoInstall(void)
return;
}
STATIC BYTE far * searchvar(const BYTE * name, int length)
{
BYTE far * pp = master_env;
do {
if (!fmemcmp(name, pp, length + 1)) {
return pp;
}
pp += fstrlen(pp) + 1;
} while (*pp);
return NULL;
}
STATIC void deletevar(const BYTE * name, int length) {
int variablelength;
BYTE far * pp = searchvar(name, length);
if (NULL == pp)
return;
variablelength = fstrlen(pp) + 1;
fmemcpy(pp, pp + variablelength, envp + 3 - (pp + variablelength));
/* our fmemcpy always copies forwards */
envp -= variablelength;
return;
}
STATIC VOID CmdSet(BYTE *pLine)
{
pLine = GetStringArg(pLine, szBuf);
@ -2747,7 +2771,9 @@ STATIC VOID CmdSet(BYTE *pLine)
{
int size;
strupr(szBuf); /* all environment variables must be uppercase */
size = strlen(szBuf);
strcat(szBuf, "=");
deletevar(szBuf, size);
pLine = skipwh(++pLine);
strcat(szBuf, pLine); /* append the variable value (may include spaces) */
size = strlen(szBuf);

View File

@ -150,6 +150,7 @@ SECTIONS
_init_strcpy = INIT_STRCPY;
_init_fstrcpy = INIT_FSTRCPY;
_init_strlen = INIT_STRLEN;
_init_fstrlen = INIT_FSTRLEN;
_init_strchr = INIT_STRCHR;
_UMB_get_largest = UMB_GET_LARGEST;
_init_call_intr = INIT_CALL_INTR;