aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLasse Collin <lasse.collin@tukaani.org>2009-02-08 10:37:50 +0200
committerLasse Collin <lasse.collin@tukaani.org>2009-02-08 10:37:50 +0200
commit79e25eded48d2fe33f31441ab7a034f902e335f8 (patch)
tree722ed10f7f9716e68c2fbdd57c85b7547b94c4bf
parentOmit the wrong and (even if corrected) nowadays useless rm (diff)
downloadxz-79e25eded48d2fe33f31441ab7a034f902e335f8.tar.xz
Support both slash and backslash as path component
separator on Windows when parsing argv[0].
-rw-r--r--src/xz/args.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/xz/args.c b/src/xz/args.c
index c9d1dc14..93cd220a 100644
--- a/src/xz/args.c
+++ b/src/xz/args.c
@@ -425,11 +425,20 @@ args_parse(args_info *args, int argc, char **argv)
// Check how we were called.
{
// 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], '/');
if (name == NULL)
name = argv[0];
else
++name;
+#endif
// NOTE: It's possible that name[0] is now '\0' if argv[0]
// is weird, but it doesn't matter here.