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

pull/599/head
jsteube 8 years ago
parent 23fa7000fa
commit 316694fd08

@ -15,9 +15,6 @@
int sort_by_hash_t_salt (const void *v1, const void *v2);
int sort_by_hash_t_salt_hccap (const void *v1, const void *v2);
void hc_qsort_r (void *base, size_t nmemb, size_t size, int (*compar) (const void *, const void *, void *), void *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);
int potfile_init (hashcat_ctx_t *hashcat_ctx);
int potfile_read_open (hashcat_ctx_t *hashcat_ctx);
void potfile_read_close (hashcat_ctx_t *hashcat_ctx);

@ -34,4 +34,7 @@ void setup_seeding (const bool rp_gen_seed_chgd, const u32 rp_gen_seed);
int hc_stat (const char *pathname, hc_stat_t *buf);
int hc_fstat (int fd, hc_stat_t *buf);
void hc_qsort_r (void *base, size_t nmemb, size_t size, int (*compar) (const void *, const void *, void *), void *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);
#endif // _SHARED_H

@ -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;

@ -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");

Loading…
Cancel
Save