summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKim Woelders <kim@woelders.dk>2022-01-17 12:42:02 +0100
committerKim Woelders <kim@woelders.dk>2022-01-17 13:06:22 +0100
commit9afad50f970e46db1ed30599d06ad8b458910742 (patch)
treeb0d85d423643b0d7a77b9228f0dde4235b223e05
parent64c031acab05b8513cae7e8e2ed2c1a7cd939ae6 (diff)
downloadimlib2-9afad50f970e46db1ed30599d06ad8b458910742.tar.gz
Simplify __imlib_FileKey()
And avoid malloc when not needed.
-rw-r--r--src/lib/file.c43
1 files 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;
}