On 5/30/06, Peter Blair <[EMAIL PROTECTED]> wrote:
Be careful -- if you have an application "say /usr/local/whatever/foo"
that is linked from "/usr/local/bin/bar" then when you call
"/usr/local/bin/bar" it will populate "bar" as the argv[0] element.

Wrong, argv[0] will be whatever was passed to execvp as the first
element of the second argument.  (If that is not clear remember that
the second argument is a NULL-terminated array of char pointers.)
Although in most cases it will be set to the name of the application
or a path to it.

This may be what you want, but then again, perhaps you want to know
that "foo" is the application being called.

"__progname" *should* ensure that "foo" is is being used when doing
things like opening app-name specific logs etc.

Wrong again, __progname is derived from argv[0].  That's what enable
things like crunchgen to work by altering the function of the program
based on its name.


On 5/30/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:

> I usually write a usage function to take a single argument, i.e.
> usage(const char *progname).  When I call usage(), which is always
> from main(), I just pass in argv[0].  I'm under the impression that
> argv[0] being set to the name of the program is standard (could be
> wrong though).


__progname is filled in at program initialisation time (in ___start)
with everything after the last / in argv[0].  It has nothing to do
with the compiler.

If you don't trust me, trust the sources:
http://www.openbsd.org/cgi-bin/cvsweb/src/lib/csu/i386/crt0.c?rev=1.13&content-type=text/x-cvsweb-markup

--
"i think we should rewrite the kernel in java since it has good
support for threads." - Ted Unangst

Reply via email to