Move hc_qsort_r() and hc_bsearch_r() from potfile.c to shared.c - Lets us use them from within all objects

This commit is contained in:
jsteube
2016-11-16 10:22:57 +01:00
parent 23fa7000fa
commit 316694fd08
4 changed files with 42 additions and 41 deletions
+1 -38
View File
@@ -13,14 +13,7 @@
#include "outfile.h"
#include "potfile.h"
#include "locking.h"
#if defined (_WIN)
#define __WINDOWS__
#endif
#include "sort_r.h"
#if defined (_WIN)
#undef __WINDOWS__
#endif
#include "shared.h"
// get rid of this later
int sort_by_hash (const void *v1, const void *v2, void *v3);
@@ -82,36 +75,6 @@ int sort_by_hash_t_salt_hccap (const void *v1, const void *v2)
return 0;
}
void hc_qsort_r (void *base, size_t nmemb, size_t size, int (*compar) (const void *, const void *, void *), void *arg)
{
sort_r (base, nmemb, size, compar, arg);
}
void *hc_bsearch_r (const void *key, const void *base, size_t nmemb, size_t size, int (*compar) (const void *, const void *, void *), void *arg)
{
for (size_t l = 0, r = nmemb; r; r >>= 1)
{
const size_t m = r >> 1;
const size_t c = l + m;
const char *next = (char *) base + (c * size);
const int cmp = (*compar) (key, next, arg);
if (cmp > 0)
{
l += m + 1;
r--;
}
if (cmp == 0) return ((void *) next);
}
return (NULL);
}
int potfile_init (hashcat_ctx_t *hashcat_ctx)
{
folder_config_t *folder_config = hashcat_ctx->folder_config;
+38
View File
@@ -141,6 +141,44 @@ void hc_sleep (const u32 sec)
#endif
}
#if defined (_WIN)
#define __WINDOWS__
#endif
#include "sort_r.h"
#if defined (_WIN)
#undef __WINDOWS__
#endif
void hc_qsort_r (void *base, size_t nmemb, size_t size, int (*compar) (const void *, const void *, void *), void *arg)
{
sort_r (base, nmemb, size, compar, arg);
}
void *hc_bsearch_r (const void *key, const void *base, size_t nmemb, size_t size, int (*compar) (const void *, const void *, void *), void *arg)
{
for (size_t l = 0, r = nmemb; r; r >>= 1)
{
const size_t m = r >> 1;
const size_t c = l + m;
const char *next = (char *) base + (c * size);
const int cmp = (*compar) (key, next, arg);
if (cmp > 0)
{
l += m + 1;
r--;
}
if (cmp == 0) return ((void *) next);
}
return (NULL);
}
void setup_environment_variables ()
{
char *compute = getenv ("COMPUTE");