From: Frantisek Hanzlik <franta@hanzlici.cz>
To: Paul Crawford <psc@sat.dundee.ac.uk>
Cc: DOSEMU/FreeDOS <linux-msdos@vger.kernel.org>,
Freedos user list <freedos-user@lists.sourceforge.net>
Subject: Re: DOS program recording it's parameters and environment?
Date: Thu, 16 Feb 2012 22:34:49 +0100 [thread overview]
Message-ID: <4F3D7679.1070106@hanzlici.cz> (raw)
In-Reply-To: <4F3D6EC1.4050100@sat.dundee.ac.uk>
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 <stdlib.h>.
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 <stdio.h>
> #include <stdlib.h>
>
> 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<argc; 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;
> }
next prev parent reply other threads:[~2012-02-16 21:34 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-01-18 5:20 DOS program recording it's parameters and environment? Frantisek Hanzlik
[not found] ` <4F16E21B.9030804@gmail.com>
2012-01-18 17:46 ` Frantisek Hanzlik
2012-01-18 17:55 ` Frank Cox
2012-01-18 18:36 ` Frantisek Hanzlik
2012-01-18 19:17 ` Scott
2012-01-27 12:01 ` Paul Crawford
2012-02-16 18:54 ` Frantisek Hanzlik
2012-02-16 21:01 ` Paul Crawford
2012-02-16 21:34 ` Frantisek Hanzlik [this message]
2012-02-17 1:57 ` Samuel Bronson
2012-02-17 22:29 ` Scott
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4F3D7679.1070106@hanzlici.cz \
--to=franta@hanzlici.cz \
--cc=freedos-user@lists.sourceforge.net \
--cc=linux-msdos@vger.kernel.org \
--cc=psc@sat.dundee.ac.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox