Mail Archives: djgpp/2011/12/07/06:15:21
"Georg" <dosusb AT googlemail DOT com> wrote in message
news:dca6ea34-7cf2-4abe-afc3-8a1122602ed9 AT y12g2000vba DOT googlegroups DOT com...
> I finally found a way to retrieve the absolute path to the current
> program. It seems that the pointer to the environment in the PSP when
> using DJGPP is wrong for whatever reason. There is a KB16 program
> which has the correct pointer to the environment I am looking for in
> its PSP though.
>
> So I walked through the MCB chain to find the environment block in
> there. There are two entries in there with the same PSP, one is the
> environment block, the other is the program code. The latter has the
> PSP right after the MCB so if that is not the case you have found the
> environment block. The absolute path is then located behind the size
> given in the MCB of the environment block. Here is my code:
>
> #include <stdio.h>
> #include <sys/movedata.h>
> #include <dpmi.h>
> #include <go32.h>
>
> main(int argc,char **argv)
> {
> [...]
FYI, that code returns the correct program names, but doesn't return *any*
paths here, not for RM DOS, nor for Windows 98 "dosbox." In RM DOS, it also
SIGSEGVs.
What does this do on your end? It's what I suggested earlier. It prints
the correct ENV here.
#include <stdio.h>
#include <go32.h>
#include <dpmi.h>
#define env_size 320
int main()
{
int i;
unsigned int env_address = 0;
unsigned int the_psp = 0 , old_psp;
static char environment[env_size];
the_psp = _go32_info_block.linear_address_of_original_psp;
printf("\nPSP:%04X\n",the_psp);
dosmemget(the_psp,sizeof(environment),&environment);
do{
old_psp=the_psp;
dosmemget(the_psp+0x16, 2, &the_psp);
the_psp <<= 4; //make linear address
dosmemget(the_psp,sizeof(environment),&environment);
}while(old_psp!=the_psp);
dosmemget(the_psp + 0x2C, 2, &env_address);
env_address <<= 4; //make linear address
printf("\nENV:%04X\n",env_address);
dosmemget(env_address, sizeof(environment), &environment);
for (i=0;i<env_size;i++) {printf("%c",environment[i]);}
return 0;
}
Rod Pemberton
- Raw text -