5590 improper use of NULL in tools/protocmp
[unleashed.git] / usr / src / tools / protocmp / exception_list.c
blobf44f5296e9fdc2fc41dcc8620628fab127f572f3
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
23 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright 2015 PALO, Richard
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <string.h>
33 #include "list.h"
34 #include "exception_list.h"
35 #include "arch.h"
38 * This is global so that the protodir reading functions can rely on the
39 * exception list to weed out innocuous problems in the IHV gate.
41 elem_list exception_list;
43 #define FS " \t\n"
45 static int
46 parse_exception_line(char *line, elem_list *list)
48 char *name, *arch;
49 elem *e;
51 if ((name = strtok(line, FS)) == NULL) {
52 /* don't complain; this is only a blank line */
53 return (0);
56 if ((arch = strtok(NULL, FS)) == NULL) {
57 arch = "all";
60 e = (elem *) malloc(sizeof (elem));
61 if (e == NULL) {
62 perror("malloc");
63 exit(1);
66 e->inode = 0;
67 e->perm = 0;
68 e->ref_cnt = 0;
69 e->flag = 0;
70 e->major = 0;
71 e->minor = 0;
72 e->link_parent = NULL;
73 e->link_sib = NULL;
74 e->symsrc = NULL;
75 e->file_type = DIR_T;
77 while ((e->arch = assign_arch(arch)) == 0) {
78 if ((arch = strtok(NULL, FS)) == NULL) {
79 return (0);
83 (void) strcpy(e->name, name);
84 add_elem(list, e);
86 return (1);
89 int
90 read_in_exceptions(const char *exception_file, int verbose)
92 FILE *except_fp;
93 char buf[BUFSIZ];
94 int count = 0;
96 exception_file = exception_file ? exception_file : EXCEPTION_FILE;
98 if (verbose) {
99 (void) printf("reading in exceptions from %s...\n",
100 exception_file);
103 if ((except_fp = fopen(exception_file, "r")) == NULL) {
104 perror(exception_file);
105 return (0);
107 while (fgets(buf, BUFSIZ, except_fp)) {
108 if (buf[0] != '#') /* allow for comments */
109 count += parse_exception_line(buf, &exception_list);
111 if (verbose)
112 (void) printf("read in %d exceptions...\n", count);
114 return (count);