home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / sys / atari / st / tech / 4162 < prev    next >
Encoding:
Internet Message Format  |  1992-07-28  |  2.4 KB

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