home *** CD-ROM | disk | FTP | other *** search
- From: jensk@hpbbrd.bbn.hp.com (Jens Kilian)
- Date: Tue, 28 Jul 1992 06:39:20 GMT
- Subject: Problems with ARGV
- Message-ID: <9130026@hpbbrd.bbn.hp.com>
- Organization: HP Mechanical Design Division
- Path: sparky!uunet!darwin.sura.net!mips!sdd.hp.com!hplabs!hplextra!hpfcso!hpfcmdd!hpbbrd!jensk
- Newsgroups: comp.sys.atari.st.tech
- Lines: 49
-
- Yesterday I ran into a problem with the ARGV parameter passing scheme that
- I'm sure others must have seen before. The ARGV scheme can't pass empty strings
- as parameters !
- What happens is that Pexec can't distinguish between an empty parameter and
- the end of the environment string (both are represented by two consecutive
- NUL bytes). In effect, the first empty parameter will terminate the parameter
- list.
-
- Since I haven't seen this problem come up previously, I guess that nobody ever
- tried to work around it. Anyway, here's a suggestion for fixing it (while
- still remaining compatible to ARGV):
-
- - Pass all non-empty arguments via ARGV, ignoring empty ones.
- Let's say you want to execute
-
- /bin/arrgh foo "" bar baz "" zip;
-
- you would pass an environment string ending in
-
- ARGV=\0/bin/arrgh\0foo\0bar\0baz\0zip\0\0
-
- - Pass the *positions* of the empty arguments in some other place
- (within the environment). Most convenient would be the ARGV variable
- itself, but some shells and/or runtime libraries already use that
- for other purposes.
- Assuming you use an environment variable called 'ARRGH' (just for
- demonstration) and pass the positions in ASCII format (dito), this
- would look like
-
- ARRGH=2,5\0
-
- in the example above. The C startup code would interpret this by
- assigning empty strings to argv[2] and argv[5].
-
- This approach won't break any existing code. If a program or shell doesn't
- understand it, it will just keep the old behavior. By incorporating the
- mechanism into the C library (startup code and exec() or spawn() or whatever),
- programs have just to be relinked to be able to use it.
-
- I'd like to hear the experts comment on this.
-
- Jens.
- --
- Internet: jensk@hpbeo82.bbn.hp.com HPDESK : JENS_KILIAN%XU@HP1200
- MausNet: Jens Kilian @ BB KILIAN_JENS/HP1200_XU@hpbbi4
- Phone: (0|+49)7031-14-4308 TELNET : 778-4308
- Fax : (0|+49)7031-14-2049
- -------------------------------------------------------------------------------
- As the air to a bird, or the sea to a fish, so is contempt to the contemptible.
-