8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / sgs / rtld.4.x / rtsubrs.c
blobf08a707a9491ca28afbd26ab0adda012b362d17e
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 #pragma ident "%Z%%M% %I% %E% SMI"
25 * Copyright (c) 1987, 1988, 1989, 1990 by Sun Microsystems, Inc.
28 /* Copyright (c) 1988 AT&T */
29 /* All Rights Reserved */
32 * Subroutines for the 4.0 compatibility run-time link editor.
34 #include <varargs.h>
35 #include <sys/types.h>
38 * Local "printf" & stdio facilities.
40 int stdout = 1; /* File descriptor for output */
41 int stderr = 2; /* File descriptor for errors */
43 static char *printn();
44 static void prf();
45 static void doprf();
46 static int _write();
49 * printf
51 /*VARARGS1*/
52 printf(fmt, va_alist)
53 char *fmt;
54 va_dcl
56 va_list x1;
58 va_start(x1);
59 prf(stdout, fmt, x1);
60 va_end(x1);
64 * fprintf
66 /*VARARGS2*/
67 fprintf(fd, fmt, va_alist)
68 int fd;
69 char *fmt;
70 va_dcl
72 va_list x1;
74 va_start(x1);
75 prf(fd, fmt, x1);
76 va_end(x1);
80 * panic
82 /*VARARGS2*/
83 panic(fmt, va_alist)
84 char *fmt;
85 va_dcl
87 va_list x1;
88 extern char *program_name;
90 va_start(x1);
91 prf(stderr, "%s (4.x.ld.so): ", program_name);
92 prf(stderr, fmt, x1);
93 prf(stderr, "\n", x1);
94 va_end(x1);
95 _exit(127);
96 /* NOTREACHED */
100 * sprintf
102 /*VARARGS2*/
103 sprintf(cp, fmt, va_alist)
104 char *cp;
105 char *fmt;
106 va_dcl
108 va_list x1;
110 va_start(x1);
111 doprf(-1, fmt, x1, cp);
112 va_end(x1);
116 * printf worker functions
118 static void
119 prf(fd, fmt, adx)
120 int fd;
121 char *fmt;
122 va_list adx;
124 char linebuf[128];
126 doprf(fd, fmt, adx, linebuf);
129 static void
130 doprf(fd, fmt, adx, linebuf)
131 int fd;
132 register char *fmt;
133 register va_list adx;
134 char *linebuf;
136 register int c; /* Character temporary */
137 register char *lbp; /* Pointer into stack buffer */
138 register char *s; /* %s temporary */
139 int i; /* General integer temporary */
140 int b; /* Conversion base */
142 #define PUTCHAR(c) { \
143 if (lbp >= &linebuf[128]) { \
144 _write(fd, linebuf, lbp - &linebuf[0]); \
145 lbp = &linebuf[0]; \
147 *lbp++ = (c); \
150 lbp = &linebuf[0];
151 loop:
152 while ((c = *fmt++) != '%') {
153 if (c == '\0') {
154 _write(fd, linebuf, lbp - &linebuf[0]);
155 return;
157 PUTCHAR(c);
159 again:
160 c = *fmt++;
161 /* THIS CODE IS VAX DEPENDENT IN HANDLING %l? AND %c */
162 switch (c) {
164 case 'x': case 'X':
165 b = 16;
166 goto number;
167 case 'd': case 'D':
168 case 'u': /* what a joke */
169 b = 10;
170 goto number;
171 case 'o': case 'O':
172 b = 8;
173 number:
174 lbp = printn(fd, va_arg(adx, u_long), b, &linebuf[0], lbp,
175 &linebuf[128]);
176 break;
178 case 'c':
179 b = va_arg(adx, int);
180 for (i = 24; i >= 0; i -= 8)
181 if (c = (b >> i) & 0x7f) {
182 PUTCHAR(c);
184 break;
186 case 's':
187 s = va_arg(adx, char *);
188 while (c = *s++) {
189 PUTCHAR(c);
191 break;
193 case '%':
194 PUTCHAR('%');
195 break;
197 goto loop;
201 * Printn prints a number n in base b.
203 static char *
204 printn(fd, n, b, linebufp, lbp, linebufend)
205 int fd; /* File descriptor to get output */
206 u_long n; /* Number */
207 int b; /* Base */
208 char *linebufp; /* Buffer location */
209 register char *lbp; /* Current offset in buffer */
210 char *linebufend; /* Where buffer ends */
212 char prbuf[11]; /* Local result accumulator */
213 register char *cp;
215 #undef PUTCHAR
216 #define PUTCHAR(c) { \
217 if (lbp >= linebufend) { \
218 _write(fd, linebufp, lbp - linebufp); \
219 lbp = linebufp; \
221 *lbp++ = (c); \
224 if (b == 10 && (int)n < 0) {
225 PUTCHAR('-');
226 n = (unsigned)(-(int)n);
228 cp = prbuf;
229 do {
230 *cp++ = "0123456789abcdef"[n%b];
231 n /= b;
232 } while (n);
233 do {
234 PUTCHAR(*--cp);
235 } while (cp > prbuf);
236 return (lbp);
239 static int
240 _write(fd, buf, len)
241 int fd;
242 char *buf;
243 int len;
246 if (fd == -1) {
247 *(buf + len) = '\0';
248 return (0);
250 return (write(fd, buf, len));