xref: /onnv-gate/usr/src/lib/libnsl/saf/checkver.c (revision 1914:8a8c5f225b1b)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*1914Scasper  * Common Development and Distribution License (the "License").
6*1914Scasper  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
21132Srobinson 
22132Srobinson /*
231219Sraf  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
24132Srobinson  * Use is subject to license terms.
25132Srobinson  */
26132Srobinson 
270Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
280Sstevel@tonic-gate /*	  All Rights Reserved  	*/
290Sstevel@tonic-gate 
300Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
310Sstevel@tonic-gate 
321219Sraf #include "mt.h"
330Sstevel@tonic-gate #include <stdio.h>
340Sstevel@tonic-gate #include <stdlib.h>
350Sstevel@tonic-gate #include <string.h>
36132Srobinson #include <sys/types.h>
370Sstevel@tonic-gate 
38132Srobinson #define	VSTR	"# VERSION="
390Sstevel@tonic-gate 
400Sstevel@tonic-gate 
410Sstevel@tonic-gate /*
420Sstevel@tonic-gate  * check_version - check to make sure designated file is the correct version
430Sstevel@tonic-gate  *		returns : 0 - version correct
440Sstevel@tonic-gate  *			  1 - version incorrect
450Sstevel@tonic-gate  *			  2 - could not open file
460Sstevel@tonic-gate  *			  3 - corrupt file
470Sstevel@tonic-gate  */
480Sstevel@tonic-gate 
490Sstevel@tonic-gate 
500Sstevel@tonic-gate int
check_version(int ver,char * fname)51132Srobinson check_version(int ver, char *fname)
520Sstevel@tonic-gate {
530Sstevel@tonic-gate 	FILE *fp;		/* file pointer for sactab */
540Sstevel@tonic-gate 	char line[BUFSIZ];	/* temp buffer for input */
550Sstevel@tonic-gate 	char *p;		/* working pointer */
560Sstevel@tonic-gate 	int version;		/* version number from sactab */
570Sstevel@tonic-gate 
58*1914Scasper 	if ((fp = fopen(fname, "rF")) == NULL)
59132Srobinson 		return (2);
600Sstevel@tonic-gate 	p = line;
610Sstevel@tonic-gate 	while (fgets(p, BUFSIZ, fp)) {
62132Srobinson 		if (strncmp(p, VSTR, strlen(VSTR)) == 0) {
630Sstevel@tonic-gate 			p += strlen(VSTR);
640Sstevel@tonic-gate 			if (*p)
650Sstevel@tonic-gate 				version = atoi(p);
66132Srobinson 			else
67132Srobinson 				return (3);
680Sstevel@tonic-gate 			(void) fclose(fp);
69132Srobinson 			return ((version != ver) ? 1 : 0);
700Sstevel@tonic-gate 		}
710Sstevel@tonic-gate 		p = line;
720Sstevel@tonic-gate 	}
73132Srobinson 	return (3);
740Sstevel@tonic-gate }
75