Support both slash and backslash as path component
separator on Windows when parsing argv[0].
This commit is contained in:
parent
bc7c7109cc
commit
79e25eded4
|
@ -425,11 +425,20 @@ args_parse(args_info *args, int argc, char **argv)
|
||||||
// Check how we were called.
|
// Check how we were called.
|
||||||
{
|
{
|
||||||
// Remove the leading path name, if any.
|
// Remove the leading path name, if any.
|
||||||
|
#ifdef _WIN32
|
||||||
|
// Some systems support both / and \ to separate path
|
||||||
|
// components.
|
||||||
|
const char *name = argv[0] + strlen(argv[0]);
|
||||||
|
while (argv[0] < name && name[-1] != '/' && name[-1] != '\\')
|
||||||
|
--name;
|
||||||
|
#else
|
||||||
|
// POSIX
|
||||||
const char *name = strrchr(argv[0], '/');
|
const char *name = strrchr(argv[0], '/');
|
||||||
if (name == NULL)
|
if (name == NULL)
|
||||||
name = argv[0];
|
name = argv[0];
|
||||||
else
|
else
|
||||||
++name;
|
++name;
|
||||||
|
#endif
|
||||||
|
|
||||||
// NOTE: It's possible that name[0] is now '\0' if argv[0]
|
// NOTE: It's possible that name[0] is now '\0' if argv[0]
|
||||||
// is weird, but it doesn't matter here.
|
// is weird, but it doesn't matter here.
|
||||||
|
|
Loading…
Reference in New Issue