Velocity Reviews > Question about C

Richard Bos
Guest
Posts: n/a

 05-17-2010
Malcolm McLean <(E-Mail Removed)> wrote:

> On May 12, 6:06=A0am, (E-Mail Removed) wrote:
> >
> > No, argv[0] contains the *name* of the program, which is usually *not*
> > the complete path and might not have anything whatsoever to do with the
> > path to the executable file.

Not even that; it _represents_ the program name. If the program has been
called in an unusual way (or on an unusual OS), it might not even have
anything to do with the real name of the executable file.

> You need to look at the environment pointer, passed in as a third
> parameter, which usually contains the paths to directories containing
> executables. However that's also non-ANSI, of course.

....and, partly because of the above, does not work in the general case.

And then, even with a perfectly normal program execution, who is to say
that running "\not\in\the\normal\executable\PATH\environment\pr ogname"
does not result in argv[0] containing only "progname"? If PATH contains
"\$HOME$\programs;\public\programs;\\progserver\\p ublic\programs" and
there happens to be another program, also called "progname", on that
server referred to in that PATH, your method will find the wrong program
file. And that's not a _very_ unlikely scenario, you'll have to admit.

Richard