mailing list of musl libc
 help / color / mirror / code / Atom feed
* program_invocation_name
@ 2013-03-24  0:16 Rich Felker
  2013-03-24  2:49 ` program_invocation_name Szabolcs Nagy
  0 siblings, 1 reply; 5+ messages in thread
From: Rich Felker @ 2013-03-24  0:16 UTC (permalink / raw)
  To: musl

Hi,

I've seen some demand again for the GNU extension
program_invocation_name (and program_invocation_short_name) and I'm
not totally opposed to adding them (although the latter adds some ugly
nontrivial startup cost), but I'm also frustrated that they're not
documented properly. The glibc manual defines them as:

— Variable: char * program_invocation_name
This variable's value is the name that was used to invoke the program
running in the current process. It is the same as argv[0]. Note that
this is not necessarily a useful file name; often it contains no
directory names. See Program Arguments.

— Variable: char * program_invocation_short_name
This variable's value is the name that was used to invoke the program
running in the current process, with directory names removed. (That is
to say, it is the same as program_invocation_name minus everything up
to the last slash, if any.)

But my understanding is that these descriptions are false, and that
program_invocation_name is just a pointer to the same storage as
argv[0], and program_invocation_short_name points to the tail of
argv[0]. In this case, modifications to argv[0] would be reflected
through these pointers. Is that correct and reasonable? The
alternative, copying a string that could be up to ARG_MAX to its own
storage, is obviously nasty and unwanted.

If we do add program_invocation_short_name, what should the size/speed
tradeoff be? I really don't want to make strrchr a mandatory part of
the startup code; would a trivial loop to do the job suffice?

for (s=t=argv[0]; *t; t++) if (*t=='/') s=t+1;

Rich


P.S. If we do add these, we could certainly add the BSD names too as
aliases.


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2013-03-24  9:29 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-03-24  0:16 program_invocation_name Rich Felker
2013-03-24  2:49 ` program_invocation_name Szabolcs Nagy
2013-03-24  3:01   ` program_invocation_name Rich Felker
2013-03-24  3:24     ` program_invocation_name Szabolcs Nagy
2013-03-24  9:29       ` program_invocation_name Daniel Cegiełka

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).