From fe4ab56c69b8d36e3fc3c31a6a9527b439e976d9 Mon Sep 17 00:00:00 2001 From: Ricardo Campos Date: Thu, 26 Mar 2020 11:11:51 -0300 Subject: [PATCH 01/11] Windows:sys/stat.h:changes for tests Windows compatibility --- src/lib/evil/evil_stat.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/lib/evil/evil_stat.h b/src/lib/evil/evil_stat.h index f06b94dd3f..2efa978b1b 100644 --- a/src/lib/evil/evil_stat.h +++ b/src/lib/evil/evil_stat.h @@ -20,3 +20,7 @@ #endif #endif + +#include +#include +#include_next From a50025d57930bc43563d088a98dbc4b53f9ced08 Mon Sep 17 00:00:00 2001 From: Ricardo Campos Date: Tue, 19 May 2020 13:47:44 -0300 Subject: [PATCH 02/11] Include chmod and umask --- src/lib/evil/evil_stat.h | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/src/lib/evil/evil_stat.h b/src/lib/evil/evil_stat.h index 2efa978b1b..a063f8ec9c 100644 --- a/src/lib/evil/evil_stat.h +++ b/src/lib/evil/evil_stat.h @@ -1,6 +1,22 @@ #ifndef __EVIL_STAT_H__ #define __EVIL_STAT_H__ +#include +#include <../ucrt/sys/types.h> +#include +#include +#include_next +#include +#include +#include +// loading as functions: chmod and umask (for umask, it is necessary to include: errno.h) +// fstat ja incluido em +#include + +#ifndef stat64 +# define stat64 _stat64 +#endif + // Missing definitions: // Note: some pieces of code were based on LibreSSL-Portable's compat lib and // adapted to EFL standards. @@ -21,6 +37,21 @@ #endif -#include -#include -#include_next + + +/* + +// ------------------------------------------------------------------------ + +// Sinalizadores de tipo de arquivo para d_type // ver a questão de st_mode + +#define DT_UNKNOWN 0 +#define DT_REG S_IFREG +#define DT_DIR S_IFDIR +#define DT_FIFO S_IFIFO +#define DT_SOCK S_IFSOCK //ver +#define DT_CHR S_IFCHR +#define DT_BLK S_IFBLK //ver +#define DT_LNK S_IFLNK //ver + +*/ \ No newline at end of file From cfe5040cff93e81797a3ad3d6a726f723ba59d45 Mon Sep 17 00:00:00 2001 From: Ricardo Campos Date: Thu, 7 May 2020 10:59:16 -0300 Subject: [PATCH 03/11] implementation of the fstatat () function --- src/lib/evil/evil_stat.h | 36 +++++------ src/lib/evil/stat.c | 130 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 147 insertions(+), 19 deletions(-) create mode 100644 src/lib/evil/stat.c diff --git a/src/lib/evil/evil_stat.h b/src/lib/evil/evil_stat.h index a063f8ec9c..8c9d250dbe 100644 --- a/src/lib/evil/evil_stat.h +++ b/src/lib/evil/evil_stat.h @@ -12,11 +12,20 @@ // loading as functions: chmod and umask (for umask, it is necessary to include: errno.h) // fstat ja incluido em #include +// loading as functions: chmod and umask (for umask, it is necessary to include: errno.h) +// from corecrt_io import chmod and umask +// fstat ja incluido em +typedef int mode_t ; #ifndef stat64 # define stat64 _stat64 #endif + +int fstatat(int fd, const char *restrict path, struct stat *restrict buf, int flag); + +int fstatat64(int fd, const char *restrict path, struct stat *restrict buf, int flag); + // Missing definitions: // Note: some pieces of code were based on LibreSSL-Portable's compat lib and // adapted to EFL standards. @@ -35,23 +44,12 @@ # define S_IXOTH 0 /* Execute others */ #endif -#endif - - - -/* - -// ------------------------------------------------------------------------ - -// Sinalizadores de tipo de arquivo para d_type // ver a questão de st_mode - -#define DT_UNKNOWN 0 -#define DT_REG S_IFREG -#define DT_DIR S_IFDIR -#define DT_FIFO S_IFIFO -#define DT_SOCK S_IFSOCK //ver -#define DT_CHR S_IFCHR -#define DT_BLK S_IFBLK //ver -#define DT_LNK S_IFLNK //ver +#define S_ISFIFO(mode) (((mode) & S_IFMT) == S_IFIFO) +#define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR) +#define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG) +#define S_ISLNK(mode) (((mode) & S_IFMT) == S_IFLNK) +#define S_ISSOCK(mode) (((mode) & S_IFMT) == S_IFSOCK) +#define S_ISCHR(mode) (((mode) & S_IFMT) == S_IFCHR) +#define S_ISBLK(mode) (((mode) & S_IFMT) == S_IFBLK) -*/ \ No newline at end of file +#endif \ No newline at end of file diff --git a/src/lib/evil/stat.c b/src/lib/evil/stat.c new file mode 100644 index 0000000000..5745c5c2fa --- /dev/null +++ b/src/lib/evil/stat.c @@ -0,0 +1,130 @@ +#include +#include +#include + +//#include +#include +# include +# include +#include "stat.h" + + + +#define AT_SYMLINK_NOFOLLOW 0x01 + + +int fstatat(int dirfd, const char *pathname, struct stat *statbuf,int flags){ + int r_fstatat; + int size_str, size_str_02; + char* pathbuf = NULL; + size_t pathbuf_size = 0; + DWORD copied = 0; + + + + + if(pathname[2] == '\\'){ + if(flags == AT_SYMLINK_NOFOLLOW){ + r_fstatat = stat(pathname,statbuf); + } + else{ + r_fstatat = stat(pathname,statbuf); + } + } + else{ + do { + + pathbuf_size += MAX_PATH; + pathbuf = realloc(pathbuf, pathbuf_size * sizeof(char)); + copied = GetModuleFileName(NULL, pathbuf, pathbuf_size); + } while (copied >= pathbuf_size); + pathbuf_size = copied; + pathbuf = realloc(pathbuf, pathbuf_size * sizeof(char)); + copied = GetModuleFileName(NULL, pathbuf, pathbuf_size); + + + //getlasterror + + for(size_str = strlen(pathbuf); size_str >= 0; size_str -- ){ + if(pathbuf[size_str] == '\\'){ + pathbuf[size_str + 1] = 0; + break; + } + } + + size_str = strlen(pathbuf) + strlen(pathname); + //size_str = strlen(pathname); + + // verificar a nescesidade de " / " entre as variaveis + char* path_complete = malloc(sizeof(char) * size_str); + + path_complete = pathbuf; + + + if(flags == AT_SYMLINK_NOFOLLOW){ + r_fstatat = stat(path_complete, statbuf); + } + else{ + r_fstatat = stat(path_complete, statbuf); + } + } + return r_fstatat; +} + +int fstatat64(int dirfd, const char *pathname, struct stat *statbuf,int flags){ + int r_fstatat; + int size_str, size_str_02; + char* pathbuf = NULL; + size_t pathbuf_size = 0; + DWORD copied = 0; + + + + + if(pathname[2] == '\\'){ + if(flags == AT_SYMLINK_NOFOLLOW){ + r_fstatat = stat64(pathname,statbuf); + } + else{ + r_fstatat = stat64(pathname,statbuf); + } + } + else{ + do { + + pathbuf_size += MAX_PATH; + pathbuf = realloc(pathbuf, pathbuf_size * sizeof(char)); + copied = GetModuleFileName(NULL, pathbuf, pathbuf_size); + } while (copied >= pathbuf_size); + pathbuf_size = copied; + pathbuf = realloc(pathbuf, pathbuf_size * sizeof(char)); + copied = GetModuleFileName(NULL, pathbuf, pathbuf_size); + + + //getlasterror + + for(size_str = strlen(pathbuf); size_str >= 0; size_str -- ){ + if(pathbuf[size_str] == '\\'){ + pathbuf[size_str + 1] = 0; + break; + } + } + + size_str = strlen(pathbuf) + strlen(pathname); + //size_str = strlen(pathname); + + // verificar a nescesidade de " / " entre as variaveis + char* path_complete = malloc(sizeof(char) * size_str); + + path_complete = pathbuf; + + + if(flags == AT_SYMLINK_NOFOLLOW){ + r_fstatat = stat64(path_complete, statbuf); + } + else{ + r_fstatat = stat64(path_complete, statbuf); + } + } + return r_fstatat; +} From ad3709f1a2969e0e961f9a73fd62200710d27f5b Mon Sep 17 00:00:00 2001 From: Ricardo Campos <46923915+ricardocvel@users.noreply.github.com> Date: Tue, 12 May 2020 11:13:38 -0300 Subject: [PATCH 04/11] Update stat.c Update stat.h Update stat.c Update stat.h Update stat.c Update stat.h including Windows.h at WIN_LEAN_AND_MEAN. Co-authored-by: Lucas moving stat. {h, c) for evil / evil stat. {h, c} deleting items, which were copied to another directory --- src/lib/evil/evil_stat.c | 132 +++++++++++++++++++++++++++++++++++++++ src/lib/evil/evil_stat.h | 6 +- 2 files changed, 136 insertions(+), 2 deletions(-) create mode 100644 src/lib/evil/evil_stat.c diff --git a/src/lib/evil/evil_stat.c b/src/lib/evil/evil_stat.c new file mode 100644 index 0000000000..604f6ea55f --- /dev/null +++ b/src/lib/evil/evil_stat.c @@ -0,0 +1,132 @@ +#include +#include +#include +#ifdef _WIN32 +# ifndef WIN_LEAN_AND_MEAN +# define WIN_LEAN_AND_MEAN +# endif /* WIN_LEAN_AND_MEAN */ +# include +# undef WIN_LEAN_AND_MEAN +#endif /* _WIN32 */ +# include +# include +#include "stat.h" + +#define AT_SYMLINK_NOFOLLOW 0x01 + + +int +fstatat(int dirfd, const char *pathname, struct stat *statbuf, int flags) +{ + int r_fstatat; + + if (pathname[2] == '\\') + { + if (flags == AT_SYMLINK_NOFOLLOW) + r_fstatat = stat(pathname, statbuf); + else + r_fstatat = stat(pathname, statbuf); + return r_fstatat; + } + else + { + char *pathbuf = NULL; + size_t pathbuf_size = 0; + DWORD copied = 0; + do + { + pathbuf_size += MAX_PATH; + pathbuf = realloc(pathbuf, pathbuf_size * sizeof(char)); + copied = GetModuleFileName(NULL, pathbuf, pathbuf_size); + } while (copied >= pathbuf_size); + + pathbuf_size = copied; + pathbuf = realloc(pathbuf, pathbuf_size * sizeof(char)); + copied = GetModuleFileName(NULL, pathbuf, pathbuf_size); + + int size_str; + for (size_str = strlen(pathbuf); size_str >= 0; size_str -- ) + { + if (pathbuf[size_str] == '\\') + { + pathbuf[size_str + 1] = 0; + break; + } + } + + size_str = strlen(pathbuf) + strlen(pathname); + + char *path_complete = malloc(sizeof(char) * size_str); + + path_complete = strcat(pathbuf, pathname); + + + if (flags == AT_SYMLINK_NOFOLLOW) + { + r_fstatat = stat(path_complete, statbuf); + } + else + { + r_fstatat = stat(path_complete, statbuf); + } + return r_fstatat; + } +} + +int +fstatat64(int dirfd, const char *pathname, struct stat *statbuf, int flags) +{ + int r_fstatat; + + if (pathname[2] == '\\') + { + if (flags == AT_SYMLINK_NOFOLLOW) + r_fstatat = stat64(pathname, statbuf); + else + r_fstatat = stat64(pathname, statbuf); + return r_fstatat; + } + else + { + char *pathbuf = NULL; + size_t pathbuf_size = 0; + DWORD copied = 0; + do + { + pathbuf_size += MAX_PATH; + pathbuf = realloc(pathbuf, pathbuf_size * sizeof(char)); + copied = GetModuleFileName(NULL, pathbuf, pathbuf_size); + } while (copied >= pathbuf_size); + + pathbuf_size = copied; + pathbuf = realloc(pathbuf, pathbuf_size * sizeof(char)); + copied = GetModuleFileName(NULL, pathbuf, pathbuf_size); + + int size_str; + for (size_str = strlen(pathbuf); size_str >= 0; size_str -- ) + { + if (pathbuf[size_str] == '\\') + { + pathbuf[size_str + 1] = 0; + break; + } + } + + size_str = strlen(pathbuf) + strlen(pathname); + + char *path_complete = malloc(sizeof(char) * size_str); + + path_complete = strcat(pathbuf, pathname); + + + if (flags == AT_SYMLINK_NOFOLLOW) + { + r_fstatat = stat64(path_complete, statbuf); + } + else + { + r_fstatat = stat64(path_complete, statbuf); + } + return r_fstatat; + } +} diff --git a/src/lib/evil/evil_stat.h b/src/lib/evil/evil_stat.h index 8c9d250dbe..5ccfa32f55 100644 --- a/src/lib/evil/evil_stat.h +++ b/src/lib/evil/evil_stat.h @@ -9,9 +9,12 @@ #include #include #include + // loading as functions: chmod and umask (for umask, it is necessary to include: errno.h) // fstat ja incluido em + #include + // loading as functions: chmod and umask (for umask, it is necessary to include: errno.h) // from corecrt_io import chmod and umask // fstat ja incluido em @@ -21,7 +24,6 @@ typedef int mode_t ; # define stat64 _stat64 #endif - int fstatat(int fd, const char *restrict path, struct stat *restrict buf, int flag); int fstatat64(int fd, const char *restrict path, struct stat *restrict buf, int flag); @@ -52,4 +54,4 @@ int fstatat64(int fd, const char *restrict path, struct stat *restrict buf, int #define S_ISCHR(mode) (((mode) & S_IFMT) == S_IFCHR) #define S_ISBLK(mode) (((mode) & S_IFMT) == S_IFBLK) -#endif \ No newline at end of file +#endif From a8fa40850408736bab85c332c68485348b3cceca Mon Sep 17 00:00:00 2001 From: Ricardo Campos Date: Wed, 17 Jun 2020 09:30:16 -0300 Subject: [PATCH 05/11] replacing with "evil_private.h" and including 'evil_stat.c' in lib/evil/meson.build --- src/lib/evil/evil_stat.c | 14 ++--- src/lib/evil/evil_stat.h | 21 +++---- src/lib/evil/meson.build | 1 + src/lib/evil/stat.c | 130 --------------------------------------- 4 files changed, 12 insertions(+), 154 deletions(-) delete mode 100644 src/lib/evil/stat.c diff --git a/src/lib/evil/evil_stat.c b/src/lib/evil/evil_stat.c index 604f6ea55f..c650a63d6f 100644 --- a/src/lib/evil/evil_stat.c +++ b/src/lib/evil/evil_stat.c @@ -1,16 +1,10 @@ #include #include #include -#ifdef _WIN32 -# ifndef WIN_LEAN_AND_MEAN -# define WIN_LEAN_AND_MEAN -# endif /* WIN_LEAN_AND_MEAN */ -# include -# undef WIN_LEAN_AND_MEAN -#endif /* _WIN32 */ -# include -# include -#include "stat.h" +#include "evil_private.h" +#include +#include +#include "evil_stat.h" #define AT_SYMLINK_NOFOLLOW 0x01 diff --git a/src/lib/evil/evil_stat.h b/src/lib/evil/evil_stat.h index 5ccfa32f55..554aa1d211 100644 --- a/src/lib/evil/evil_stat.h +++ b/src/lib/evil/evil_stat.h @@ -1,36 +1,29 @@ #ifndef __EVIL_STAT_H__ #define __EVIL_STAT_H__ -#include -#include <../ucrt/sys/types.h> #include #include -#include_next -#include +#include #include -#include - -// loading as functions: chmod and umask (for umask, it is necessary to include: errno.h) -// fstat ja incluido em - +#include #include +#include +#include -// loading as functions: chmod and umask (for umask, it is necessary to include: errno.h) -// from corecrt_io import chmod and umask -// fstat ja incluido em typedef int mode_t ; #ifndef stat64 # define stat64 _stat64 #endif -int fstatat(int fd, const char *restrict path, struct stat *restrict buf, int flag); +EAPI int fstatat(int fd, const char *restrict path, struct stat *restrict buf, int flag); -int fstatat64(int fd, const char *restrict path, struct stat *restrict buf, int flag); +EAPI int fstatat64(int fd, const char *restrict path, struct stat *restrict buf, int flag); // Missing definitions: // Note: some pieces of code were based on LibreSSL-Portable's compat lib and // adapted to EFL standards. + #ifdef _MSC_VER # define S_IRWXU 0 /* RWX user */ # define S_IRUSR S_IREAD /* Read user */ diff --git a/src/lib/evil/meson.build b/src/lib/evil/meson.build index f41d4b4961..37b820a579 100644 --- a/src/lib/evil/meson.build +++ b/src/lib/evil/meson.build @@ -21,6 +21,7 @@ if target_machine.system() == 'windows' 'evil_unistd.c', 'evil_util.c', 'evil_private.h', + 'evil_stat.c', ]) evil_header_src = [ diff --git a/src/lib/evil/stat.c b/src/lib/evil/stat.c deleted file mode 100644 index 5745c5c2fa..0000000000 --- a/src/lib/evil/stat.c +++ /dev/null @@ -1,130 +0,0 @@ -#include -#include -#include - -//#include -#include -# include -# include -#include "stat.h" - - - -#define AT_SYMLINK_NOFOLLOW 0x01 - - -int fstatat(int dirfd, const char *pathname, struct stat *statbuf,int flags){ - int r_fstatat; - int size_str, size_str_02; - char* pathbuf = NULL; - size_t pathbuf_size = 0; - DWORD copied = 0; - - - - - if(pathname[2] == '\\'){ - if(flags == AT_SYMLINK_NOFOLLOW){ - r_fstatat = stat(pathname,statbuf); - } - else{ - r_fstatat = stat(pathname,statbuf); - } - } - else{ - do { - - pathbuf_size += MAX_PATH; - pathbuf = realloc(pathbuf, pathbuf_size * sizeof(char)); - copied = GetModuleFileName(NULL, pathbuf, pathbuf_size); - } while (copied >= pathbuf_size); - pathbuf_size = copied; - pathbuf = realloc(pathbuf, pathbuf_size * sizeof(char)); - copied = GetModuleFileName(NULL, pathbuf, pathbuf_size); - - - //getlasterror - - for(size_str = strlen(pathbuf); size_str >= 0; size_str -- ){ - if(pathbuf[size_str] == '\\'){ - pathbuf[size_str + 1] = 0; - break; - } - } - - size_str = strlen(pathbuf) + strlen(pathname); - //size_str = strlen(pathname); - - // verificar a nescesidade de " / " entre as variaveis - char* path_complete = malloc(sizeof(char) * size_str); - - path_complete = pathbuf; - - - if(flags == AT_SYMLINK_NOFOLLOW){ - r_fstatat = stat(path_complete, statbuf); - } - else{ - r_fstatat = stat(path_complete, statbuf); - } - } - return r_fstatat; -} - -int fstatat64(int dirfd, const char *pathname, struct stat *statbuf,int flags){ - int r_fstatat; - int size_str, size_str_02; - char* pathbuf = NULL; - size_t pathbuf_size = 0; - DWORD copied = 0; - - - - - if(pathname[2] == '\\'){ - if(flags == AT_SYMLINK_NOFOLLOW){ - r_fstatat = stat64(pathname,statbuf); - } - else{ - r_fstatat = stat64(pathname,statbuf); - } - } - else{ - do { - - pathbuf_size += MAX_PATH; - pathbuf = realloc(pathbuf, pathbuf_size * sizeof(char)); - copied = GetModuleFileName(NULL, pathbuf, pathbuf_size); - } while (copied >= pathbuf_size); - pathbuf_size = copied; - pathbuf = realloc(pathbuf, pathbuf_size * sizeof(char)); - copied = GetModuleFileName(NULL, pathbuf, pathbuf_size); - - - //getlasterror - - for(size_str = strlen(pathbuf); size_str >= 0; size_str -- ){ - if(pathbuf[size_str] == '\\'){ - pathbuf[size_str + 1] = 0; - break; - } - } - - size_str = strlen(pathbuf) + strlen(pathname); - //size_str = strlen(pathname); - - // verificar a nescesidade de " / " entre as variaveis - char* path_complete = malloc(sizeof(char) * size_str); - - path_complete = pathbuf; - - - if(flags == AT_SYMLINK_NOFOLLOW){ - r_fstatat = stat64(path_complete, statbuf); - } - else{ - r_fstatat = stat64(path_complete, statbuf); - } - } - return r_fstatat; -} From 5c8ca7112f907f4255ce4a286ed2d5fa73d85ed2 Mon Sep 17 00:00:00 2001 From: Ricardo Campos Date: Wed, 24 Jun 2020 12:14:43 -0300 Subject: [PATCH 06/11] inclusion of EAPI in evil_stat.c --- src/lib/evil/evil_stat.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lib/evil/evil_stat.c b/src/lib/evil/evil_stat.c index c650a63d6f..fa968a27be 100644 --- a/src/lib/evil/evil_stat.c +++ b/src/lib/evil/evil_stat.c @@ -2,14 +2,14 @@ #include #include #include "evil_private.h" +#include #include #include #include "evil_stat.h" #define AT_SYMLINK_NOFOLLOW 0x01 - -int +EAPI int fstatat(int dirfd, const char *pathname, struct stat *statbuf, int flags) { int r_fstatat; @@ -67,7 +67,7 @@ fstatat(int dirfd, const char *pathname, struct stat *statbuf, int flags) } } -int +EAPI int fstatat64(int dirfd, const char *pathname, struct stat *statbuf, int flags) { int r_fstatat; From 3c9df9aea6ce220aa15dfc571772675a0580382f Mon Sep 17 00:00:00 2001 From: Ricardo Campos Date: Thu, 25 Jun 2020 17:48:20 -0300 Subject: [PATCH 07/11] replacement of EAPI with EVIL_API --- src/lib/evil/evil_stat.c | 8 ++++---- src/lib/evil/evil_stat.h | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/lib/evil/evil_stat.c b/src/lib/evil/evil_stat.c index fa968a27be..0c6867bf38 100644 --- a/src/lib/evil/evil_stat.c +++ b/src/lib/evil/evil_stat.c @@ -9,7 +9,7 @@ #define AT_SYMLINK_NOFOLLOW 0x01 -EAPI int +EVIL_API_H int fstatat(int dirfd, const char *pathname, struct stat *statbuf, int flags) { int r_fstatat; @@ -39,7 +39,7 @@ fstatat(int dirfd, const char *pathname, struct stat *statbuf, int flags) copied = GetModuleFileName(NULL, pathbuf, pathbuf_size); int size_str; - for (size_str = strlen(pathbuf); size_str >= 0; size_str -- ) + for (size_str = strlen(pathbuf); size_str >= 0; size_str --) { if (pathbuf[size_str] == '\\') { @@ -67,7 +67,7 @@ fstatat(int dirfd, const char *pathname, struct stat *statbuf, int flags) } } -EAPI int +EVIL_API_H int fstatat64(int dirfd, const char *pathname, struct stat *statbuf, int flags) { int r_fstatat; @@ -97,7 +97,7 @@ fstatat64(int dirfd, const char *pathname, struct stat *statbuf, int flags) copied = GetModuleFileName(NULL, pathbuf, pathbuf_size); int size_str; - for (size_str = strlen(pathbuf); size_str >= 0; size_str -- ) + for (size_str = strlen(pathbuf); size_str >= 0; size_str --) { if (pathbuf[size_str] == '\\') { diff --git a/src/lib/evil/evil_stat.h b/src/lib/evil/evil_stat.h index 554aa1d211..b5339cb685 100644 --- a/src/lib/evil/evil_stat.h +++ b/src/lib/evil/evil_stat.h @@ -16,9 +16,9 @@ typedef int mode_t ; # define stat64 _stat64 #endif -EAPI int fstatat(int fd, const char *restrict path, struct stat *restrict buf, int flag); +EVIL_API_H int fstatat(int fd, const char *restrict path, struct stat *restrict buf, int flag); -EAPI int fstatat64(int fd, const char *restrict path, struct stat *restrict buf, int flag); +EVIL_API_H int fstatat64(int fd, const char *restrict path, struct stat *restrict buf, int flag); // Missing definitions: // Note: some pieces of code were based on LibreSSL-Portable's compat lib and From 6f33c4890712719627bef1d17574de1b6b404f6f Mon Sep 17 00:00:00 2001 From: Ricardo Campos Date: Thu, 25 Jun 2020 18:04:03 -0300 Subject: [PATCH 08/11] deleted fstatat64 () and added guard _MSC_VER --- src/lib/evil/evil_stat.c | 60 +--------------------------------------- src/lib/evil/evil_stat.h | 9 +++--- 2 files changed, 6 insertions(+), 63 deletions(-) diff --git a/src/lib/evil/evil_stat.c b/src/lib/evil/evil_stat.c index 0c6867bf38..01151e50f7 100644 --- a/src/lib/evil/evil_stat.c +++ b/src/lib/evil/evil_stat.c @@ -65,62 +65,4 @@ fstatat(int dirfd, const char *pathname, struct stat *statbuf, int flags) } return r_fstatat; } -} - -EVIL_API_H int -fstatat64(int dirfd, const char *pathname, struct stat *statbuf, int flags) -{ - int r_fstatat; - - if (pathname[2] == '\\') - { - if (flags == AT_SYMLINK_NOFOLLOW) - r_fstatat = stat64(pathname, statbuf); - else - r_fstatat = stat64(pathname, statbuf); - return r_fstatat; - } - else - { - char *pathbuf = NULL; - size_t pathbuf_size = 0; - DWORD copied = 0; - do - { - pathbuf_size += MAX_PATH; - pathbuf = realloc(pathbuf, pathbuf_size * sizeof(char)); - copied = GetModuleFileName(NULL, pathbuf, pathbuf_size); - } while (copied >= pathbuf_size); - - pathbuf_size = copied; - pathbuf = realloc(pathbuf, pathbuf_size * sizeof(char)); - copied = GetModuleFileName(NULL, pathbuf, pathbuf_size); - - int size_str; - for (size_str = strlen(pathbuf); size_str >= 0; size_str --) - { - if (pathbuf[size_str] == '\\') - { - pathbuf[size_str + 1] = 0; - break; - } - } - - size_str = strlen(pathbuf) + strlen(pathname); - - char *path_complete = malloc(sizeof(char) * size_str); - - path_complete = strcat(pathbuf, pathname); - - - if (flags == AT_SYMLINK_NOFOLLOW) - { - r_fstatat = stat64(path_complete, statbuf); - } - else - { - r_fstatat = stat64(path_complete, statbuf); - } - return r_fstatat; - } -} +} \ No newline at end of file diff --git a/src/lib/evil/evil_stat.h b/src/lib/evil/evil_stat.h index b5339cb685..d907f7d667 100644 --- a/src/lib/evil/evil_stat.h +++ b/src/lib/evil/evil_stat.h @@ -6,10 +6,13 @@ #include #include #include -#include -#include #include +#ifndef _MSC_VER +# include +# include +#endif + typedef int mode_t ; #ifndef stat64 @@ -18,8 +21,6 @@ typedef int mode_t ; EVIL_API_H int fstatat(int fd, const char *restrict path, struct stat *restrict buf, int flag); -EVIL_API_H int fstatat64(int fd, const char *restrict path, struct stat *restrict buf, int flag); - // Missing definitions: // Note: some pieces of code were based on LibreSSL-Portable's compat lib and // adapted to EFL standards. From 2bad3e73b2c2ff5866b29fe49f0f6230097969c8 Mon Sep 17 00:00:00 2001 From: Ricardo Campos Date: Fri, 26 Jun 2020 11:43:14 -0300 Subject: [PATCH 09/11] inclusion of the EVIL_API symbol --- src/lib/evil/evil_stat.c | 4 ++-- src/lib/evil/evil_stat.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lib/evil/evil_stat.c b/src/lib/evil/evil_stat.c index 01151e50f7..4db583f76e 100644 --- a/src/lib/evil/evil_stat.c +++ b/src/lib/evil/evil_stat.c @@ -9,7 +9,7 @@ #define AT_SYMLINK_NOFOLLOW 0x01 -EVIL_API_H int +EVIL_API int fstatat(int dirfd, const char *pathname, struct stat *statbuf, int flags) { int r_fstatat; @@ -39,7 +39,7 @@ fstatat(int dirfd, const char *pathname, struct stat *statbuf, int flags) copied = GetModuleFileName(NULL, pathbuf, pathbuf_size); int size_str; - for (size_str = strlen(pathbuf); size_str >= 0; size_str --) + for (size_str = strlen(pathbuf) -1; size_str >= 0; size_str --) { if (pathbuf[size_str] == '\\') { diff --git a/src/lib/evil/evil_stat.h b/src/lib/evil/evil_stat.h index d907f7d667..e3edbeac81 100644 --- a/src/lib/evil/evil_stat.h +++ b/src/lib/evil/evil_stat.h @@ -19,7 +19,7 @@ typedef int mode_t ; # define stat64 _stat64 #endif -EVIL_API_H int fstatat(int fd, const char *restrict path, struct stat *restrict buf, int flag); +EVIL_API int fstatat(int fd, const char *restrict path, struct stat *restrict buf, int flag); // Missing definitions: // Note: some pieces of code were based on LibreSSL-Portable's compat lib and From 4c3d41f9e4de6a9d2664132e9a1a8ee96f396457 Mon Sep 17 00:00:00 2001 From: Ricardo Campos Date: Thu, 2 Jul 2020 13:35:50 -0300 Subject: [PATCH 10/11] adequacy of fstatat () for correct reading of absolute paths in windows --- src/lib/evil/evil_stat.c | 6 +----- src/lib/evil/evil_stat.h | 3 ++- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/lib/evil/evil_stat.c b/src/lib/evil/evil_stat.c index 4db583f76e..8c5b2fc711 100644 --- a/src/lib/evil/evil_stat.c +++ b/src/lib/evil/evil_stat.c @@ -14,7 +14,7 @@ fstatat(int dirfd, const char *pathname, struct stat *statbuf, int flags) { int r_fstatat; - if (pathname[2] == '\\') + if (pathname[1] == ':' && pathname[2] == '\\' || pathname[2] == '/' ) { if (flags == AT_SYMLINK_NOFOLLOW) r_fstatat = stat(pathname, statbuf); @@ -34,10 +34,6 @@ fstatat(int dirfd, const char *pathname, struct stat *statbuf, int flags) copied = GetModuleFileName(NULL, pathbuf, pathbuf_size); } while (copied >= pathbuf_size); - pathbuf_size = copied; - pathbuf = realloc(pathbuf, pathbuf_size * sizeof(char)); - copied = GetModuleFileName(NULL, pathbuf, pathbuf_size); - int size_str; for (size_str = strlen(pathbuf) -1; size_str >= 0; size_str --) { diff --git a/src/lib/evil/evil_stat.h b/src/lib/evil/evil_stat.h index e3edbeac81..c7e29f38c1 100644 --- a/src/lib/evil/evil_stat.h +++ b/src/lib/evil/evil_stat.h @@ -38,7 +38,6 @@ EVIL_API int fstatat(int fd, const char *restrict path, struct stat *restrict bu # define S_IROTH 0 /* Read others */ # define S_IWOTH 0 /* Write others */ # define S_IXOTH 0 /* Execute others */ -#endif #define S_ISFIFO(mode) (((mode) & S_IFMT) == S_IFIFO) #define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR) @@ -49,3 +48,5 @@ EVIL_API int fstatat(int fd, const char *restrict path, struct stat *restrict bu #define S_ISBLK(mode) (((mode) & S_IFMT) == S_IFBLK) #endif + +#endif From 63714340fc6dd414a681335f4c55562fb6143a95 Mon Sep 17 00:00:00 2001 From: Ricardo Campos Date: Tue, 7 Jul 2020 12:17:59 -0300 Subject: [PATCH 11/11] solving problems with memory loss in evil_stat.c --- src/lib/evil/evil_stat.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/lib/evil/evil_stat.c b/src/lib/evil/evil_stat.c index 8c5b2fc711..0b799f8024 100644 --- a/src/lib/evil/evil_stat.c +++ b/src/lib/evil/evil_stat.c @@ -43,13 +43,11 @@ fstatat(int dirfd, const char *pathname, struct stat *statbuf, int flags) break; } } - - size_str = strlen(pathbuf) + strlen(pathname); - - char *path_complete = malloc(sizeof(char) * size_str); - - path_complete = strcat(pathbuf, pathname); + size_str = strlen(pathbuf) + strlen(pathname); + char *path_complete = malloc(sizeof(char) * size_str + 1); + strcpy(path_complete, pathbuf); + strcat(path_complete, pathname); if (flags == AT_SYMLINK_NOFOLLOW) {