From 9afad50f970e46db1ed30599d06ad8b458910742 Mon Sep 17 00:00:00 2001 From: Kim Woelders Date: Mon, 17 Jan 2022 12:42:02 +0100 Subject: Simplify __imlib_FileKey() And avoid malloc when not needed. --- src/lib/file.c | 43 +++++++++++++------------------------------ 1 file changed, 13 insertions(+), 30 deletions(-) diff --git a/src/lib/file.c b/src/lib/file.c index d5a5242..d8e4d64 100644 --- a/src/lib/file.c +++ b/src/lib/file.c @@ -29,38 +29,21 @@ __imlib_IsRealFile(const char *s) char * __imlib_FileKey(const char *file) { - char *newfile; + const char *p; - newfile = malloc(strlen(file) + 1); - if (!newfile) - return NULL; - newfile[0] = 0; - { - char *p1, *p2; - int go; + for (p = file;;) + { + p = strchr(p, ':'); + if (!p) + break; + p++; + if (*p == '\0') + break; + if (*p != ':') /* :: Drive spec? */ + return strdup(p); + p++; + } - go = 0; - p1 = (char *)file; - p2 = newfile; - while (p1[0]) - { - if (go) - { - p2[0] = p1[0]; - p2++; - } - if ((p1[0] == ':') && (p1[1] != ':')) - go = 1; - if ((p1[0] == ':') && (p1[1] == ':')) - p1++; - p1++; - } - p2[0] = p1[0]; - } - if (newfile[0]) - return newfile; - else - free(newfile); return NULL; } -- cgit v1.2.1