dasdfmt: Set prog_name to last component of program name

In the process of switching to glibc defined error functions it becomes
apparent that self-defined error functions that do special things are
not in line with the output of the glibc functions.

To address this, set the prog_name variable to the last component of the
program name (stored in argv[0]) and guarantee a uniform error output.

Reviewed-by: Stefan Haberland <sth@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
This commit is contained in:
Jan Höppner
2020-10-25 20:16:00 +01:00
parent 9fe491df27
commit da4fdeeb82

View File

@@ -1481,6 +1481,20 @@ static void eval_format_mode(void)
mode = g.ese ? QUICK : FULL;
}
/*
* Set prog_name to the last component of the program name to be in line with
* err() and warn() function (and its derivatives).
*/
static void set_prog_name(char *s)
{
char *p = strrchr(s, '/');
if (p == NULL)
prog_name = s;
else
prog_name = p + 1;
}
int main(int argc, char *argv[])
{
volume_label_t vlabel;
@@ -1502,7 +1516,7 @@ int main(int argc, char *argv[])
signal(SIGQUIT, program_interrupt_signal);
/******************* initialization ********************/
prog_name = argv[0];
set_prog_name(argv[0]);
util_prg_init(&prg);
util_opt_init(opt_vec, NULL);