dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / lib / libbsm / common / adrf.c
blobdd82b0a85e685d0e22bb356e768dc4d1d8a6b099
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
19 * CDDL HEADER END
22 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #pragma ident "%Z%%M% %I% %E% SMI"
28 #include <stdio.h>
29 #include <sys/types.h>
30 #include <bsm/audit.h>
31 #include <bsm/libbsm.h>
32 #include <bsm/audit_record.h>
36 * adr_struct.now is used to calculate the record length so
37 * end of record will be recognized.
41 void
42 adrf_start(adrf_t *adrf, adr_t *adr, FILE *fp)
44 adrf->adrf_fp = fp;
45 adrf->adrf_adr = adr;
46 adrf->adrf_adr->adr_now = NULL;
50 * adrf_char - pull out characters
52 int
53 adrf_char(adrf_t *adrf, char *cp, int count)
55 int c; /* read character in here */
57 if (count < 0)
58 return (-1);
59 while (count--) {
60 if ((c = fgetc(adrf->adrf_fp)) == EOF)
61 return (-1);
62 *cp++ = c;
63 adrf->adrf_adr->adr_now += sizeof (char);
65 return (0);
69 * adrf_short - pull out shorts
71 int
72 adrf_short(adrf_t *adrf, short *sp, int count)
74 int c; /* read character in here */
76 if (count < 0)
77 return (-1);
78 while (count--) {
79 if ((c = fgetc(adrf->adrf_fp)) == EOF)
80 return (-1);
81 *sp = c << 8;
82 if ((c = fgetc(adrf->adrf_fp)) == EOF)
83 return (-1);
84 *sp++ |= c & 0x00ff;
85 adrf->adrf_adr->adr_now += sizeof (short);
87 return (0);
91 * adrf_int32 - pull out int32
93 int adrf_int(adrf_t *adrf, int32_t *lp, int count);
94 int adrf_long(adrf_t *adrf, int32_t *lp, int count);
96 #pragma weak adrf_int = adrf_int32
97 #pragma weak adrf_long = adrf_int32
99 int
100 adrf_int32(adrf_t *adrf, int32_t *lp, int count)
102 int i;
103 int c; /* read character in here */
105 if (count < 0)
106 return (-1);
107 for (; count--; lp++) {
108 *lp = 0;
109 for (i = 0; i < 4; i++) {
110 if ((c = fgetc(adrf->adrf_fp)) == EOF)
111 return (-1);
112 *lp <<= 8;
113 *lp |= c & 0x000000ff;
115 adrf->adrf_adr->adr_now += sizeof (int32_t);
117 return (0);
121 adrf_int64(adrf_t *adrf, int64_t *lp, int count)
123 int i;
124 int c; /* read character in here */
126 if (count < 0)
127 return (-1);
128 for (; count--; lp++) {
129 *lp = 0;
130 for (i = 0; i < 8; i++) {
131 if ((c = fgetc(adrf->adrf_fp)) == EOF)
132 return (-1);
133 *lp <<= 8;
134 *lp |= c & 0x00000000000000ff;
136 adrf->adrf_adr->adr_now += sizeof (int64_t);
138 return (0);
141 int adrf_u_int(adrf_t *adrf, uint32_t *cp, int count);
142 int adrf_u_long(adrf_t *adrf, uint32_t *cp, int count);
144 #pragma weak adrf_u_int = adrf_u_int32
145 #pragma weak adrf_u_long = adrf_u_int32
148 adrf_u_int32(adrf_t *adrf, uint32_t *cp, int count)
150 return (adrf_int32(adrf, (int32_t *)cp, count));
154 adrf_u_char(adrf_t *adrf, uchar_t *cp, int count)
156 return (adrf_char(adrf, (char *)cp, count));
160 adrf_u_int64(adrf_t *adrf, uint64_t *lp, int count)
162 return (adrf_int64(adrf, (int64_t *)lp, count));
166 adrf_u_short(adrf_t *adrf, ushort_t *sp, int count)
168 return (adrf_short(adrf, (short *)sp, count));
172 adrf_peek(adrf_t *adrf)
174 return (ungetc(fgetc(adrf->adrf_fp), adrf->adrf_fp));