Print this page
10075 make usr/src/tools smatch clean
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/tools/protocmp/proto_list.c
+++ new/usr/src/tools/protocmp/proto_list.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
↓ open down ↓ |
15 lines elided |
↑ open up ↑ |
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
23 23 * Use is subject to license terms.
24 24 */
25 25
26 -#pragma ident "%Z%%M% %I% %E% SMI"
26 +/*
27 + * Copyright (c) 2018, Joyent, Inc.
28 + */
27 29
28 30 #include <stdio.h>
29 31 #include <fcntl.h>
30 32 #include <strings.h>
31 33 #include <ctype.h>
32 34 #include <stdlib.h>
33 35
34 36 #include "list.h"
35 37 #include "proto_list.h"
36 38
37 39 #define FS " \t\n"
38 40
39 41 static void
40 42 error(const char *msg, int lc)
41 43 {
42 44 (void) fprintf(stderr, "warning: line %d - %s\n", lc, msg);
43 45 }
44 46
45 47 /*
46 48 * int is_num()
47 49 *
48 50 * returns 1 if the string is entirely numeric - if not it returns 0
49 51 *
50 52 */
51 53 static int
52 54 is_num(const char *str)
53 55 {
54 56 int i;
55 57 int len = strlen(str);
56 58
57 59 if (len < 1)
58 60 return (0);
59 61
60 62 for (i = 0; i < len; i++)
61 63 if (!isdigit(str[i]))
62 64 return (0);
63 65 return (1);
64 66 }
65 67
66 68 /*
67 69 * void check_line()
68 70 *
69 71 * try and do some sanity/syntax checking against the line just
70 72 * read in - print warning messages as errors are encountered.
71 73 *
72 74 * these are simple checks, but then they catch the simple errors-:)
73 75 *
74 76 */
75 77 static void
76 78 check_line(char *v[], int lc)
77 79 {
78 80 if ((!v[NAME]) || ((int)strlen(v[NAME]) < 1))
79 81 error("bad name", lc);
80 82
81 83 if ((!v[SRC]) || ((int)strlen(v[SRC])) < 1)
82 84 error("bad source/symbolic line", lc);
83 85
84 86 if ((!v[PERM]) || ((int)strlen(v[PERM]) < 3) || (!is_num(v[PERM])))
85 87 error("bad permissions", lc);
86 88
87 89 if ((!v[OWNR]) || ((int)strlen(v[OWNR]) < 2))
88 90 error("bad owner", lc);
89 91
90 92 if ((!v[GRP]) || ((int)strlen(v[GRP]) < 2))
91 93 error("bad group", lc);
92 94
93 95 if ((!v[INO]) || (!is_num(v[INO])))
94 96 error("bad i-node", lc);
95 97
96 98 if ((!v[LCNT]) || (!is_num(v[LCNT])))
97 99 error("bad link-count", lc);
98 100
99 101 if ((!v[CODE]) || ((*v[CODE] != 'f') && (*v[CODE] != 'c') &&
100 102 (*v[CODE] != 'd') && (*v[CODE] != 'b') &&
101 103 (*v[CODE] != 'v') && (*v[CODE] != 'e') &&
102 104 (*v[CODE] != 's')) || ((int)strlen(v[CODE]) > 1))
103 105 error("bad type", lc);
104 106
105 107 if ((!v[MAJOR]) || ((!is_num(v[MAJOR])) && (*v[MAJOR] != '-')))
106 108 error("bad major number", lc);
107 109
108 110 if ((!v[MINOR]) || ((!is_num(v[MINOR])) && (*v[MINOR] != '-')))
109 111 error("bad minor number", lc);
110 112 }
111 113
112 114 static char **
113 115 get_line(FILE *fp, char *v[])
114 116 {
115 117 char *rc;
116 118 char *p;
117 119 int len;
118 120 int cont = 1;
119 121 static char buf[BUFSIZ];
120 122 static int line_count = 0;
121 123
122 124 p = buf;
123 125 p[0] = '\0';
124 126
125 127 do {
126 128 rc = fgets(p, BUFSIZ, fp);
127 129 line_count ++;
128 130 /*
129 131 * check for continuation marks at the end of the
130 132 * line - if it exists then append the next line at the
131 133 * end of this one.
132 134 */
133 135 if (buf[0] == '#') {
134 136 /*
135 137 * skip comments.
136 138 */
137 139 continue;
138 140 } else if ((rc != NULL) && ((len = strlen(p)) > 1) &&
139 141 (p[len - 2] == '\\')) {
140 142 /*
141 143 * check for continuation marks at the end of the
142 144 * line - if it exists then append the next line at the
143 145 * end of this one.
144 146 */
145 147 p += len - 2;
146 148 } else
147 149 cont = 0;
148 150 } while (cont);
149 151
150 152 if (rc == NULL)
151 153 return (NULL);
152 154
153 155 /*
154 156 * breakup the line into the various fields.
155 157 */
156 158 v[PROTOS] = index(buf, ';');
157 159 if (v[PROTOS])
158 160 *v[PROTOS]++ = '\0';
159 161 v[0] = strtok(buf, FS);
160 162 for (cont = 1; cont < FIELDS - 1; cont++)
161 163 v[cont] = strtok(NULL, FS);
162 164
163 165 check_line(v, line_count);
164 166
165 167 return (v);
166 168 }
167 169
168 170 static void
169 171 parse_line(char **v, elem *e)
170 172 {
171 173 e->flag = 0;
172 174 e->pkgs = NULL;
173 175 e->arch = P_ISA;
174 176 (void) strcpy(e->name, v[NAME]);
175 177 e->perm = strtol(v[PERM], NULL, 8);
176 178 (void) strcpy(e->owner, v[OWNR]);
177 179 (void) strcpy(e->group, v[GRP]);
178 180 e->inode = atoi(v[INO]);
179 181 e->ref_cnt = atoi(v[LCNT]);
180 182 e->file_type = *v[CODE];
181 183 if ((v[MAJOR][0] == '-') && (v[MAJOR][1] == '\0'))
182 184 e->major = -1;
183 185 else
184 186 e->major = atoi(v[MAJOR]);
185 187
↓ open down ↓ |
149 lines elided |
↑ open up ↑ |
186 188 if ((v[MINOR][0] == '-') && (v[MINOR][1] == '\0'))
187 189 e->minor = -1;
188 190 else
189 191 e->minor = atoi(v[MINOR]);
190 192
191 193 if ((v[SYM][0] == '-') && (v[SYM][1] == '\0'))
192 194 e->symsrc = NULL;
193 195 else {
194 196 e->symsrc = malloc(strlen(v[SYM]) + 1);
195 197 (void) strcpy(e->symsrc, v[SYM]);
196 - if (e->file_type != SYM_LINK_T)
198 + if (e->file_type != SYM_LINK_T)
197 199 #if defined(__sparc)
198 200 if (strncmp(e->symsrc, "sun4/", 5) == 0)
199 201 e->arch = P_SUN4;
200 202 else if (strncmp(e->symsrc, "sun4c/", 6) == 0)
201 203 e->arch = P_SUN4c;
202 204 else if (strncmp(e->symsrc, "sun4u/", 6) == 0)
203 205 e->arch = P_SUN4u;
204 206 else if (strncmp(e->symsrc, "sun4d/", 6) == 0)
205 207 e->arch = P_SUN4d;
206 208 else if (strncmp(e->symsrc, "sun4e/", 6) == 0)
207 209 e->arch = P_SUN4e;
208 210 else if (strncmp(e->symsrc, "sun4m/", 6) == 0)
209 211 e->arch = P_SUN4m;
210 212 else if (strncmp(e->symsrc, "sun4v/", 6) == 0)
211 213 e->arch = P_SUN4v;
212 214 #elif defined(__i386)
213 215 if (strncmp(e->symsrc, "i86pc/", 6) == 0)
214 216 e->arch = P_I86PC;
215 217 #elif defined(__ppc)
216 218 if (strncmp(e->symsrc, "prep/", 5) == 0)
217 219 e->arch = P_PREP;
218 220 #else
219 221 #error "Unknown instruction set"
220 222 #endif
221 223 else {
222 224 (void) fprintf(stderr,
223 225 "warning: Unknown relocation architecture "
224 226 "for %s\n", e->symsrc);
225 227 }
226 228
227 229 }
228 230 }
229 231
230 232 int
231 233 read_in_protolist(const char *pname, elem_list *list, int verbose)
232 234 {
233 235 FILE *proto_fp;
234 236 char *line_vec[FIELDS];
235 237 int count = 0;
236 238 static elem *e = NULL;
237 239
238 240 list->type = PROTOLIST_LIST;
239 241
240 242 if ((proto_fp = fopen(pname, "r")) == NULL) {
241 243 perror(pname);
242 244 exit(1);
243 245 }
244 246
245 247 if (verbose)
246 248 (void) printf("reading in proto_list(%s)...\n", pname);
247 249
248 250 count = 0;
249 251 while (get_line(proto_fp, line_vec)) {
250 252 if (!e)
251 253 e = (elem *)calloc(1, sizeof (elem));
252 254
253 255 parse_line(line_vec, e);
254 256 if (!find_elem(list, e, FOLLOW_LINK)) {
255 257 add_elem(list, e);
256 258 e = NULL;
257 259 count++;
258 260 }
259 261 }
260 262
261 263 if (verbose)
262 264 (void) printf("read in %d lines\n", count);
263 265
264 266 (void) fclose(proto_fp);
265 267
266 268 return (count);
267 269 }
↓ open down ↓ |
61 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX