8349 thrd_equal implements the wrong specification
[unleashed.git] / usr / src / cmd / bnu / imsg.c
blob3d24d0508638099f0c092cccb7d902c2b46b7698
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 #define MSYNC '\020'
36 /* maximum likely message - make sure you don't get run away input */
37 #define MAXIMSG 256
40 * read message routine used before a
41 * protocol is agreed upon.
42 * msg -> address of input buffer
43 * fn -> input file descriptor
44 * returns:
45 * EOF -> no more messages
46 * 0 -> message returned
48 int
49 imsg(msg, fn)
50 char *msg;
51 int fn;
53 char c;
54 int i;
55 short fndsync;
56 char *bmsg;
58 fndsync = 0;
59 bmsg = msg;
60 CDEBUG(7, "imsg %s>", "");
61 while ((i = (*Read)(fn, msg, sizeof(char))) == sizeof(char)) {
62 *msg &= 0177;
63 c = *msg;
64 CDEBUG(7, "%s", c < 040 ? "^" : "");
65 CDEBUG(7, "%c", c < 040 ? c | 0100 : c);
66 if (c == MSYNC) { /* look for sync character */
67 msg = bmsg;
68 fndsync = 1;
69 continue;
71 if (!fndsync)
72 continue;
74 if (c == '\0' || c == '\n') {
75 *msg = '\0';
76 return(0);
78 else
79 msg++;
81 if (msg - bmsg > MAXIMSG) /* unlikely */
82 return(FAIL);
84 /* have not found sync or end of message */
85 if (i < 0) {
86 CDEBUG(7, "\nimsg read error: %s\n", strerror(errno));
88 *msg = '\0';
89 return(EOF);
93 * initial write message routine -
94 * used before a protocol is agreed upon.
95 * type -> message type
96 * msg -> message body address
97 * fn -> file descriptor
98 * return:
99 * Must always return 0 - wmesg (WMESG) looks for zero
102 omsg(type, msg, fn)
103 char *msg;
104 char type;
105 int fn;
107 char buf[BUFSIZ];
109 (void) sprintf(buf, "%c%c%s", MSYNC, type, msg);
110 DEBUG( 7, "omsg \"%s\"\n", &buf[1] );
111 (*Write)(fn, buf, strlen(buf) + 1);
112 return(0);
116 * null turnoff routine to be used for errors
117 * during protocol selection.
120 turnoff(void)
122 return(0);