From 2994afd81a5240c009b5971e050c0ba489c76c03 Mon Sep 17 00:00:00 2001 From: jsteube Date: Sat, 1 Oct 2016 14:22:50 +0200 Subject: [PATCH] Use hc_stat from types.c instead of OS dependant branching --- include/types.h | 14 ++++++++++++++ src/dictstat.c | 6 ++---- src/outfile.c | 24 +++--------------------- src/outfile_check.c | 6 ++---- 4 files changed, 21 insertions(+), 29 deletions(-) diff --git a/include/types.h b/include/types.h index f58ba5f3d..cda101a56 100644 --- a/include/types.h +++ b/include/types.h @@ -67,6 +67,20 @@ typedef pthread_t hc_thread_t; typedef pthread_mutex_t hc_thread_mutex_t; #endif +// stat + +#if defined (_POSIX) +typedef struct stat hc_stat; +#endif + +#if defined (_WIN) +#if defined (_MSC_VER) +typedef struct _stat64 hc_stat; +#else +typedef struct stat64 hc_stat; +#endif +#endif + // enums typedef enum amplifier_count diff --git a/src/dictstat.c b/src/dictstat.c index b0cb2d64d..6df1dd979 100644 --- a/src/dictstat.c +++ b/src/dictstat.c @@ -74,15 +74,13 @@ void dictstat_read (dictstat_ctx_t *dictstat_ctx, const int comptime) return; } - #if defined (_POSIX) - struct stat tmpstat; + hc_stat tmpstat; + #if defined (_POSIX) fstat (fileno (fp), &tmpstat); #endif #if defined (_WIN) - struct stat64 tmpstat; - _fstat64 (fileno (fp), &tmpstat); #endif diff --git a/src/outfile.c b/src/outfile.c index cace79d51..c41570eaf 100644 --- a/src/outfile.c +++ b/src/outfile.c @@ -167,15 +167,8 @@ int outfile_and_hashfile (outfile_ctx_t *outfile_ctx, const char *hashfile) if (outfile == NULL) return 0; - #if defined (_POSIX) - struct stat tmpstat_outfile; - struct stat tmpstat_hashfile; - #endif - - #if defined (_WIN) - struct stat64 tmpstat_outfile; - struct stat64 tmpstat_hashfile; - #endif + hc_stat tmpstat_outfile; + hc_stat tmpstat_hashfile; FILE *tmp_outfile_fp = fopen (outfile, "r"); @@ -231,23 +224,12 @@ int outfile_and_hashfile (outfile_ctx_t *outfile_ctx, const char *hashfile) tmpstat_hashfile.st_blocks = 0; #endif - #if defined (_POSIX) - if (memcmp (&tmpstat_outfile, &tmpstat_hashfile, sizeof (struct stat)) == 0) + if (memcmp (&tmpstat_outfile, &tmpstat_hashfile, sizeof (hc_stat)) == 0) { log_error ("ERROR: Hashfile and Outfile are not allowed to point to the same file"); return -1; } - #endif - - #if defined (_WIN) - if (memcmp (&tmpstat_outfile, &tmpstat_hashfile, sizeof (struct stat64)) == 0) - { - log_error ("ERROR: Hashfile and Outfile are not allowed to point to the same file"); - - return -1; - } - #endif } return 0; diff --git a/src/outfile_check.c b/src/outfile_check.c index 3f6b0e8b5..c706ffa06 100644 --- a/src/outfile_check.c +++ b/src/outfile_check.c @@ -128,15 +128,13 @@ static void outfile_remove (hashcat_ctx_t *hashcat_ctx) { //hc_thread_mutex_lock (status_ctx->mux_display); - #if defined (_POSIX) - struct stat outfile_stat; + hc_stat outfile_stat; + #if defined (_POSIX) fstat (fileno (fp), &outfile_stat); #endif #if defined (_WIN) - struct stat64 outfile_stat; - _fstat64 (fileno (fp), &outfile_stat); #endif