raster pushed a commit to branch master.

http://git.enlightenment.org/core/efl.git/commit/?id=b5b0222ae0569526f96af1876dd162efcb4ca937

commit b5b0222ae0569526f96af1876dd162efcb4ca937
Author: Vincent Torri <[email protected]>
Date:   Wed Nov 10 12:51:23 2021 +0000

    Eina: sanitize eina_path output on Windows
    
    Summary:
     * remove additional \ character
     * use only / as path separator
    
    Test Plan:
    compilation and run
    
    test program :
    
    ```
    {
            elm_app_bin_dir_get();
            printf("%s\n", eina_vpath_resolve("(:tmp:)/foo"));
            printf("%s\n", eina_vpath_resolve("(:home:)/foo"));
            printf("%s\n", eina_vpath_resolve("(:usr.desktop:)/foo"));
            printf("%s\n", eina_vpath_resolve("(:usr.documents:)/foo"));
            printf("%s\n", eina_vpath_resolve("(:usr.downloads:)/foo"));
            printf("%s\n", eina_vpath_resolve("(:usr.music:)/foo"));
            printf("%s\n", eina_vpath_resolve("(:usr.pictures:)/foo"));
            printf("%s\n", eina_vpath_resolve("(:usr.public:)/foo"));
            printf("%s\n", eina_vpath_resolve("(:usr.templates:)/foo"));
            printf("%s\n", eina_vpath_resolve("(:usr.videos:)/foo"));
            printf("%s\n", eina_vpath_resolve("(:usr.data:)/foo"));
            printf("%s\n", eina_vpath_resolve("(:usr.config:)/foo"));
            printf("%s\n", eina_vpath_resolve("(:usr.cache:)/foo"));
            printf("%s\n", eina_vpath_resolve("(:usr.run:)/foo"));
            printf("%s\n", eina_vpath_resolve("(:usr.tmp:)/foo"));
            printf("%s\n", eina_vpath_resolve("(:app.dir:)/foo"));
            printf("%s\n", eina_vpath_resolve("(:app.bin:)/foo"));
            printf("%s\n", eina_vpath_resolve("(:app.lib:)/foo"));
            printf("%s\n", eina_vpath_resolve("(:app.data:)/foo"));
            printf("%s\n", eina_vpath_resolve("(:app.locale:)/foo"));
            printf("%s\n", eina_vpath_resolve("(:app.config:)/foo"));
            printf("%s\n", eina_vpath_resolve("(:app.local:)/foo"));
            printf("%s\n", eina_vpath_resolve("(:app.tmp:)/foo"));
        }
    ```
    
    before patch :
    
    ```
    C:\Documents\msys2\tmp/foo
    C:\Users\vincent.torri/foo
    C:\Users\vincent.torri\Desktop/foo
    C:\Users\vincent.torri\Documents/foo
    C:\Users\vincent.torri\Downloads/foo
    C:\Users\vincent.torri\Music/foo
    C:\Users\vincent.torri\Pictures/foo
    C:\Users\Public\/foo
    C:\Users\vincent.torri\AppData\Roaming\Microsoft\Windows\Templates/foo
    C:\Users\vincent.torri\Videos/foo
    C:\Users\vincent.torri\AppData\Local\/foo
    C:\Users\vincent.torri\AppData\Roaming\/foo
    C:\Users\vincent.torri\AppData\Local\/foo
    C:\Users\vincent.torri\AppData\Roaming/foo
    C:\Users\vincent.torri\AppData\Local\Temp/foo
    C:/Documents/msys2/opt/entice_64/bin/foo
    C:/Documents/msys2/opt/entice_64/bin/foo
    C:/Documents/msys2/opt/entice_64/lib/foo
    C:/Documents/msys2/opt/entice_64/share/foo
    C:/Documents/msys2/opt/entice_64/share/foo
    C:\Users\vincent.torri\AppData\Roaming\/entice/foo
    C:\Users\vincent.torri\AppData\Local\/entice/foo
    C:\Users\vincent.torri\AppData\Local\Temp/entice/foo
    ```
    
    after patch
    
    ```
    C:/Documents/msys2/tmp/foo
    C:/Users/vincent.torri/foo
    C:/Users/vincent.torri/Desktop/foo
    C:/Users/vincent.torri/Documents/foo
    C:/Users/vincent.torri/Downloads/foo
    C:/Users/vincent.torri/Music/foo
    C:/Users/vincent.torri/Pictures/foo
    C:/Users/Public/foo
    C:/Users/vincent.torri/AppData/Roaming/Microsoft/Windows/Templates/foo
    C:/Users/vincent.torri/Videos/foo
    C:/Users/vincent.torri/AppData/Local/foo
    C:/Users/vincent.torri/AppData/Roaming/foo
    C:/Users/vincent.torri/AppData/Local/foo
    C:/Users/vincent.torri/AppData/Roaming/foo
    C:/Users/vincent.torri/AppData/Local/Temp/foo
    C:/Documents/msys2/opt/entice_64/bin/foo
    C:/Documents/msys2/opt/entice_64/bin/foo
    C:/Documents/msys2/opt/entice_64/lib/foo
    C:/Documents/msys2/opt/entice_64/share/foo
    C:/Documents/msys2/opt/entice_64/share/foo
    C:/Users/vincent.torri/AppData/Roaming/entice/foo
    C:/Users/vincent.torri/AppData/Local/entice/foo
    C:/Users/vincent.torri/AppData/Local/Temp/entice/foo
    ```
    
    Reviewers: raster
    
    Reviewed By: raster
    
    Subscribers: cedric, #reviewers, #committers
    
    Tags: #efl
    
    Differential Revision: https://phab.enlightenment.org/D12306
---
 src/lib/eina/eina_file_common.c |  2 +-
 src/lib/eina/eina_file_win32.c  |  2 +-
 src/lib/eina/eina_private.h     | 17 +++++++++++++++++
 src/lib/eina/eina_util.c        |  6 ++++++
 src/lib/eina/eina_vpath_xdg.c   |  9 +++++++--
 src/lib/evil/evil_stdio.h       | 15 ---------------
 6 files changed, 32 insertions(+), 19 deletions(-)

diff --git a/src/lib/eina/eina_file_common.c b/src/lib/eina/eina_file_common.c
index d93d2ef7b7..9e7cd081d3 100644
--- a/src/lib/eina/eina_file_common.c
+++ b/src/lib/eina/eina_file_common.c
@@ -126,7 +126,7 @@ _eina_file_escape(char *path, size_t len)
      return NULL;
 
 #ifdef _WIN32
-   EVIL_PATH_SEP_WIN32_TO_UNIX(path);
+   EINA_PATH_TO_UNIX(path);
 #endif
 
    while ((p = strchr(p, '/')))
diff --git a/src/lib/eina/eina_file_win32.c b/src/lib/eina/eina_file_win32.c
index 455d583b96..ddce2137ec 100644
--- a/src/lib/eina/eina_file_win32.c
+++ b/src/lib/eina/eina_file_win32.c
@@ -550,7 +550,7 @@ eina_file_cleanup(Eina_Tmpstr *path)
    if (!result)
      return NULL;
 
-   EVIL_PATH_SEP_WIN32_TO_UNIX(result);
+   EINA_PATH_TO_UNIX(result);
 
    return result;
 }
diff --git a/src/lib/eina/eina_private.h b/src/lib/eina/eina_private.h
index 9d4da033ce..0de9dd8f81 100644
--- a/src/lib/eina/eina_private.h
+++ b/src/lib/eina/eina_private.h
@@ -35,6 +35,23 @@
 #include "eina_accessor.h"
 #include "eina_stringshare.h"
 
+#ifdef _WIN32
+
+# define EINA_PATH_SEP_SWAP(p, s1, s2) \
+   do { \
+     char *iter = p; \
+     while (*iter) \
+       { \
+          if (*iter == s1) \
+            *iter = s2; \
+          iter++; \
+       } \
+   } while (0)
+
+# define EINA_PATH_TO_UNIX(p) EINA_PATH_SEP_SWAP(p, '\\', '/')
+# define EINA_PATH_TO_WIN32(p) EINA_PATH_SEP_SWAP(p, '/', '\\')
+#endif
+
 #ifndef ABS
 # define ABS(x) ((x) < 0 ? -(x) : (x))
 #endif
diff --git a/src/lib/eina/eina_util.c b/src/lib/eina/eina_util.c
index a003eb8fdb..036b85a382 100644
--- a/src/lib/eina/eina_util.c
+++ b/src/lib/eina/eina_util.c
@@ -91,6 +91,9 @@ eina_environment_home_get(void)
      }
 #endif
    home = strdup(home);
+#ifdef _WIN32
+   EINA_PATH_TO_UNIX(home);
+#endif
    return home;
 }
 
@@ -130,5 +133,8 @@ eina_environment_tmp_get(void)
 #endif
 
    tmp = strdup(tmp);
+#ifdef _WIN32
+   EINA_PATH_TO_UNIX(tmp);
+#endif
    return tmp;
 }
diff --git a/src/lib/eina/eina_vpath_xdg.c b/src/lib/eina/eina_vpath_xdg.c
index d300a8da1f..f9cecc5b1f 100644
--- a/src/lib/eina/eina_vpath_xdg.c
+++ b/src/lib/eina/eina_vpath_xdg.c
@@ -42,6 +42,7 @@ eina_xdg_env_init(void)
       if (!s) s = home; \
    } else s = home; \
    FATAL_SNPRINTF(_meta, "vpath string '%s' truncated - fatal", "%s\\%s", s, 
(char *)_dir); \
+   EINA_PATH_TO_UNIX(_meta); \
    (&user)->_meta = _meta;
 
 # define ENV_SET(_env, _meta) \
@@ -50,7 +51,8 @@ eina_xdg_env_init(void)
       s = getenv(_env); \
       if (!s) s = home; \
    } else s = home; \
-   FATAL_SNPRINTF(_meta, "vpath string '%s' truncated - fatal", "%s\\", s); \
+   FATAL_SNPRINTF(_meta, "vpath string '%s' truncated - fatal", "%s", s); \
+   EINA_PATH_TO_UNIX(_meta); \
    (&user)->_meta = _meta;
 
    ENV_DIR_SET(NULL, "Desktop", desktop);
@@ -68,7 +70,10 @@ eina_xdg_env_init(void)
    if (!(s = getenv("APPDATA")))
      user.run = NULL;
    else
-     user.run = s;
+     {
+        EINA_PATH_TO_UNIX(s);
+        user.run = s;
+     }
 #else /* _WIN32 */
 # if defined(HAVE_GETUID) && defined(HAVE_GETEUID)
 #  define ENV_HOME_SET(_env, _dir, _meta) \
diff --git a/src/lib/evil/evil_stdio.h b/src/lib/evil/evil_stdio.h
index 4a2ed57fd3..f948c674a6 100644
--- a/src/lib/evil/evil_stdio.h
+++ b/src/lib/evil/evil_stdio.h
@@ -12,21 +12,6 @@
  * @{
  */
 
-#define EVIL_PATH_SEP_SWAP(p, s1, s2) \
-   do { \
-     char *_evil_path_tmp; \
-     _evil_path_tmp = p; \
-     while (*_evil_path_tmp) \
-       { \
-          if (*_evil_path_tmp == s1) \
-            *_evil_path_tmp = s2; \
-          _evil_path_tmp++; \
-       } \
-   } while (0)
-
-#define EVIL_PATH_SEP_WIN32_TO_UNIX(p) EVIL_PATH_SEP_SWAP(p, '\\', '/')
-#define EVIL_PATH_SEP_UNIX_TO_WIN32(p) EVIL_PATH_SEP_SWAP(p, '/', '\\')
-
 
 /**
  * @brief Emulate the rename() function on Windows.

-- 


Reply via email to