7712 mandoc -Tlint does always exit with error code 0
[unleashed.git] / usr / src / lib / lvm / libsvm / common / getdrvname.c
bloba24b85e0408928a1bdb53678793bb9f7fbabc52f
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
22 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #pragma ident "%Z%%M% %I% %E% SMI"
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <ctype.h>
31 #include <string.h>
32 #include <limits.h>
33 #include <sys/types.h>
34 #include <svm.h>
37 * Macros to produce a quoted string containing the value of a
38 * preprocessor macro. For example, if SIZE is defined to be 256,
39 * VAL2STR(SIZE) is "256". This is used to construct format
40 * strings for scanf-family functions below.
42 #define QUOTE(x) #x
43 #define VAL2STR(x) QUOTE(x)
45 static int is_blank(char *);
48 * is_blank() returns 1 (true) if a line specified is composed of
49 * whitespace characters only. otherwise, it returns 0 (false).
51 * Note. the argument (line) must be null-terminated.
53 static int
54 is_blank(char *line)
56 for (/* nothing */; *line != '\0'; line++)
57 if (!isspace(*line))
58 return (0);
59 return (1);
63 * FUNCTION:
64 * Return the driver name for a major number
66 * INPUT: major number, mount point for name_to_major file, pointer
67 * to a valid buffer.
69 * RETURN VALUES:
70 * 0 - SUCCESS - buf contain the driver name.
71 * -1 - FAIL
75 int
76 get_drv_name(major_t major, char *mnt, char *buf)
78 FILE *fp;
79 char drv[FILENAME_MAX + 1];
80 char entry[FILENAME_MAX + 1];
81 char line[MAX_N2M_ALIAS_LINE], *cp;
82 char fname[PATH_MAX];
84 int status = RET_NOERROR;
85 (void) snprintf(fname, sizeof (fname), "%s%s", mnt, NAME_TO_MAJOR);
87 if ((fp = fopen(fname, "r")) == NULL) {
88 return (RET_ERROR);
91 while ((fgets(line, sizeof (line), fp) != NULL) &&
92 status == RET_NOERROR) {
93 /* cut off comments starting with '#' */
94 if ((cp = strchr(line, '#')) != NULL)
95 *cp = '\0';
96 /* ignore comment or blank lines */
97 if (is_blank(line))
98 continue;
99 /* sanity-check */
100 if (sscanf(line,
101 "%" VAL2STR(FILENAME_MAX) "s %" VAL2STR(FILENAME_MAX) "s",
102 drv, entry) != 2) {
103 status = RET_ERROR;
105 if (atoi(entry) == major)
106 break;
109 if (status == RET_NOERROR)
110 (void) strcpy(buf, drv);
111 (void) fclose(fp);
112 return (status);