argv[0] handling

Theo Markettos theo at
Tue Jun 14 05:57:52 PDT 2005

On Tue, Jun 14, 2005 at 01:26:52PM +0100, Alex Waugh wrote:
> I have a feeling that there are a few programs that change their 
> behaviour based on argv[0], but I can't think of any examples at present.

A rather extreme case is busybox, which does the job of 101 standard Unix
tools and works out which one you asked for via argv[0].  I'm guessing this
is generally done with hard/soft links but we could do it with aliases which
wouldn't break argv[0] (unless people do things like */foo )
[does exec*() handle RISC OS aliases?]

> I think canonicalising it if it contains any . : < > $ characters, 
> otherwise leaving it as it is, should be good enough for most cases.

The aliases case above makes that a little more dangerous: what does
exec("cat") do?  (which could exist as a built in *command, an alias and an
executable all at the same time).  What about exec(".")?

> I'd be tempted to leave making it configurable until someone finds a 
> case where it is needed.

I think probably making it configurable and the default being keep the
status quo is safest...


More information about the gcc mailing list