summaryrefslogtreecommitdiffstats
path: root/programs/lz4cli.c
diff options
context:
space:
mode:
authorYann Collet <Cyan4973@users.noreply.github.com>2017-03-25 03:42:27 (GMT)
committerGitHub <noreply@github.com>2017-03-25 03:42:27 (GMT)
commit84246b974e41740e0f20036f5ca06d9996a04291 (patch)
tree2358e5ba104a0d0194cb1a60c76b5d6906d889e3 /programs/lz4cli.c
parent4567d0def545fe0bd3141db294ba82040b9e419f (diff)
parente9c3b14f29486feee823f95b238fe0a83fb64670 (diff)
downloadlz4-84246b974e41740e0f20036f5ca06d9996a04291.zip
lz4-84246b974e41740e0f20036f5ca06d9996a04291.tar.gz
lz4-84246b974e41740e0f20036f5ca06d9996a04291.tar.bz2
Merge pull request #341 from iburinoc/exematch
Ignore extensions in exe name matching
Diffstat (limited to 'programs/lz4cli.c')
-rw-r--r--programs/lz4cli.c21
1 files changed, 15 insertions, 6 deletions
diff --git a/programs/lz4cli.c b/programs/lz4cli.c
index 7a75f55..329ca0b 100644
--- a/programs/lz4cli.c
+++ b/programs/lz4cli.c
@@ -242,10 +242,19 @@ static void waitEnter(void)
static const char* lastNameFromPath(const char* path)
{
- const char* name = strrchr(path, '/');
- if (name==NULL) name = strrchr(path, '\\'); /* windows */
- if (name==NULL) return path;
- return name+1;
+ const char* name = path;
+ if (strrchr(name, '/')) name = strrchr(name, '/') + 1;
+ if (strrchr(name, '\\')) name = strrchr(name, '\\') + 1; /* windows */
+ return name;
+}
+
+/*! exeNameMatch() :
+ @return : a non-zero value if exeName matches test, excluding the extension
+ */
+static int exeNameMatch(const char* exeName, const char* test)
+{
+ return !strncmp(exeName, test, strlen(test)) &&
+ (exeName[strlen(test)] == '\0' || exeName[strlen(test)] == '.');
}
/*! readU32FromChar() :
@@ -298,7 +307,7 @@ int main(int argc, const char** argv)
LZ4IO_setOverwrite(0);
/* lz4cat predefined behavior */
- if (!strcmp(exeName, LZ4CAT)) {
+ if (exeNameMatch(exeName, LZ4CAT)) {
mode = om_decompress;
LZ4IO_setOverwrite(1);
LZ4IO_setRemoveSrcFile(0);
@@ -307,7 +316,7 @@ int main(int argc, const char** argv)
displayLevel=1;
multiple_inputs=1;
}
- if (!strcmp(exeName, UNLZ4)) { mode = om_decompress; }
+ if (exeNameMatch(exeName, UNLZ4)) { mode = om_decompress; }
/* command switches */
for(i=1; i<argc; i++) {