Replace DARWIN macro with __APPLE__
[hashcat.git] / src / shared.c
index df14f43..f4c76f9 100644 (file)
@@ -6,10 +6,15 @@
  * License.....: MIT
  */
 
-#ifdef DARWIN
+#ifdef __APPLE__
 #include <stdio.h>
 #endif
 
+#ifdef __FreeBSD__
+#include <stdio.h>
+#include <pthread_np.h>
+#endif
+
 #include <shared.h>
 #include <limits.h>
 
@@ -2382,7 +2387,7 @@ int tty_fix()
 }
 #endif
 
-#ifdef DARWIN
+#if defined(__APPLE__) || defined(__FreeBSD__)
 static struct termios savemodes;
 static int havemodes = 0;
 
@@ -3484,7 +3489,9 @@ int hm_set_fanspeed_with_device_id_nvapi (const uint device_id, const int fanspe
     {
       if (fanpolicy == 1)
       {
-        NV_GPU_COOLER_LEVELS CoolerLevels = { 0 };
+        NV_GPU_COOLER_LEVELS CoolerLevels;
+
+        memset (&CoolerLevels, 0, sizeof (NV_GPU_COOLER_LEVELS));
 
         CoolerLevels.Version = GPU_COOLER_LEVELS_VER | sizeof (NV_GPU_COOLER_LEVELS);
 
@@ -4358,7 +4365,7 @@ char *get_exec_path ()
 
   const int len = GetModuleFileName (NULL, exec_path, exec_path_len - 1);
 
-  #elif DARWIN
+  #elif __APPLE__
 
   uint size = exec_path_len;
 
@@ -4371,6 +4378,23 @@ char *get_exec_path ()
 
   const int len = strlen (exec_path);
 
+  #elif __FreeBSD__
+
+  #include <sys/sysctl.h>
+
+  int mib[4];
+  mib[0] = CTL_KERN;
+  mib[1] = KERN_PROC;
+  mib[2] = KERN_PROC_PATHNAME;
+  mib[3] = -1;
+
+  char tmp[32] = { 0 };
+
+  size_t size = exec_path_len;
+  sysctl(mib, 4, exec_path, &size, NULL, 0);
+
+  const int len = readlink (tmp, exec_path, exec_path_len - 1);
+
   #else
   #error Your Operating System is not supported or detected
   #endif
@@ -4495,7 +4519,7 @@ void truecrypt_crc32 (const char *filename, u8 keytab[64])
   myfree (buf);
 }
 
-#ifdef DARWIN
+#ifdef __APPLE__
 int pthread_setaffinity_np (pthread_t thread, size_t cpu_size, cpu_set_t *cpu_set)
 {
   int core;
@@ -4523,6 +4547,9 @@ void set_cpu_affinity (char *cpu_affinity)
 {
   #ifdef _WIN
   DWORD_PTR aff_mask = 0;
+  #elif __FreeBSD__
+  cpuset_t cpuset;
+  CPU_ZERO (&cpuset);
   #elif _POSIX
   cpu_set_t cpuset;
   CPU_ZERO (&cpuset);
@@ -4570,6 +4597,9 @@ void set_cpu_affinity (char *cpu_affinity)
   #ifdef _WIN
   SetProcessAffinityMask (GetCurrentProcess (), aff_mask);
   SetThreadAffinityMask (GetCurrentThread (), aff_mask);
+  #elif __FreeBSD__
+  pthread_t thread = pthread_self ();
+  pthread_setaffinity_np (thread, sizeof (cpuset_t), &cpuset);
   #elif _POSIX
   pthread_t thread = pthread_self ();
   pthread_setaffinity_np (thread, sizeof (cpu_set_t), &cpuset);
@@ -5764,11 +5794,14 @@ char **scan_directory (const char *path)
 
   if ((d = opendir (tmp_path)) != NULL)
   {
-    #ifdef DARWIN
+    #ifdef __APPLE__
+
     struct dirent e;
 
-    for (;;) {
+    for (;;)
+    {
       memset (&e, 0, sizeof (e));
+
       struct dirent *de = NULL;
 
       if (readdir_r (d, &e, &de) != 0)
@@ -5779,12 +5812,16 @@ char **scan_directory (const char *path)
       }
 
       if (de == NULL) break;
+
     #else
+
     struct dirent *de;
 
     while ((de = readdir (d)) != NULL)
     {
+
     #endif
+
       if ((strcmp (de->d_name, ".") == 0) || (strcmp (de->d_name, "..") == 0)) continue;
 
       int path_size = strlen (tmp_path) + 1 + strlen (de->d_name);
@@ -6148,9 +6185,10 @@ void ascii_digest (char *out_buf, uint salt_pos, uint digest_pos)
 
   uint len = 4096;
 
-  uint digest_buf[64] = { 0 };
+  u8 datax[256] = { 0 };
 
-  u64 *digest_buf64 = (u64 *) digest_buf;
+  u64 *digest_buf64 = (u64 *) datax;
+  u32 *digest_buf   = (u32 *) datax;
 
   char *digests_buf_ptr = (char *) data.digests_buf;