summaryrefslogtreecommitdiff
path: root/x11-toolkits/xview/files/patch-lib+libxview+ttysw+tty_init.c
blob: bf40a6bd435adab05a9aea50758e2cc56ef9f57f (plain) (blame)
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
--- lib/libxview/ttysw/tty_init.c.orig	1993-06-28 22:17:19.000000000 -0700
+++ lib/libxview/ttysw/tty_init.c	2011-09-24 22:14:48.726921496 -0700
@@ -14,6 +14,7 @@
  * Ttysw initialization, destruction and error procedures
  */
 
+#include <sys/param.h>
 #include <sys/time.h>
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -23,10 +24,17 @@
 
 #include <xview_private/portable.h>	/* for XV* defines and termios */
 
+#if defined(__FreeBSD_version) && __FreeBSD_version > 900007
+#define SVR4
+#define XV_USE_SVR4_PTYS
+#endif
+
 #ifdef	XV_USE_SVR4_PTYS
+#if !(defined(__FreeBSD_version) && __FreeBSD_version > 900007)
 #include <sys/stream.h>
 #include <sys/stropts.h>
 #include <sys/bufmod.h>
+#endif
 #endif	/* XV_USE_SVR4_PTYS */
 
 #ifndef SVR4
@@ -82,7 +90,11 @@
 
 extern char    *strncpy();
 extern char    *strcpy();
+#if (defined(BSD) && (BSD >= 199306))
+extern off_t	lseek();
+#else
 extern long     lseek();
+#endif
 char           *textsw_checkpoint_undo();
 
 /* static */ void ttysw_parseargs();
@@ -106,6 +118,7 @@
 
 extern int      ttysel_use_seln_service;
 
+static int	ttyinit();
 
 struct ttysw_createoptions {
     int             becomeconsole;	/* be the console */
@@ -518,6 +531,9 @@
     (void) dup2(ttysw->ttysw_tty, 2);
     (void) close(ttysw->ttysw_tty);
 
+#if (defined(BSD) && (BSD >= 199103))
+    (void) ioctl(0, TIOCSCTTY, NULL);
+#endif
     if (*argv == (char *) NULL || strcmp("-c", *argv) == 0) {
 	/* Process arg list */
 	int             argc;
@@ -544,15 +560,25 @@
  * ttcompat seems to leave things in a funny state and assumes
  * (seemingly) that login will fix things up.  Do it here.
  */
+#if defined(__FreeBSD_version) && __FreeBSD_version > 900007
+    if (tcgetattr (0, &tp) == -1)
+        perror("tcgetattr");
+#else
     if (ioctl (0, TCGETS, &tp) == -1)
         perror("ioctl TCGETS");
+#endif
     else {
         tp.c_lflag |= ECHO;
         tp.c_oflag |= ONLCR;
         tp.c_iflag |= ICRNL;
     }
+#if defined(__FreeBSD_version) && __FreeBSD_version > 900007
+    if (tcsetattr (0, TCSANOW, &tp) == -1)
+        perror("tcsetattr");
+#else
     if (ioctl (0, TCSETS, &tp) == -1)
         perror("ioctl TCSETS");
+#endif
 #endif /* BSD_TTY_COMPAT */
 #endif /* SVR4 */
 
@@ -739,7 +765,9 @@
 
 #ifdef SB_NO_DROPS /* defined as result of including new bufmod.h */
 
+#if !defined(__FreeBSD_version)
     if(ioctl(pty, I_PUSH, "bufmod") == -1) { /* some buffering ... */
+#endif
       
       /* we can't push bufmod... this means we're probably 
 	 running on a generic SVR4 system - we can ignore this
@@ -864,13 +892,16 @@
 #endif SB_NO_DROPS
 
 
+#ifndef __FreeBSD_version
     if (ioctl(pty, I_PUSH, "pckt") == -1) { /* must use getmsg for read */
         perror("push pckt");
 	return XV_ERROR;
     }
+#endif
 
     if ((tty = open(ptsname(pty),O_RDWR))<0)
         return XV_ERROR;
+#ifndef __FreeBSD_version
     if (ioctl(tty, I_PUSH, "ptem") == -1) {
         perror("push ptem");
 	return XV_ERROR;
@@ -879,12 +910,15 @@
         perror("push ldterm");
 	return XV_ERROR;
     }
+#endif
 #ifdef BSD_TTY_COMPAT
+#ifndef __FreeBSD_version
     if (ioctl(tty, I_PUSH, "ttcompat") == -1) { /* for csh */
         perror("push ttcompat");
 	return XV_ERROR;
     }
 #endif
+#endif
  
 #endif /* SVR4 */
 
@@ -955,7 +989,11 @@
     struct utmpx     utmp;
 #endif
     struct passwd  *passwdent;
+#if !(defined(BSD) && (BSD >= 199103))
     extern struct passwd *getpwuid();
+#else
+    struct passwd *getpwuid __P((uid_t));
+#endif
     int             f;
     char           *ttyn;
     extern char    *ttyname();
@@ -1007,13 +1045,22 @@
 		XV_MSG("Add tty[qrs][0-f] to /etc/ttys file.\n"));
 	return (0);
     }
+#if !(defined(BSD) && (BSD >= 199103))
     if ((f = open("/etc/utmp", 1)) >= 0) {
+#else
+    if ((f = open(_PATH_UTMP, 1)) >= 0) {
+#endif
 	(void) lseek(f, (long) (ttyslotuse * sizeof(utmp)), 0);
 	(void) write(f, (char *) &utmp, sizeof(utmp));
 	(void) close(f);
     } else {
 	(void) fprintf(stderr, 
+#if !(defined(BSD) && (BSD >= 199103))
 	XV_MSG("make sure that you can write /etc/utmp!\n"));
+#else
+	XV_MSG("make sure that you can write "));
+	    (void) fprintf(stderr, "%s!\n", _PATH_UTMP);
+#endif
 	return (0);
     }
     return (ttyslotuse);