From dbc3eccdb9b2dd282a498427e51cbc68a02aeb87 Mon Sep 17 00:00:00 2001
From: deuce <>
Date: Wed, 3 Sep 2003 03:51:58 +0000
Subject: [PATCH] Added support for /dev/speaker for BSD builds... you'll need
 /dev/speaker enabled in your kernel and be writeable by the uid/gid the BBS
 runs as.

---
 src/xpdev/genwrap.c | 24 +++++++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)

diff --git a/src/xpdev/genwrap.c b/src/xpdev/genwrap.c
index c6b88736e8..c805b63ad8 100644
--- a/src/xpdev/genwrap.c
+++ b/src/xpdev/genwrap.c
@@ -55,6 +55,11 @@
 		#include <sys/kbio.h>
 		#include <sys/kbd.h>
 	#endif
+	#if defined(__OpenBSD__) || defined(__NetBSD__)
+		#include <machine/spkr.h>
+	#elif defined(__FreeBSD__)
+		#include <machine/speaker.h>
+	#endif
 #endif	/* __unix__ */
 
 #include "genwrap.h"	/* Verify prototypes */
@@ -128,18 +133,31 @@ char* strrev(char* str)
     }
     return str;
 }
-#endif
 
 /****************************************************************************/
 /* Generate a tone at specified frequency for specified milliseconds		*/
 /* Thanks to Casey Martin for this code										*/
 /****************************************************************************/
-#if defined(__unix__)
 void DLLCALL unix_beep(int freq, int dur)
 {
 	static int console_fd=-1;
 
-#if !defined(__OpenBSD__) && !defined(__GNU__) && !defined(__NetBSD__) && !defined(__QNX__)
+#if defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__NetBSD__)
+	int speaker_fd=-1;
+	tone_t tone;
+
+	speaker_fd = open("/dev/speaker", O_WRONLY|O_APPEND);
+	if(speaker_fd != -1)  {
+		tone.frequency=freq;
+		tone.duration=dur;
+		ioctl(speaker_fd,SPKRTONE,&tone);
+		SLEEP(dur);
+		close(speaker_fd);
+		return;
+	}
+#endif
+
+#if !defined(__GNU__) && !defined(__QNX__)
 	if(console_fd == -1) 
   		console_fd = open("/dev/console", O_NOCTTY);
 	
-- 
GitLab