8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / lp / lib / msgs / _getmessage.c
blobae4d62374c4abf65fa94bac94e8ce6290a3acd20
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
22 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
23 /* All Rights Reserved */
26 #ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.9 */
27 /* LINTLIBRARY */
29 # include <stdarg.h>
30 # include <string.h>
31 # include <errno.h>
33 # include "msgs.h"
35 extern char *_lp_msg_fmts[];
36 extern int errno;
38 /* VARARGS */
39 #if defined(__STDC__)
40 int _getmessage ( char * buf, short rtype, va_list arg )
41 #else
42 int _getmessage (buf, rtype, arg)
43 char *buf;
44 short rtype;
45 va_list arg;
46 #endif
48 char *endbuf;
49 char *fmt;
50 char **t_string;
51 int temp = 0;
52 long *t_long;
53 short *t_short;
54 short etype;
56 if (buf == (char *)0)
58 errno = ENOSPC;
59 return(-1);
63 * We assume that we're given a buffer big enough to hold
64 * the header.
67 endbuf = buf + (long)stoh(buf);
68 if ((buf + MESG_DATA) > endbuf)
70 errno = ENOMSG;
71 return(-1);
74 etype = stoh(buf + MESG_TYPE);
75 if (etype < 0 || etype > LAST_MESSAGE)
77 errno = EBADMSG;
78 return(-1);
81 if (etype != rtype)
83 if (rtype > 0 && rtype <= LAST_MESSAGE)
84 fmt = _lp_msg_fmts[rtype];
85 else
87 errno = EINVAL;
88 return(-1);
91 else
92 fmt = _lp_msg_fmts[etype];
94 buf += MESG_LEN;
96 while (*fmt != '\0')
97 switch(*fmt++)
99 case 'H':
100 if ((buf + 4) > endbuf)
102 errno = ENOMSG;
103 return(-1);
106 t_short = va_arg(arg, short *);
107 *t_short = stoh(buf);
108 buf += 4;
109 break;
111 case 'L':
112 if ((buf + 8) > endbuf)
114 errno = ENOMSG;
115 return(-1);
118 t_long = va_arg(arg, long *);
119 *t_long = stol(buf);
120 buf += 8;
121 break;
123 case 'D':
124 if ((buf + 4) > endbuf)
126 errno = ENOMSG;
127 return(-1);
130 t_short = va_arg(arg, short *);
131 *t_short = stoh(buf);
132 buf += 4;
133 t_string = va_arg(arg, char **);
134 if ((buf + *t_short) > endbuf)
136 errno = ENOMSG;
137 return(-1);
139 (*t_short)--; /* Don't mention the null we added */
140 *t_string = buf;
141 buf += *t_short;
142 break;
144 case 'S':
145 if ((buf + 4) > endbuf)
147 errno = ENOMSG;
148 return(-1);
151 t_string = va_arg(arg, char **);
152 temp = stoh(buf);
153 buf += 4;
154 if ((buf + temp) > endbuf)
156 errno = ENOMSG;
157 return(-1);
160 *t_string = buf;
161 buf += temp;
162 break;
164 return(etype);