xref: /illumos-gate/usr/src/cmd/ttymon/admutil.c (revision 42b53e0fbc5c05289c3d334bb864b784fafe5ce4)
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 2004 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
28 /*	  All Rights Reserved	*/
29 
30 #include <stdio.h>
31 #include <unistd.h>
32 #include <stdlib.h>
33 #include <string.h>
34 #include <sys/types.h>
35 #include <ctype.h>
36 #include <sys/stat.h>
37 #include "tmstruct.h"
38 #include "ttymon.h"
39 
40 /*
41  *	find_label - return 1 if ttylabel already exists
42  *		   - return 0 otherwise
43  */
44 int
45 find_label(FILE *fp, char *ttylabel)
46 {
47 	char *p;		/* working pointer */
48 	int line = 0;		/* line number we found entry on */
49 	static char buf[BUFSIZ]; /* scratch buffer */
50 
51 	while (fgets(buf, BUFSIZ, fp)) {
52 		line++;
53 		p = buf;
54 		while (isspace(*p))
55 			p++;
56 		if ((p = strtok(p, " :")) != NULL) {
57 			if (strcmp(p, ttylabel) == 0)
58 				return (line);
59 		}
60 	}
61 	if (!feof(fp)) {
62 		(void) fprintf(stderr, "error reading \"%s\"\n", TTYDEFS);
63 		return (0);
64 	}
65 	return (0);
66 }
67