ftp.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2011/12/07/06:15:21

X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f
From: "Rod Pemberton" <do_not_have AT noavailemail DOT cmm>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: argv[0]
Date: Wed, 7 Dec 2011 06:00:48 -0500
Organization: Aioe.org NNTP Server
Lines: 68
Message-ID: <jbngu9$b4$1@speranza.aioe.org>
References: <16b04d29-8317-4c7f-929c-1a22a328fa32 AT p9g2000vbb DOT googlegroups DOT com> <jaueod$2t8$1 AT speranza DOT aioe DOT org> <9bf257a7-a0f8-43ba-a65f-36c6027f68cb AT r28g2000yqj DOT googlegroups DOT com> <jb1ejh$hm8$1 AT speranza DOT aioe DOT org> <cc43d375-8e59-425d-a32e-b4ca200ae5cc AT 4g2000yqu DOT googlegroups DOT com> <jbeegg$qp2$1 AT speranza DOT aioe DOT org> <dca06357-dc1d-4ede-aa9e-510e15e499b5 AT z17g2000vbe DOT googlegroups DOT com> <dca6ea34-7cf2-4abe-afc3-8a1122602ed9 AT y12g2000vba DOT googlegroups DOT com>
NNTP-Posting-Host: qBjb0U1QTH77eiTXJSCpEw.user.speranza.aioe.org
X-Complaints-To: abuse AT aioe DOT org
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.2001
X-Notice: Filtered by postfilter v. 0.8.2
X-Newsreader: Microsoft Outlook Express 6.00.2800.2001
X-Priority: 3
X-MSMail-Priority: Normal
Bytes: 3230
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

"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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019