Home | History | Annotate | Download | only in protocmp
      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, Version 1.0 only
      6  * (the "License").  You may not use this file except in compliance
      7  * with the License.
      8  *
      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.
     13  *
     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]
     19  *
     20  * CDDL HEADER END
     21  */
     22 /*
     23  * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
     24  * Use is subject to license terms.
     25  */
     26 
     27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
     28 
     29 #include <stdio.h>
     30 #include <stdlib.h>
     31 #include <string.h>
     32 
     33 #include "list.h"
     34 #include "exception_list.h"
     35 #include "arch.h"
     36 
     37 /*
     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.
     40  */
     41 elem_list exception_list;
     42 
     43 #define	FS	" \t\n"
     44 
     45 static int
     46 parse_exception_line(char *line, elem_list *list)
     47 {
     48 	char	*name, *arch;
     49 	elem	*e;
     50 
     51 	if ((name = strtok(line, FS)) == NULL) {
     52 		/* don't complain; this is only a blank line */
     53 		return (0);
     54 	}
     55 
     56 	if ((arch = strtok(NULL, FS)) == NULL) {
     57 		(void) fprintf(stderr,
     58 		    "error: no arch field for %s entry in exception file\n",
     59 		    name);
     60 		return (0);
     61 	}
     62 
     63 	e = (elem *) malloc(sizeof (elem));
     64 
     65 	e->inode = 0;
     66 	e->perm = 0;
     67 	e->ref_cnt = 0;
     68 	e->flag = 0;
     69 	e->major = 0;
     70 	e->minor = 0;
     71 	e->link_parent = NULL;
     72 	e->link_sib = NULL;
     73 	e->symsrc = NULL;
     74 	e->file_type = DIR_T;
     75 
     76 	if ((e->arch = assign_arch(arch)) == NULL) {
     77 		(void) fprintf(stderr,
     78 		    "warning: Unknown architecture %s found in "
     79 		    "exception file\n", arch);
     80 		return (0);
     81 	}
     82 
     83 	(void) strcpy(e->name, name);
     84 	add_elem(list, e);
     85 
     86 	return (1);
     87 }
     88 
     89 int
     90 read_in_exceptions(const char *exception_file, int verbose)
     91 {
     92 	FILE	*except_fp;
     93 	char	buf[BUFSIZ];
     94 	int	count = 0;
     95 
     96 	exception_file = exception_file ? exception_file : EXCEPTION_FILE;
     97 
     98 	if (verbose) {
     99 		(void) printf("reading in exceptions from %s...\n",
    100 		    exception_file);
    101 	}
    102 
    103 	if ((except_fp = fopen(exception_file, "r")) == NULL) {
    104 		perror(exception_file);
    105 		return (0);
    106 	}
    107 	while (fgets(buf, BUFSIZ, except_fp)) {
    108 		if (buf[0] != '#')	/* allow for comments */
    109 			count += parse_exception_line(buf, &exception_list);
    110 	}
    111 	if (verbose)
    112 		(void) printf("read in %d exceptions...\n", count);
    113 
    114 	return (count);
    115 }
    116