diff --git a/src/lib/evil/evil_stat.c b/src/lib/evil/evil_stat.c new file mode 100644 index 0000000000..0b799f8024 --- /dev/null +++ b/src/lib/evil/evil_stat.c @@ -0,0 +1,62 @@ +#include +#include +#include +#include "evil_private.h" +#include +#include +#include +#include "evil_stat.h" + +#define AT_SYMLINK_NOFOLLOW 0x01 + +EVIL_API int +fstatat(int dirfd, const char *pathname, struct stat *statbuf, int flags) +{ + int r_fstatat; + + if (pathname[1] == ':' && pathname[2] == '\\' || 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); + + int size_str; + for (size_str = strlen(pathbuf) -1; 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 + 1); + strcpy(path_complete, pathbuf); + strcat(path_complete, pathname); + + if (flags == AT_SYMLINK_NOFOLLOW) + { + r_fstatat = stat(path_complete, statbuf); + } + else + { + r_fstatat = stat(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 f06b94dd3f..c7e29f38c1 100644 --- a/src/lib/evil/evil_stat.h +++ b/src/lib/evil/evil_stat.h @@ -1,9 +1,30 @@ #ifndef __EVIL_STAT_H__ #define __EVIL_STAT_H__ +#include +#include +#include +#include +#include +#include + +#ifndef _MSC_VER +# include +# include +#endif + + +typedef int mode_t ; +#ifndef stat64 +# define stat64 _stat64 +#endif + +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 // adapted to EFL standards. + #ifdef _MSC_VER # define S_IRWXU 0 /* RWX user */ # define S_IRUSR S_IREAD /* Read user */ @@ -17,6 +38,15 @@ # define S_IROTH 0 /* Read others */ # define S_IWOTH 0 /* Write others */ # define S_IXOTH 0 /* Execute others */ + +#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) + #endif #endif diff --git a/src/lib/evil/meson.build b/src/lib/evil/meson.build index 8c12015bb8..c1a7b79986 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 = [