[EGIT] [efl] 01/01: use eina_file_access() instead of access() if possible
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 49976ca388dfb66cce600e0b2169cae0c675f0e7 Author: Vincent Torri AuthorDate: Fri Mar 29 05:41:17 2024 +0100 use eina_file_access() instead of access() if possible --- src/lib/ecore_evas/ecore_evas_module.c | 11 +--- src/lib/ecore_file/ecore_file.c| 98 ++ src/lib/eet/eet_lib.c | 2 + src/lib/eeze/eeze_disk.c | 18 +++ src/lib/eeze/eeze_disk_libmount.c | 2 +- src/lib/eina/eina_prefix.c | 6 +-- src/lib/elementary/elm_main.c | 4 +- src/lib/ethumb/ethumb.c| 2 +- 8 files changed, 22 insertions(+), 121 deletions(-) diff --git a/src/lib/ecore_evas/ecore_evas_module.c b/src/lib/ecore_evas/ecore_evas_module.c index 4fdd8f70b0..0a4c6de997 100644 --- a/src/lib/ecore_evas/ecore_evas_module.c +++ b/src/lib/ecore_evas/ecore_evas_module.c @@ -22,15 +22,6 @@ static Eina_Module *_ecore_evas_vnc = NULL; # define ECORE_EVAS_ENGINE_NAME "module.so" #endif -static inline Eina_Bool -_file_exists(const char *file) -{ - if (!file) return EINA_FALSE; - - if (access(file, F_OK) == -1) return EINA_FALSE; - return EINA_TRUE; -} - static Eina_Module * _ecore_evas_vnc_server_module_try_load(const char *prefix, @@ -219,7 +210,7 @@ _ecore_evas_available_engines_get(void) eina_strbuf_append_printf(buf, "%s/%s/" ECORE_EVAS_ENGINE_NAME, info->path, MODULE_ARCH); - if (_file_exists(eina_strbuf_string_get(buf))) + if (eina_file_access(eina_strbuf_string_get(buf), EINA_FILE_ACCESS_MODE_EXIST)) { const char *name; diff --git a/src/lib/ecore_file/ecore_file.c b/src/lib/ecore_file/ecore_file.c index 66bdfe542e..a1a0a27874 100644 --- a/src/lib/ecore_file/ecore_file.c +++ b/src/lib/ecore_file/ecore_file.c @@ -606,111 +606,19 @@ ecore_file_dir_get(const char *file) EAPI Eina_Bool ecore_file_can_read(const char *file) { - if (!file) return EINA_FALSE; - if (!access(file, R_OK)) return EINA_TRUE; - return EINA_FALSE; + return eina_file_access(file, EINA_FILE_ACCESS_MODE_READ); } EAPI Eina_Bool ecore_file_can_write(const char *file) { - if (!file) return EINA_FALSE; - if (!access(file, W_OK)) return EINA_TRUE; - return EINA_FALSE; + return eina_file_access(file, EINA_FILE_ACCESS_MODE_WRITE); } EAPI Eina_Bool ecore_file_can_exec(const char *file) { -#ifdef _WIN32 - HANDLE h; - HANDLE fm; - char *base; - char *base_nt; - LARGE_INTEGER sz; - WORD characteristics; -#endif - - if (!file || !*file) return EINA_FALSE; - -#ifdef _WIN32 - /* -* we parse the file to check if it is a PE file (EXE or DLL) -* and we finally check whether it's a DLL or not. -* Reference : -* https://docs.microsoft.com/en-us/windows/win32/debug/pe-format -*/ - h = CreateFile(file, GENERIC_READ, FILE_SHARE_READ, NULL, - OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); - if (h == INVALID_HANDLE_VALUE) - goto test_bat; - - if (!GetFileSizeEx(h, )) - goto close_h; - - /* a PE file must have at least the DOS and NT headers */ - if (sz.QuadPart < (LONGLONG)(sizeof(IMAGE_DOS_HEADER) + sizeof(IMAGE_NT_HEADERS))) - goto close_h; - - fm = CreateFileMapping(h, NULL, PAGE_READONLY, 0, 0, NULL); - if (fm == NULL) - goto close_h; - - base = (char *)MapViewOfFile(fm, FILE_MAP_READ, 0, 0, 0); - CloseHandle(fm); - if (base == NULL) - goto close_h; - - /* -* the PE file begins with the DOS header. -* First magic number : the DOS header must begin with a DOS magic number, -* that is "MZ", that is 0x5a4d, stored in a WORD. -*/ - if (*((WORD *)base) != 0x5a4d) - goto unmap_view; - - /* -* The position of the NT header is located at the offset 0x3c. -*/ - base_nt = base + *((DWORD *)(base + 0x3c)); - /* -* The NT header begins with the magic number "PE\0\0", that is -* 0x4550, stored in a DWORD. -*/ - if (*((DWORD *)base_nt) != 0x4550) - goto unmap_view; - - /* -* to get informations about executable (EXE or DLL), we look at -* the 'Characteristics' member of the NT header, located at the offset -* 22 (4 for the magic number, 18 for the offset) from base_nt. -* https://docs.microsoft.com/en-us/windows/win32/debug/pe-format#characteristics -*/ - characteristics = *((WORD *)(base_nt + 4 + 18)); - - UnmapViewOfFile(base); - CloseHandle(h); - - /* -* 0x0002 : if set, EXE or DLL -* 0x2000 : if set, DLL -*/ - if ((characteristics & 0x0002) && !(characteristics & 0x2000)) - return EINA_TRUE; - unmap_view: - UnmapViewOfFile(base); - close_h: - CloseHandle(h); - test_bat: - /* -* a .bat file, considered as an executable, is only a text file, -* so we rely on
[EGIT] [efl] 01/01: use eina_file_access() instead of access() if possible
This is an automated email from the git hooks/post-receive script. git pushed a commit to branch vtorri_access in repository efl. View the commit online. commit 0ad2c7c8c6a8c24d64db439c7a09c570c3745d2c Author: Vincent Torri AuthorDate: Fri Mar 29 05:41:17 2024 +0100 use eina_file_access() instead of access() if possible --- src/lib/ecore_evas/ecore_evas_module.c | 11 +--- src/lib/ecore_file/ecore_file.c| 98 ++ src/lib/eet/eet_lib.c | 2 + src/lib/eeze/eeze_disk.c | 18 +++ src/lib/eeze/eeze_disk_libmount.c | 2 +- src/lib/eina/eina_prefix.c | 6 +-- src/lib/elementary/elm_main.c | 4 +- src/lib/ethumb/ethumb.c| 2 +- 8 files changed, 22 insertions(+), 121 deletions(-) diff --git a/src/lib/ecore_evas/ecore_evas_module.c b/src/lib/ecore_evas/ecore_evas_module.c index 4fdd8f70b0..0a4c6de997 100644 --- a/src/lib/ecore_evas/ecore_evas_module.c +++ b/src/lib/ecore_evas/ecore_evas_module.c @@ -22,15 +22,6 @@ static Eina_Module *_ecore_evas_vnc = NULL; # define ECORE_EVAS_ENGINE_NAME "module.so" #endif -static inline Eina_Bool -_file_exists(const char *file) -{ - if (!file) return EINA_FALSE; - - if (access(file, F_OK) == -1) return EINA_FALSE; - return EINA_TRUE; -} - static Eina_Module * _ecore_evas_vnc_server_module_try_load(const char *prefix, @@ -219,7 +210,7 @@ _ecore_evas_available_engines_get(void) eina_strbuf_append_printf(buf, "%s/%s/" ECORE_EVAS_ENGINE_NAME, info->path, MODULE_ARCH); - if (_file_exists(eina_strbuf_string_get(buf))) + if (eina_file_access(eina_strbuf_string_get(buf), EINA_FILE_ACCESS_MODE_EXIST)) { const char *name; diff --git a/src/lib/ecore_file/ecore_file.c b/src/lib/ecore_file/ecore_file.c index 66bdfe542e..a1a0a27874 100644 --- a/src/lib/ecore_file/ecore_file.c +++ b/src/lib/ecore_file/ecore_file.c @@ -606,111 +606,19 @@ ecore_file_dir_get(const char *file) EAPI Eina_Bool ecore_file_can_read(const char *file) { - if (!file) return EINA_FALSE; - if (!access(file, R_OK)) return EINA_TRUE; - return EINA_FALSE; + return eina_file_access(file, EINA_FILE_ACCESS_MODE_READ); } EAPI Eina_Bool ecore_file_can_write(const char *file) { - if (!file) return EINA_FALSE; - if (!access(file, W_OK)) return EINA_TRUE; - return EINA_FALSE; + return eina_file_access(file, EINA_FILE_ACCESS_MODE_WRITE); } EAPI Eina_Bool ecore_file_can_exec(const char *file) { -#ifdef _WIN32 - HANDLE h; - HANDLE fm; - char *base; - char *base_nt; - LARGE_INTEGER sz; - WORD characteristics; -#endif - - if (!file || !*file) return EINA_FALSE; - -#ifdef _WIN32 - /* -* we parse the file to check if it is a PE file (EXE or DLL) -* and we finally check whether it's a DLL or not. -* Reference : -* https://docs.microsoft.com/en-us/windows/win32/debug/pe-format -*/ - h = CreateFile(file, GENERIC_READ, FILE_SHARE_READ, NULL, - OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); - if (h == INVALID_HANDLE_VALUE) - goto test_bat; - - if (!GetFileSizeEx(h, )) - goto close_h; - - /* a PE file must have at least the DOS and NT headers */ - if (sz.QuadPart < (LONGLONG)(sizeof(IMAGE_DOS_HEADER) + sizeof(IMAGE_NT_HEADERS))) - goto close_h; - - fm = CreateFileMapping(h, NULL, PAGE_READONLY, 0, 0, NULL); - if (fm == NULL) - goto close_h; - - base = (char *)MapViewOfFile(fm, FILE_MAP_READ, 0, 0, 0); - CloseHandle(fm); - if (base == NULL) - goto close_h; - - /* -* the PE file begins with the DOS header. -* First magic number : the DOS header must begin with a DOS magic number, -* that is "MZ", that is 0x5a4d, stored in a WORD. -*/ - if (*((WORD *)base) != 0x5a4d) - goto unmap_view; - - /* -* The position of the NT header is located at the offset 0x3c. -*/ - base_nt = base + *((DWORD *)(base + 0x3c)); - /* -* The NT header begins with the magic number "PE\0\0", that is -* 0x4550, stored in a DWORD. -*/ - if (*((DWORD *)base_nt) != 0x4550) - goto unmap_view; - - /* -* to get informations about executable (EXE or DLL), we look at -* the 'Characteristics' member of the NT header, located at the offset -* 22 (4 for the magic number, 18 for the offset) from base_nt. -* https://docs.microsoft.com/en-us/windows/win32/debug/pe-format#characteristics -*/ - characteristics = *((WORD *)(base_nt + 4 + 18)); - - UnmapViewOfFile(base); - CloseHandle(h); - - /* -* 0x0002 : if set, EXE or DLL -* 0x2000 : if set, DLL -*/ - if ((characteristics & 0x0002) && !(characteristics & 0x2000)) - return EINA_TRUE; - unmap_view: - UnmapViewOfFile(base); - close_h: - CloseHandle(h); - test_bat: - /* -* a .bat file, considered as an executable, is only a text file, -* so we