summaryrefslogtreecommitdiffstats
path: root/audio/xoscope/files/patch-ser__unix.c
blob: bee2d691f1db787490be4f20d7379942e79d4ad1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
--- ser_unix.c.orig	2008-12-17 17:46:15 UTC
+++ ser_unix.c
@@ -14,7 +14,14 @@
 #include <errno.h>
 #include <unistd.h>
 #include <string.h>
+#if (defined(__unix__) || defined(unix)) && !defined(USG)
+#include <sys/param.h>
+#endif
+#ifdef BSD
+#include <termios.h>
+#else
 #include <termio.h>
+#endif
 #include <fcntl.h>
 #include <sys/types.h>
 #include <sys/ioctl.h>
@@ -24,7 +31,11 @@
 
 char device[512] = "";		/* Serial device */
 int sflags;
+#ifdef BSD
+struct termios stbuf, svbuf;	/* termios: svbuf=saved, stbuf=set */
+#else
 struct termio stbuf, svbuf;	/* termios: svbuf=saved, stbuf=set */
+#endif
 
 char serial_error[256];
 
@@ -68,7 +79,11 @@ void
 cleanup_serial(int fd)
 {
   if (fd > 0) {
+#ifdef BSD
+    if (tcsetattr(fd, TCSANOW, &svbuf) < 0 ) {
+#else
     if (ioctl(fd, TCSETA, &svbuf) < 0) {
+#endif
       /* sprintf(serial_error, "Can't ioctl set device %s", device); */
       /* perror(error); */
     }
@@ -86,12 +101,20 @@ findscope(char *dev, int i)
     sprintf(serial_error, "%s %s", dev, strerror(errno));
     return(0);
   }
+#ifdef BSD
+  if (tcgetattr(fd, &svbuf) < 0) { /* save settings */
+#else
   if (ioctl(fd, TCGETA, &svbuf) < 0) { /* save settings */
+#endif
     sprintf(serial_error, "%s Can't ioctl TCGETA", dev);
     close(fd);
     return(0);
   }
+#ifdef BSD
+  if (tcsetattr(fd, TCSANOW, &stbuf) < 0) {
+#else
   if (ioctl(fd, TCSETA, &stbuf) < 0) {
+#endif
     sprintf(serial_error, "%s Can't ioctl TCSETA", dev);
     close(fd);
     return(0);
@@ -101,7 +124,11 @@ findscope(char *dev, int i)
     return (1);		/* serial port scope found! */
   }
 
+#ifdef BSD
+  if (tcsetattr(fd, TCSANOW, &svbuf) < 0) { /* restore settings */
+#else
   if (ioctl(fd, TCSETA, &svbuf) < 0) { /* restore settings */
+#endif
 #if 0
     sprintf(serial_error, "Can't ioctl (set) %s", dev);
     close(fd);
OpenPOWER on IntegriCloud