liblzma: CRC CLMUL: Omit is_arch_extension_supported() when not needed
[xz/debian.git] / src / common / tuklib_progname.c
blob959c1270ce3292c814761c08448f3ea17d1e975e
1 // SPDX-License-Identifier: 0BSD
3 ///////////////////////////////////////////////////////////////////////////////
4 //
5 /// \file tuklib_progname.c
6 /// \brief Program name to be displayed in messages
7 //
8 // Author: Lasse Collin
9 //
10 ///////////////////////////////////////////////////////////////////////////////
12 #include "tuklib_progname.h"
13 #include <string.h>
16 #ifndef HAVE_PROGRAM_INVOCATION_NAME
17 char *progname = NULL;
18 #endif
21 extern void
22 tuklib_progname_init(char **argv)
24 #ifdef TUKLIB_DOSLIKE
25 // On these systems, argv[0] always has the full path and .exe
26 // suffix even if the user just types the plain program name.
27 // We modify argv[0] to make it nicer to read.
29 // Strip the leading path.
30 char *p = argv[0] + strlen(argv[0]);
31 while (argv[0] < p && p[-1] != '/' && p[-1] != '\\')
32 --p;
34 argv[0] = p;
36 // Strip the .exe suffix.
37 p = strrchr(p, '.');
38 if (p != NULL)
39 *p = '\0';
41 // Make it lowercase.
42 for (p = argv[0]; *p != '\0'; ++p)
43 if (*p >= 'A' && *p <= 'Z')
44 *p = *p - 'A' + 'a';
45 #endif
47 progname = argv[0];
48 return;