kwo pushed a commit to branch master.

http://git.enlightenment.org/legacy/imlib2.git/commit/?id=9afad50f970e46db1ed30599d06ad8b458910742

commit 9afad50f970e46db1ed30599d06ad8b458910742
Author: Kim Woelders <[email protected]>
Date:   Mon Jan 17 12:42:02 2022 +0100

    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;
 }
 

-- 


Reply via email to