This is an automated email from the git hooks/post-receive script.

git pushed a commit to branch master
in repository efl.

View the commit online.

commit 8272318d71b9a1817e77c3317b48bcd84326be52
Author: Vincent Torri <vto...@outlook.fr>
AuthorDate: Tue Dec 5 11:36:07 2023 +0100

    Eina: introduce API eina_file_path_relative() to uniformize this check
---
 src/lib/efreet/efreet_desktop_command.c    |  2 +-
 src/lib/efreet/efreet_menu.c               |  2 +-
 src/lib/eina/eina_file.h                   | 13 +++++++++++++
 src/lib/eina/eina_file_common.h            | 12 ------------
 src/lib/eina/eina_file_posix.c             | 16 +++++++++-------
 src/lib/eina/eina_file_win32.c             | 29 +++++++++++++++++++++++------
 src/lib/eina/eina_prefix.c                 | 16 +++-------------
 src/lib/elementary/efl_ui_image.c          | 21 +--------------------
 src/lib/elementary/efl_ui_image_zoomable.c | 21 +--------------------
 src/lib/elementary/elm_icon.c              | 21 +--------------------
 src/lib/elementary/elm_main.c              |  2 +-
 src/lib/elementary/elm_module.c            |  2 +-
 src/lib/elementary/elm_prefs.c             |  8 ++------
 src/lib/elementary/elm_theme.c             | 11 +++++------
 src/lib/evas/canvas/evas_font_dir.c        | 19 ++-----------------
 src/lib/evas/file/evas_path.c              | 16 ----------------
 src/lib/evas/file/evas_path.h              |  1 -
 src/lib/evil/evil_util.c                   | 22 ----------------------
 src/lib/evil/evil_util.h                   | 23 -----------------------
 19 files changed, 64 insertions(+), 193 deletions(-)

diff --git a/src/lib/efreet/efreet_desktop_command.c b/src/lib/efreet/efreet_desktop_command.c
index 6c388caa3f..675ac6ddbd 100644
--- a/src/lib/efreet/efreet_desktop_command.c
+++ b/src/lib/efreet/efreet_desktop_command.c
@@ -833,7 +833,7 @@ efreet_desktop_command_path_absolute(const char *path)
     int len = 0;
 
     /* relative url */
-    if (path[0] != '/')
+    if (eina_file_path_relative(path))
     {
         if (!(buf = malloc(size))) return NULL;
         if (!getcwd(buf, size))
diff --git a/src/lib/efreet/efreet_menu.c b/src/lib/efreet/efreet_menu.c
index 890934fc22..ccaad79ac5 100644
--- a/src/lib/efreet/efreet_menu.c
+++ b/src/lib/efreet/efreet_menu.c
@@ -3125,7 +3125,7 @@ efreet_menu_path_get(Efreet_Menu_Internal *internal, const char *suffix)
     size_t len;
 
     /* see if we've got an absolute or relative path */
-    if (suffix[0] == '/')
+    if (!eina_file_path_relative(suffix))
         snprintf(path, sizeof(path), "%s", suffix);
 
     else
diff --git a/src/lib/eina/eina_file.h b/src/lib/eina/eina_file.h
index c7e5b2b590..b180bb6a1d 100644
--- a/src/lib/eina/eina_file.h
+++ b/src/lib/eina/eina_file.h
@@ -245,6 +245,19 @@ struct _Eina_File_Line
  */
 #define EINA_FILE_DIR_LIST_CB(function) ((Eina_File_Dir_List_Cb)function)
 
+/**
+ * @brief Determines if a path is relative or absolute.
+ *
+ * @param[in] path The path to check.
+ *
+ * @return #EINA_TRUE if the path is relative, #EINA_FALSE otherwise.
+ *
+ * The implementation simply checks if the first char in the path is
+ * '/' on POSIX systems. On Windows, absolute paths begin with '\' or
+ * 'C:\' (or other letter). If it is not, the path is considered relative.
+ * If @p path is @c NULL, this function returns #EINA_FALSE.
+ */
+EINA_API Eina_Bool eina_file_path_relative(const char *path);
 
 /**
  * @brief Lists all the files on the directory by calling the function for every file found.
diff --git a/src/lib/eina/eina_file_common.h b/src/lib/eina/eina_file_common.h
index 16fb772c4d..67cfff5d94 100644
--- a/src/lib/eina/eina_file_common.h
+++ b/src/lib/eina/eina_file_common.h
@@ -178,18 +178,6 @@ struct _Eina_Lines_Iterator
 /** Macro for logging Eina debug messages */
 #define DBG(...) EINA_LOG_DOM_DBG(_eina_file_log_dom, __VA_ARGS__)
 
-/**
- * @brief Determines if a path is relative or absolute.
- * The implementation simply checks if the first char in the path is '/'.  If it
- * is not, the path is considered relative.
- *
- * @param[in] path The path to check.
- *
- * @return EINA_TRUE if the path is relative, EINA_FALSE otherwise.
- *
- */
-Eina_Bool eina_file_path_relative(const char *path);
-
 /**
  * @brief Gets the current directory and optionally appends a path to it.
  * If a string was passed in via the @p path parameter, it will
diff --git a/src/lib/eina/eina_file_posix.c b/src/lib/eina/eina_file_posix.c
index c4fb462b5f..f612ad06e8 100644
--- a/src/lib/eina/eina_file_posix.c
+++ b/src/lib/eina/eina_file_posix.c
@@ -521,13 +521,6 @@ eina_file_mmap_faulty(void *addr, long page_size)
  *   Simplified logic for portability layer with eina_file_common   *
  * ================================================================ */
 
-Eina_Bool
-eina_file_path_relative(const char *path)
-{
-   if (*path != '/') return EINA_TRUE;
-   return EINA_FALSE;
-}
-
 Eina_Tmpstr *
 eina_file_current_directory_get(const char *path, size_t len)
 {
@@ -562,6 +555,15 @@ eina_file_cleanup(Eina_Tmpstr *path)
 
 
 
+EINA_API Eina_Bool
+eina_file_path_relative(const char *path)
+{
+   if (!path)
+     return EINA_FALSE;
+
+   return *path != '/';
+}
+
 EINA_API Eina_Bool
 eina_file_dir_list(const char *dir,
                    Eina_Bool recursive,
diff --git a/src/lib/eina/eina_file_win32.c b/src/lib/eina/eina_file_win32.c
index ddce2137ec..5f16788929 100644
--- a/src/lib/eina/eina_file_win32.c
+++ b/src/lib/eina/eina_file_win32.c
@@ -515,12 +515,6 @@ _eina_file_mkdtemp(char *__template)
  *   Simplified logic for portability layer with eina_file_common   *
  * ================================================================ */
 
-Eina_Bool
-eina_file_path_relative(const char *path)
-{
-   return !evil_path_is_absolute(path);
-}
-
 Eina_Tmpstr *
 eina_file_current_directory_get(const char *path, size_t len)
 {
@@ -559,6 +553,29 @@ eina_file_cleanup(Eina_Tmpstr *path)
  *                                   API                                      *
  *============================================================================*/
 
+EINA_API Eina_Bool
+eina_file_path_relative(const char *path)
+{
+   /* see
+    * https://learn.microsoft.com/en-us/windows/win32/fileio/naming-a-file#paths
+    * absolute path if:
+    * - is an UNC path (begins with \\)
+    * - has a drive letter (C:\). \ is important here, otherwise it is relative
+    * - begins with \
+    */
+
+   if (!path || *path == '\\')
+     return EINA_FALSE;
+
+   if ((((*path >= 'a') && (*path <= 'z')) ||
+        ((*path >= 'A') && (*path <= 'Z'))) &&
+       (path[1] == ':') &&
+       ((path[2] == '\\') || (path[2] == '/')))
+     return EINA_FALSE;
+
+   return EINA_TRUE;
+}
+
 EINA_API Eina_Bool
 eina_file_dir_list(const char *dir,
                    Eina_Bool recursive,
diff --git a/src/lib/eina/eina_prefix.c b/src/lib/eina/eina_prefix.c
index 1e7f5ddd80..89aa78ce9f 100644
--- a/src/lib/eina/eina_prefix.c
+++ b/src/lib/eina/eina_prefix.c
@@ -43,7 +43,7 @@
 
 #ifdef _WIN32
 # include <direct.h> /* getcwd */
-# include <evil_private.h> /* path_is_absolute realpath dladdr */
+# include <evil_private.h> /* realpath dladdr */
 #endif
 
 #include "eina_config.h"
@@ -166,16 +166,6 @@ _path_sep_fix(char *buf)
 #endif
 }
 
-static Eina_Bool
-_path_absolute_check(const char *path)
-{
-#ifdef _WIN32
-   return evil_path_is_absolute(path);
-#else
-   return (path[0] == EINA_PATH_SEP_C);
-#endif
-}
-
 static int
 _fallback(Eina_Prefix *pfx, const char *pkg_bin, const char *pkg_lib,
           const char *pkg_data, const char *pkg_locale, const char *envprefix)
@@ -284,7 +274,7 @@ _try_argv(Eina_Prefix *pfx, const char *argv0)
    char buf[PATH_MAX], buf2[PATH_MAX];
 
    /* 1. is argv0 abs path? */
-   if (_path_absolute_check(argv0))
+   if (!eina_file_path_relative(argv0))
      {
         if (access(argv0, X_OK) == 0)
           {
@@ -579,7 +569,7 @@ eina_prefix_new(const char *argv0, void *symbol, const char *envprefix,
           {
              if (info_dl.dli_fname)
                {
-                  if (_path_absolute_check(info_dl.dli_fname))
+                  if (!eina_file_path_relative(info_dl.dli_fname))
                     {
                        INF("dladdr for symbol=%p: %s", symbol, info_dl.dli_fname);
                        char *rlink = realpath(info_dl.dli_fname, NULL);
diff --git a/src/lib/elementary/efl_ui_image.c b/src/lib/elementary/efl_ui_image.c
index b584aa4a7d..2ee093c319 100644
--- a/src/lib/elementary/efl_ui_image.c
+++ b/src/lib/elementary/efl_ui_image.c
@@ -2164,25 +2164,6 @@ _icon_size_min_get(Evas_Object *image)
    return MAX(16, MIN(w, h));
 }
 
-/* FIXME: move this code to ecore */
-#ifdef _WIN32
-static Eina_Bool
-_path_is_absolute(const char *path)
-{
-   //TODO: Check if this works with all absolute paths in windows
-   return (isalpha(*path)) && (*(path + 1) == ':') &&
-           ((*(path + 2) == '\\') || (*(path + 2) == '/'));
-}
-
-#else
-static Eina_Bool
-_path_is_absolute(const char *path)
-{
-   return *path == '/';
-}
-
-#endif
-
 static Eina_Bool
 _internal_efl_ui_image_icon_set(Evas_Object *obj, const char *name, Eina_Bool *fdo)
 {
@@ -2217,7 +2198,7 @@ _internal_efl_ui_image_icon_set(Evas_Object *obj, const char *name, Eina_Bool *f
    else
      eina_stringshare_replace(&sd->stdicon, NULL);
 
-   if (_path_is_absolute(name))
+   if (!eina_file_path_relative(name))
      {
         if (fdo)
           *fdo = EINA_FALSE;
diff --git a/src/lib/elementary/efl_ui_image_zoomable.c b/src/lib/elementary/efl_ui_image_zoomable.c
index fb05a56115..fd8fc3f7b6 100644
--- a/src/lib/elementary/efl_ui_image_zoomable.c
+++ b/src/lib/elementary/efl_ui_image_zoomable.c
@@ -2903,25 +2903,6 @@ _icon_size_min_get(Evas_Object *image)
    return MAX(16, MIN(w, h));
 }
 
-/* FIXME: move this code to ecore */
-#ifdef _WIN32
-static Eina_Bool
-_path_is_absolute(const char *path)
-{
-   //TODO: Check if this works with all absolute paths in windows
-   return (isalpha(*path)) && (*(path + 1) == ':') &&
-           ((*(path + 2) == '\\') || (*(path + 2) == '/'));
-}
-
-#else
-static Eina_Bool
-_path_is_absolute(const char *path)
-{
-   return *path == '/';
-}
-
-#endif
-
 static Eina_Bool
 _internal_efl_ui_image_zoomable_icon_set(Evas_Object *obj, const char *name, Eina_Bool *fdo, Eina_Bool resize)
 {
@@ -2956,7 +2937,7 @@ _internal_efl_ui_image_zoomable_icon_set(Evas_Object *obj, const char *name, Ein
     else
       eina_stringshare_replace(&sd->stdicon, NULL);
 
-   if (_path_is_absolute(name))
+   if (!eina_file_path_relative(name))
      {
         if (fdo)
           *fdo = EINA_FALSE;
diff --git a/src/lib/elementary/elm_icon.c b/src/lib/elementary/elm_icon.c
index 5894c9bb79..689f3fc95f 100644
--- a/src/lib/elementary/elm_icon.c
+++ b/src/lib/elementary/elm_icon.c
@@ -28,25 +28,6 @@ static const Evas_Smart_Cb_Description _smart_callbacks[] = {
    {NULL, NULL}
 };
 
-/* FIXME: move this code to ecore */
-#ifdef _WIN32
-static Eina_Bool
-_path_is_absolute(const char *path)
-{
-   //TODO: Check if this works with all absolute paths in windows
-   return (isalpha(*path)) && (*(path + 1) == ':') &&
-          ((*(path + 2) == '\\') || (*(path + 2) == '/'));
-}
-
-#else
-static Eina_Bool
-_path_is_absolute(const char *path)
-{
-   return *path == '/';
-}
-
-#endif
-
 static inline int
 _icon_size_min_get(Evas_Object *icon)
 {
@@ -462,7 +443,7 @@ _internal_elm_icon_standard_set(Evas_Object *obj,
         return EINA_TRUE;
      }
 
-   if (_path_is_absolute(name))
+   if (!eina_file_path_relative(name))
      {
         if (fdo)
           *fdo = EINA_FALSE;
diff --git a/src/lib/elementary/elm_main.c b/src/lib/elementary/elm_main.c
index 325726abfd..0fed8c28fe 100644
--- a/src/lib/elementary/elm_main.c
+++ b/src/lib/elementary/elm_main.c
@@ -1308,7 +1308,7 @@ elm_quicklaunch_exe_path_get(const char *exe, const char *cwd)
    const char *pathitr;
    const Eina_List *l;
    char buf[PATH_MAX];
-   if (exe[0] == '/') return strdup(exe);
+   if (!eina_file_path_relative(exe)) return strdup(exe);
    if (cwd)
      pathlist = eina_list_append(pathlist, eina_stringshare_add(cwd));
    else
diff --git a/src/lib/elementary/elm_module.c b/src/lib/elementary/elm_module.c
index 2d38327c7c..91ab09d125 100644
--- a/src/lib/elementary/elm_module.c
+++ b/src/lib/elementary/elm_module.c
@@ -203,7 +203,7 @@ _elm_module_add(const char *name, const char *as)
 {
    Elm_Module *m;
 
-   if (name[0] == '/') return NULL;
+   if (!eina_file_path_relative(name)) return NULL;
 
    m = eina_hash_find(modules, name);
    if (m)
diff --git a/src/lib/elementary/elm_prefs.c b/src/lib/elementary/elm_prefs.c
index e1b1074d19..2fa62a8ed3 100644
--- a/src/lib/elementary/elm_prefs.c
+++ b/src/lib/elementary/elm_prefs.c
@@ -3,7 +3,7 @@
 #endif
 
 #ifdef _WIN32
-# include <evil_private.h> /* strsep evil_path_absolute */
+# include <evil_private.h> /* strsep */
 #endif
 
 #define EFL_ACCESS_OBJECT_PROTECTED
@@ -1816,11 +1816,7 @@ elm_prefs_file_set(Eo *obj, const char *file, const char *page)
      sd->file = eina_stringshare_printf("%s/%s", prefix, "preferences.epb");
    else
      {
-#ifndef _WIN32
-        if (*file != '/') /* relative */
-#else
-        if (!evil_path_is_absolute(file)) /* relative */
-#endif
+        if (eina_file_path_relative(file))
           sd->file = eina_stringshare_printf("%s/%s", prefix, file);
         else
           sd->file = eina_stringshare_add(file);
diff --git a/src/lib/elementary/elm_theme.c b/src/lib/elementary/elm_theme.c
index 123bc0f14e..ea69b7978e 100644
--- a/src/lib/elementary/elm_theme.c
+++ b/src/lib/elementary/elm_theme.c
@@ -107,10 +107,9 @@ _elm_theme_file_item_add(Eina_Inlist **files, const char *item, Eina_Bool prepen
    home = eina_environment_home_get();
    buf = eina_strbuf_new();
 
-   if ((item[0] == '/') ||
+   if (!eina_file_path_relative(item) ||
        ((item[0] == '.') && (item[1] == '/')) ||
-       ((item[0] == '.') && (item[1] == '.') && (item[2] == '/')) ||
-       ((isalpha(item[0])) && (item[1] == ':')))
+       ((item[0] == '.') && (item[1] == '.') && (item[2] == '/')))
      {
         f = eina_file_open(item, EINA_FALSE);
         if (!f) goto on_error;
@@ -898,9 +897,9 @@ elm_theme_list_item_path_get(const char *f, Eina_Bool *in_search_path)
         if (!home) home = "";
      }
 
-   if ((f[0] == '/') || ((f[0] == '.') && (f[1] == '/')) ||
-       ((f[0] == '.') && (f[1] == '.') && (f[2] == '/')) ||
-       ((isalpha(f[0])) && (f[1] == ':')))
+   if (!eina_file_path_relative(f) ||
+       ((f[0] == '.') && (f[1] == '/')) ||
+       ((f[0] == '.') && (f[1] == '.') && (f[2] == '/')))
      {
         if (in_search_path) *in_search_path = EINA_FALSE;
         return strdup(f);
diff --git a/src/lib/evas/canvas/evas_font_dir.c b/src/lib/evas/canvas/evas_font_dir.c
index fa6c9591a9..83c04b0fe8 100644
--- a/src/lib/evas/canvas/evas_font_dir.c
+++ b/src/lib/evas/canvas/evas_font_dir.c
@@ -2,10 +2,6 @@
 # include <config.h>
 #endif
 
-#ifdef _WIN32
-# include <evil_private.h> /* evil_path_is_absolute */
-#endif
-
 #include <Eet.h>
 
 #ifdef HAVE_FONTCONFIG
@@ -67,17 +63,6 @@ static FcConfig *fc_config = NULL;
 /* get the casefold feature! */
 #include <unistd.h>
 #include <sys/param.h>
-int
-_file_path_is_full_path(const char *path)
-{
-   if (!path) return 0;
-#ifdef _WIN32
-   if (evil_path_is_absolute(path)) return 1;
-#else
-   if (path[0] == '/') return 1;
-#endif
-   return 0;
-}
 
 static DATA64
 _file_modified_time(const char *file)
@@ -787,7 +772,7 @@ evas_font_load(const Eina_List *font_paths, int hinting, Evas_Font_Description *
                }
              if (!font) /* Source load failed */
                {
-                  if (_file_path_is_full_path((char *)nm)) /* Try filename */
+                  if (!eina_file_path_relative((char *)nm)) /* Try filename */
                     font = (Evas_Font_Set *)evas_common_font_load((char *)nm, size, wanted_rend, bitmap_scalable);
                   else /* search font path */
                     {
@@ -856,7 +841,7 @@ evas_font_load(const Eina_List *font_paths, int hinting, Evas_Font_Description *
                }
              if (!ok)
                {
-                  if (_file_path_is_full_path((char *)nm))
+                  if (!eina_file_path_relative((char *)nm))
                     evas_common_font_add((RGBA_Font *)font, (char *)nm, size, wanted_rend, bitmap_scalable);
                   else
                     {
diff --git a/src/lib/evas/file/evas_path.c b/src/lib/evas/file/evas_path.c
index 68570a1c8d..439ba971fd 100644
--- a/src/lib/evas/file/evas_path.c
+++ b/src/lib/evas/file/evas_path.c
@@ -15,10 +15,6 @@
 #include <unistd.h>
 #include <sys/param.h>
 
-#ifdef _WIN32
-# include <evil_private.h> /* evil_path_is_absolute */
-#endif
-
 #include "evas_common_private.h"
 #include "evas_private.h"
 
@@ -28,18 +24,6 @@
 # define EVAS_PATH_SEPARATOR "/"
 #endif
 
-int
-evas_file_path_is_full_path(const char *path)
-{
-   if (!path) return 0;
-#ifdef _WIN32
-   if (evil_path_is_absolute(path)) return 1;
-#else
-   if (path[0] == '/') return 1;
-#endif
-   return 0;
-}
-
 char *
 evas_file_path_join(const char *path, const char *end)
 {
diff --git a/src/lib/evas/file/evas_path.h b/src/lib/evas/file/evas_path.h
index e0aa6bb4d0..05cea45540 100644
--- a/src/lib/evas/file/evas_path.h
+++ b/src/lib/evas/file/evas_path.h
@@ -2,7 +2,6 @@
 #define _EVAS_PATH_H
 
 
-int        evas_file_path_is_full_path (const char *path);
 char      *evas_file_path_join         (const char *path, const char *end);
 int        evas_file_path_exists       (const char *path);
 int        evas_file_path_is_file      (const char *path);
diff --git a/src/lib/evil/evil_util.c b/src/lib/evil/evil_util.c
index 2223a27cc1..42ade75503 100644
--- a/src/lib/evil/evil_util.c
+++ b/src/lib/evil/evil_util.c
@@ -188,25 +188,3 @@ _evil_last_error_display(const char *fct)
 {
    fprintf(stderr, "[Evil] [%s] ERROR: %s\n", fct, evil_last_error_get());
 }
-
-EVIL_API int
-evil_path_is_absolute(const char *path)
-{
-   size_t length;
-
-   if (!path)
-     return 0;
-
-   if (*path == '/' || *path == '\\') return 1;
-
-   length = strlen(path);
-   if (length < 3) return 0;
-
-   if ((((*path >= 'a') && (*path <= 'z')) ||
-        ((*path >= 'A') && (*path <= 'Z'))) &&
-       (path[1] == ':') &&
-       ((path[2] == '/') || (path[2] == '\\')))
-     return 1;
-
-   return 0;
-}
diff --git a/src/lib/evil/evil_util.h b/src/lib/evil/evil_util.h
index 4d7db43b3f..261718dd4d 100644
--- a/src/lib/evil/evil_util.h
+++ b/src/lib/evil/evil_util.h
@@ -81,27 +81,4 @@ EVIL_API const char *evil_format_message(long err);
 
 EVIL_API const char *evil_last_error_get(void);
 
-/**
- * @brief check if the given path is absolute.
- *
- * @param path The path to check.
- * @return 1 if the given path is absolute, 0 otherwise.
- *
- * Check if the path @p path is absolute or not. An absolute path must
- * begin with a letter (upper or lower case), followed by by the char
- * ':', followed by the char '/' or '\'. If @p path is absolute this
- * function returns 1, otherwise it returns 0. If @p path is @c NULL,
- * it returns 0.
- *
- * Conformity: Non applicable.
- *
- * Supported OS: Windows 95, Windows 98, Windows Me, Windows NT, Windows 2000,
- * Windows XP.
- *
- * @since 1.7
- *
- * @ingroup Evil
- */
-EVIL_API int evil_path_is_absolute(const char *path);
-
 #endif /* __EVIL_UTIL_H__ */

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.

Reply via email to