[comp.sys.ibm.pc] Some stuff on argv[0] under MS-DOS

madd@bucsb.bu.edu.UUCP (02/25/87)

Awhile back, people were talking about an "undocumented" argv[0] they
were using to find the name of the program they were executing.  This
was just fine, but of course purists worry about portability between
systems when undocumented features are used.  Basically, they found a
place where MS-DOS would put the pathname/name of the program being
executed.

Well, I was poking around in the DOS Tech Ref manual, and look what I
found:

"Also inherited [...] is an 'environment'.  This is a block of text
strings [...]  Following the [last] byte of zero in the environment,
is a WORD that indicates the number of other strings following.  Following
this is a copy of the DS:DX filename passed on the the child process."

                                           -- IBM PC-DOS Technical Ref.
                                              Version 3.10, p. 6-148
                                              (Function 4BH descrip.)

DS:DX is the pointer used to tell the exec function which program to
load when executing it, so DOS copies this string into the area
following the environment area.

There you go.  Documentation.  I note that this is NOT explained in
the sections of the manual dealing with the PSP, as it should be.  It
also describes the "couple of bytes" that people were confused about
that appear between the environment strings and the argv[0] string.

Now that I see argv[0] documented, I feel safe in using it.  Now,
somebody should explain to me why Microsoft/IBM thought this field so
unimportant as to mention it only once within their entire manual, and
in the wrong place, too!

Happy hacking.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
                   - Jim Frost * The Madd Hacker -
UUCP:  ..!harvard!bu-cs!bucsb!madd | ARPANET: madd@bucsb.bu.edu
CSNET: madd%bucsb@bu-cs            | BITNET:  cscc71c@bostonu
-------------------------------+---+------------------------------------
"Oh beer, oh beer." -- Me      |      [=(BEER) <- Bud the Beer (cheers!)