X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f From: Georg Newsgroups: comp.os.msdos.djgpp Subject: Re: argv[0] Date: Sun, 4 Dec 2011 09:26:14 -0800 (PST) Organization: http://groups.google.com Lines: 84 Message-ID: References: <16b04d29-8317-4c7f-929c-1a22a328fa32 AT p9g2000vbb DOT googlegroups DOT com> <9bf257a7-a0f8-43ba-a65f-36c6027f68cb AT r28g2000yqj DOT googlegroups DOT com> NNTP-Posting-Host: 92.250.191.164 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 X-Trace: posting.google.com 1323019575 28530 127.0.0.1 (4 Dec 2011 17:26:15 GMT) X-Complaints-To: groups-abuse AT google DOT com NNTP-Posting-Date: Sun, 4 Dec 2011 17:26:15 +0000 (UTC) Complaints-To: groups-abuse AT google DOT com Injection-Info: y12g2000vba.googlegroups.com; posting-host=92.250.191.164; posting-account=v5xbdQoAAAAOGc9Ccc-kLZyobvPlN3Qr User-Agent: G2/1.0 X-HTTP-Via: 1.1 TAS-4-1.man-a X-Google-Web-Client: true X-Google-Header-Order: UALSERCVNKH X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.1.4) Gecko/20091016 Firefox/3.5.4,gzip(gfe) Bytes: 4177 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie 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 #include #include #include main(int argc,char **argv) { unsigned int es,peekword,blocksize,pspseg,environment; unsigned short mcbid=0x4d; unsigned long the_psp = 0; static unsigned mcbseg; //first mcb unsigned mcbs; char* buff[256]; __dpmi_regs regs; regs.x.ax = 0x5200; /* AH = 52h, AL = 00h */ __dpmi_int (0x21, ®s); /* call DOS */ if (regs.x.flags & 1) /* is carry flag set? */ {;} /* The call failed*/ else { es = regs.x.es; es <<= 4; es += regs.x.bx; _dosmemgetw(es-2, 1, &mcbseg); mcbseg <<= 4; } the_psp = _go32_info_block.linear_address_of_original_psp; while (mcbid==0x4d){ mcbs=mcbseg; printf("\nMCB:%X \t",mcbs); _dosmemgetb(mcbs,1,&mcbid); printf("%c ",mcbid); _dosmemgetw(mcbs+1,1,&pspseg); printf("PSP:%X \t",pspseg); environment=pspseg<<4; environment += 0x2C; _dosmemgetw(mcbs+3,1,&blocksize); printf("Blocksize:%X \t",blocksize); if ((mcbseg+16)==pspseg*16){ //is it a program code mcb? _dosmemgetw(environment,1,&peekword); printf("ENV:%X ",peekword); //only print if program code dosmemget(mcbs+8,30,&buff); printf(" Program:%s",buff); } if (pspseg*16==the_psp) { //found the right PSP? //not the code but the environment block? if ((mcbseg+16)!=the_psp){ dosmemget(mcbs+blocksize*16-18,30,&buff); printf("Path:%s",buff); } } //retrieve next mcb _dosmemgetw(mcbs+3,1,&peekword); peekword <<=4; mcbseg += peekword+0x10; } return 0; } I should have used a different variable name instead of mcbseg but I leave it now as it is. Rayer may have pointed out correctly that this is all too complicated and could be replaced by reading the value in argv[0]. But I observed that when I start my code with "redir" argv[0] will not return the full path. Plus DJ Delorie's post made me uncertain whether I should use argv[0]. Georg