8349 thrd_equal implements the wrong specification
[unleashed.git] / usr / src / cmd / bnu / xio.c
blobc6108411124c0801334feda36e029391a35334b2
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
20 * CDDL HEADER END
23 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
31 #pragma ident "%Z%%M% %I% %E% SMI"
33 #include "uucp.h"
35 #ifdef X_PROTOCOL
37 #define XBUFSIZ 512
38 static jmp_buf Xfailbuf;
39 extern int xrdblk();
40 extern unsigned msgtime;
43 * x.25 protocol
45 /* ARGSUSED */
46 static void
47 xalarm(sig)
48 int sig;
50 longjmp(Xfailbuf, 1);
53 static void (*xsig)();
56 * turn on protocol timer
58 int
59 xturnon()
61 xsig=signal(SIGALRM, xalarm);
62 return(0);
65 int
66 xturnoff()
68 (void) signal(SIGALRM, xsig);
69 return(0);
73 * write message across x.25 link
74 * type -> message type
75 * str -> message body (ascii string)
76 * fn -> x.25 file descriptor
77 * return
78 * 0
80 int
81 xwrmsg(type, str, fn)
82 char *str;
83 int fn;
84 char type;
86 char *s;
87 char bufr[XBUFSIZ];
89 bufr[0] = type;
90 s = &bufr[1];
91 while (*str)
92 *s++ = *str++;
93 *s = '\0';
94 if (*(--s) == '\n')
95 *s = '\0';
96 (void) (*Write)(fn, bufr, strlen(bufr) + 1);
97 return(0);
101 * read message from x.25 link
102 * str -> message buffer
103 * fn -> x.25 file descriptor
104 * return
105 * FAIL -> send timed out
106 * 0 -> ok message in str
109 xrdmsg(str, fn)
110 char *str;
112 int len;
114 if(setjmp(Xfailbuf))
115 return(FAIL);
117 (void) alarm(msgtime);
118 for (;;) {
119 if( (len = (*Read)(fn, str, XBUFSIZ)) == 0)
120 continue;
121 if (len < 0) {
122 (void) alarm(0);
123 return(FAIL);
125 str += len;
126 if (*(str - 1) == '\0')
127 break;
129 (void) alarm(0);
130 return(0);
134 * read data from file fp1 and write
135 * on x.25 link
136 * fp1 -> file descriptor
137 * fn -> x.25 descriptor
138 * returns:
139 * FAIL ->failure in x.25 link
140 * 0 -> ok
143 xwrdata(fp1, fn)
144 FILE *fp1;
146 int fd1;
147 int len, ret;
148 unsigned long bytes;
149 char bufr[XBUFSIZ];
151 bytes = 0L;
152 fd1 = fileno( fp1 );
153 while ((len = read( fd1, bufr, XBUFSIZ )) > 0) {
154 bytes += len;
155 putfilesize(bytes);
156 ret = (*Write)(fn, bufr, len);
157 if (ret != len) {
158 return(FAIL);
160 if (len != XBUFSIZ)
161 break;
163 ret = (*Write)(fn, bufr, 0);
164 return(0);
168 * read data from x.25 link and
169 * write into file
170 * fp2 -> file descriptor
171 * fn -> x.25 descriptor
172 * returns:
173 * 0 -> ok
174 * FAIL -> failure on x.25 link
177 xrddata(fn, fp2)
178 FILE *fp2;
180 int fd2;
181 int len;
182 int ret = SUCCESS;
183 unsigned long bytes;
184 char bufr[XBUFSIZ];
186 bytes = 0L;
187 fd2 = fileno( fp2 );
188 for (;;) {
189 len = xrdblk(bufr, XBUFSIZ, fn);
190 if (len < 0) {
191 return(FAIL);
193 bytes += len;
194 putfilesize(bytes);
195 if( ret == SUCCESS && write( fd2, bufr, len ) != len )
196 ret = errno;
197 if (len < XBUFSIZ)
198 break;
200 return(ret);
204 * read blank from x.25 link
205 * reads are timed
206 * blk -> address of buffer
207 * len -> size to read
208 * fn -> x.25 descriptor
209 * returns:
210 * FAIL -> link error timeout on link
211 * i -> # of bytes read
214 xrdblk(blk, len, fn)
215 char *blk;
217 int i, ret;
219 if(setjmp(Xfailbuf))
220 return(FAIL);
222 (void) alarm(msgtime);
223 for (i = 0; i < len; i += ret) {
224 if ((ret = (*Read)(fn, blk, len - i)) < 0) {
225 (void) alarm(0);
226 return(FAIL);
228 blk += ret;
229 if (ret == 0)
230 break;
232 (void) alarm(0);
233 return(i);
235 #endif /* X_PROTOCOL */