From mboxrd@z Thu Jan 1 00:00:00 1970 From: Frantisek Hanzlik Subject: Re: DOS program recording it's parameters and environment? Date: Thu, 16 Feb 2012 22:34:49 +0100 Message-ID: <4F3D7679.1070106@hanzlici.cz> References: <4F165699.1080204@hanzlici.cz> <4F229215.1040801@sat.dundee.ac.uk> <4F3D50CF.4000004@hanzlici.cz> <4F3D6EC1.4050100@sat.dundee.ac.uk> Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <4F3D6EC1.4050100@sat.dundee.ac.uk> Sender: linux-msdos-owner@vger.kernel.org List-ID: Content-Type: text/plain; charset="us-ascii" To: Paul Crawford Cc: DOSEMU/FreeDOS , Freedos user list Dear Paul, You are right, it works with Watcom C fine. And now I found in "Watcom C Library Reference" manual paragraph: environ Prototype in . This char ** __near data item is a pointer to an array of character pointers to the environment strings. which I not noticed before. Eeh, I still must learn to much! Many thanks once again, Franta Paul Crawford napsal(a): > Dear Frantisek, >> compiler v1.9 (http://www.openwatcom.org/) for DOS. And there I knock >> to problem - it seems as this compiler not support construction: >> >> int main(int argc, char *argv[], char *envp[]) > > I think this 3rd argument may be a MS-specific extension, as most C > programs just have argc & argv in the call to main(); > > If you change to use the 'environ' variable, that should be pre-defined > (probably in stdlib.h) and should do the same job. Attached is an > example that seems to compile & work under C6 DOS compiler and with gcc > on my Ubuntu 10.04 box. > > Regards, > Paul > > > dosenv.c > > > > > #include > #include > > extern char **environ; > > int main(int argc, char *argv[]) > { > int ii; > FILE *fp; > char **envp = environ; > > > fp=fopen("dosenv.txt", "wb"); > if(fp != NULL) > { > fprintf(fp, "argc = %d\n", argc); > > for(ii=0; ii { > fprintf(fp, "argv[%d] = %s\n", ii, argv[ii]); > } > > ii=0; > while(envp != NULL && envp[ii] != NULL) > { > fprintf(fp, "envp[%d] = %s\n", ii, envp[ii]); > ii++; > } > > fclose(fp); > } > > > return 0; > }