Skip to content

Commit 423b2f1

Browse files
Replace ends_with_case_insensitive with prefix_stricmp (closes #212)
1 parent b2aceed commit 423b2f1

3 files changed

Lines changed: 11 additions & 11 deletions

File tree

src/common.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,6 @@
2121
#define prefix_stricmp strcasecmp
2222
#endif
2323

24-
static inline int ends_with_case_insensitive(const char *s, const char *suffix) {
25-
if (!s || !suffix)
26-
return 0;
27-
size_t ls = strlen(s), lf = strlen(suffix);
28-
return lf <= ls && prefix_stricmp(s + (ls - lf), suffix) == 0;
29-
}
30-
3124
static inline char *prefix_fullpath_dup(const char *path) {
3225
if (!path || path[0] == '\0') {
3326
return NULL;

src/extensions.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,13 @@ static const char *platform_dynlib_suffix(void) {
129129
}
130130

131131
static int has_dynlib_suffix(const char *path) {
132-
return ends_with_case_insensitive(path, ".dll") || ends_with_case_insensitive(path, ".so") ||
133-
ends_with_case_insensitive(path, ".dylib");
132+
if (!path) {
133+
return 0;
134+
}
135+
size_t plen = strlen(path);
136+
return (plen >= 4 && prefix_stricmp(path + plen - 4, ".dll") == 0) ||
137+
(plen >= 3 && prefix_stricmp(path + plen - 3, ".so") == 0) ||
138+
(plen >= 6 && prefix_stricmp(path + plen - 6, ".dylib") == 0);
134139
}
135140

136141
static char *path_join2(const char *a, const char *b) {

src/main.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@ static int is_extension_arg(const char *arg) {
1919
if (!arg) {
2020
return 0;
2121
}
22-
return ends_with_case_insensitive(arg, ".dll") || ends_with_case_insensitive(arg, ".so") ||
23-
ends_with_case_insensitive(arg, ".dylib");
22+
size_t alen = strlen(arg);
23+
return (alen >= 4 && prefix_stricmp(arg + alen - 4, ".dll") == 0) ||
24+
(alen >= 3 && prefix_stricmp(arg + alen - 3, ".so") == 0) ||
25+
(alen >= 6 && prefix_stricmp(arg + alen - 6, ".dylib") == 0);
2426
}
2527

2628
static char *path_dirname_dup(const char *path) {

0 commit comments

Comments
 (0)