Set the program name if the crunched program is selected through

argv[1] to mimic crt0 behaviour.  Do the job by a direct assignment
to __progname in order to stay compatible with NetBSD, whose
setprogname() is a deliberate no-op.

The reason for this change is that some programs (usually those
imported from NetBSD) use getprogname() to distinguish between their
aliases.  (See pkill aka pgrep for example.)

This change can be useful, and applicable, to NetBSD, too.
This commit is contained in:
yar 2007-10-27 16:13:31 +00:00
parent 0b0826633e
commit 59761712e0

View File

@ -41,6 +41,7 @@ struct stub {
int (*f)();
};
extern char *__progname;
extern struct stub entry_points[];
int main(int argc, char **argv, char **envp)
@ -83,12 +84,16 @@ int crunched_here(char *path)
int crunched_main(int argc, char **argv, char **envp)
{
char *slash;
struct stub *ep;
int columns, len;
if(argc <= 1)
crunched_usage();
slash = strrchr(argv[1], '/');
__progname = slash? slash+1 : argv[1];
return main(--argc, ++argv, envp);
}