forked from enlightenment/efl
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
This commit is contained in:
parent
173c9cdbe1
commit
b5b0222ae0
|
@ -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, '/')))
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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) \
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue