implement get_exec_path for FreeBSD
[hashcat.git] / src / shared.c
index b10790c..c2e7db8 100644 (file)
@@ -6,7 +6,7 @@
  * License.....: MIT
  */
 
-#ifdef OSX
+#if defined(DARWIN) || defined(__FreeBSD__)
 #include <stdio.h>
 #endif
 
@@ -2334,14 +2334,14 @@ void drupal7_encode (u8 digest[64], u8 buf[43])
  */
 
 #ifdef LINUX
-static struct termio savemodes;
+static struct termios savemodes;
 static int havemodes = 0;
 
 int tty_break()
 {
-  struct termio modmodes;
+  struct termios modmodes;
 
-  if (ioctl (fileno (stdin), TCGETA, &savemodes) < 0) return -1;
+  if (tcgetattr (fileno (stdin), &savemodes) < 0) return -1;
 
   havemodes = 1;
 
@@ -2350,7 +2350,7 @@ int tty_break()
   modmodes.c_cc[VMIN] = 1;
   modmodes.c_cc[VTIME] = 0;
 
-  return ioctl (fileno (stdin), TCSETAW, &modmodes);
+  return tcsetattr (fileno (stdin), TCSANOW, &modmodes);
 }
 
 int tty_getchar()
@@ -2378,11 +2378,11 @@ int tty_fix()
 {
   if (!havemodes) return 0;
 
-  return ioctl (fileno (stdin), TCSETAW, &savemodes);
+  return tcsetattr (fileno (stdin), TCSADRAIN, &savemodes);
 }
 #endif
 
-#ifdef OSX
+#ifdef DARWIN
 static struct termios savemodes;
 static int havemodes = 0;
 
@@ -4358,7 +4358,7 @@ char *get_exec_path ()
 
   const int len = GetModuleFileName (NULL, exec_path, exec_path_len - 1);
 
-  #elif OSX
+  #elif DARWIN
 
   uint size = exec_path_len;
 
@@ -4371,6 +4371,20 @@ 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;
+
+  size_t size = sizeof(exec_path);
+
+  const int len = sysctl(mib, 4, exec_path, &size, NULL, 0);
+
   #else
   #error Your Operating System is not supported or detected
   #endif
@@ -4495,7 +4509,7 @@ void truecrypt_crc32 (const char *filename, u8 keytab[64])
   myfree (buf);
 }
 
-#ifdef OSX
+#ifdef DARWIN
 int pthread_setaffinity_np (pthread_t thread, size_t cpu_size, cpu_set_t *cpu_set)
 {
   int core;
@@ -5763,7 +5777,7 @@ char **scan_directory (const char *path)
 
   if ((d = opendir (tmp_path)) != NULL)
   {
-    #ifdef OSX
+    #ifdef DARWIN
     struct dirent e;
 
     for (;;) {