xref: /titanic_52/usr/src/tools/protocmp/exception_list.c (revision 26f3cdf03f1adcc98f6d3d99843ee71e9229a8c0)
1 /*
2  * CDDL HEADER START
3  *
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.
7  *
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.
12  *
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]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <string.h>
30 
31 #include "list.h"
32 #include "exception_list.h"
33 #include "arch.h"
34 
35 /*
36  * This is global so that the protodir reading functions can rely on the
37  * exception list to weed out innocuous problems in the IHV gate.
38  */
39 elem_list exception_list;
40 
41 #define	FS	" \t\n"
42 
43 static int
44 parse_exception_line(char *line, elem_list *list)
45 {
46 	char	*name, *arch;
47 	elem	*e;
48 
49 	if ((name = strtok(line, FS)) == NULL) {
50 		/* don't complain; this is only a blank line */
51 		return (0);
52 	}
53 
54 	if ((arch = strtok(NULL, FS)) == NULL) {
55 		arch = "all";
56 	}
57 
58 	e = (elem *) malloc(sizeof (elem));
59 
60 	e->inode = 0;
61 	e->perm = 0;
62 	e->ref_cnt = 0;
63 	e->flag = 0;
64 	e->major = 0;
65 	e->minor = 0;
66 	e->link_parent = NULL;
67 	e->link_sib = NULL;
68 	e->symsrc = NULL;
69 	e->file_type = DIR_T;
70 
71 	while ((e->arch = assign_arch(arch)) == NULL) {
72 		if ((arch = strtok(NULL, FS)) == NULL) {
73 			return (0);
74 		}
75 	}
76 
77 	(void) strcpy(e->name, name);
78 	add_elem(list, e);
79 
80 	return (1);
81 }
82 
83 int
84 read_in_exceptions(const char *exception_file, int verbose)
85 {
86 	FILE	*except_fp;
87 	char	buf[BUFSIZ];
88 	int	count = 0;
89 
90 	exception_file = exception_file ? exception_file : EXCEPTION_FILE;
91 
92 	if (verbose) {
93 		(void) printf("reading in exceptions from %s...\n",
94 		    exception_file);
95 	}
96 
97 	if ((except_fp = fopen(exception_file, "r")) == NULL) {
98 		perror(exception_file);
99 		return (0);
100 	}
101 	while (fgets(buf, BUFSIZ, except_fp)) {
102 		if (buf[0] != '#')	/* allow for comments */
103 			count += parse_exception_line(buf, &exception_list);
104 	}
105 	if (verbose)
106 		(void) printf("read in %d exceptions...\n", count);
107 
108 	return (count);
109 }
110